private Optional<MetadataCacheId> getHashedGlobal(String name) { if (!isBlank(name)) { return locator.get(Location.builder().globalName(name).build()) .map(global -> getIdForComponentMetadata(global).orElse(null)); } return empty(); }
@Test public void attributesDynamicPersonTypeMetadata() throws Exception { location = Location.builder().globalName(OUTPUT_ATTRIBUTES_WITH_DYNAMIC_METADATA).addProcessorsPart().addIndexPart(0).build(); final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadataWithKey(PERSON_METADATA_KEY); final OperationModel typedModel = metadataDescriptor.getModel(); MetadataType type = typedModel.getOutputAttributes().getType(); assertThat(type, is(instanceOf(ObjectType.class))); ObjectType dictionary = (ObjectType) type; assertThat(dictionary.getOpenRestriction().get(), is(instanceOf(StringType.class))); }
@Test public void nonExistentConnectivityTestingObject() { reset(mockMuleContext); when(mockMuleContext.getConfigurationComponentLocator().find(any(Location.class))).thenReturn(empty()); connectivityTestingService.setLocator(mockMuleContext.getConfigurationComponentLocator()); expectedException.expect(ObjectNotFoundException.class); connectivityTestingService.testConnection(builder().globalName(TEST_IDENTIFIER).build()); }
@Test public void retrieveKeysFromBooleanMetadataKey() { location = Location.builder().globalName(BOOLEAN_METADATA_KEY).addProcessorsPart().addIndexPart(0).build(); MetadataResult<MetadataKeysContainer> result = metadataService.getMetadataKeys(location); assertSuccessResult(result); String booleanMetadataResolver = "BooleanMetadataResolver"; assertThat(result.get().getCategories(), contains(booleanMetadataResolver)); Set<MetadataKey> metadataKeys = result.get().getKeys(booleanMetadataResolver).get(); assertThat(metadataKeys, hasItems(metadataKeyWithId("FALSE"), metadataKeyWithId("TRUE"))); }
@Test public void getContentMetadataWithKey() throws Exception { location = Location.builder().globalName(CONTENT_METADATA_WITH_KEY_ID).addProcessorsPart().addIndexPart(0).build(); final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadataWithKey(PERSON_METADATA_KEY); final OperationModel typedModel = metadataDescriptor.getModel(); assertExpectedOutput(typedModel, typeBuilder.anyType().build(), void.class); assertExpectedType(getParameter(typedModel, "type"), String.class); assertExpectedType(getParameter(typedModel, "content"), personType, true); }
@Test public void attributesUnionTypeMetadata() throws Exception { location = Location.builder().globalName(OUTPUT_ATTRIBUTES_WITH_DECLARED_SUBTYPES_METADATA).addProcessorsPart() .addIndexPart(0).build(); final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadata(NULL_METADATA_KEY); final OperationModel typedModel = metadataDescriptor.getModel(); assertExpectedOutput(typedModel, Shape.class, AbstractOutputAttributes.class); }
@Test public void dynamicOperationMetadata() throws Exception { location = Location.builder().globalName(CONTENT_AND_OUTPUT_METADATA_WITH_KEY_ID).addProcessorsPart().addIndexPart(0).build(); final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadataWithKey(PERSON_METADATA_KEY); final OperationModel typedModel = metadataDescriptor.getModel(); assertExpectedType(getParameter(typedModel, "type"), String.class); assertExpectedType(getParameter(typedModel, "content"), personType, true); }
@Test public void getMetadataKeysWithKeyId() throws Exception { location = Location.builder().globalName(OUTPUT_METADATA_WITH_KEY_ID).addProcessorsPart().addIndexPart(0).build(); final MetadataResult<MetadataKeysContainer> metadataKeysResult = metadataService.getMetadataKeys(location); assertSuccessResult(metadataKeysResult); final Set<MetadataKey> metadataKeys = getKeysFromContainer(metadataKeysResult.get()); assertThat(metadataKeys.size(), is(3)); assertThat(metadataKeys, hasItems(metadataKeyWithId(PERSON), metadataKeyWithId(CAR), metadataKeyWithId(HOUSE))); }
@Test public void failToGetMetadataFromNonExistingConfig() throws IOException { location = builder().globalName(NON_EXISTING_CONFIG).build(); final MetadataResult<MetadataKeysContainer> result = metadataService.getMetadataKeys(location); assertFailureResult(result, 1); assertMetadataFailure(result.getFailures().get(0), format(NO_OBJECT_FOUND, NON_EXISTING_CONFIG), COMPONENT_NOT_FOUND, NO_SUCH_COMPONENT_MODEL_EXCEPTION_CLASS_NAME, COMPONENT); }
@Test public void getOperationMetadataWithResolvingException() throws Exception { location = builder().globalName(FAIL_WITH_RESOLVING_EXCEPTION).addProcessorsPart().addIndexPart(0).build(); MetadataResult<ComponentMetadataDescriptor<OperationModel>> metadata = getComponentDynamicMetadata(PERSON_METADATA_KEY); assertThat(metadata.isSuccess(), is(false)); assertFailureResult(metadata, 2); List<MetadataFailure> failures = metadata.getFailures(); assertMetadataFailure(failures.get(0), "", CONNECTION_FAILURE, "", OUTPUT_PAYLOAD, ""); assertMetadataFailure(failures.get(1), "", CONNECTION_FAILURE, "", INPUT, "content"); }
@Test public void testObjectNotSupported() { reset(mockConnectivityTestingStrategy); when(mockConnectivityTestingStrategy.accepts(fakeConnectivityTestingObject)).thenReturn(false); expectedException.expect(UnsupportedConnectivityTestingObjectException.class); connectivityTestingService.testConnection(builder().globalName(TEST_IDENTIFIER).build()); }
@Override public Location getRootContainerLocation() { return Location.builder().globalName(getRootContainerName()).build(); } }
@Test public void operationWhichReturnsListOfMessages() throws Exception { location = Location.builder().globalName("listOfMessages").addProcessorsPart().addIndexPart(0).build(); final MetadataResult<ComponentMetadataDescriptor<OperationModel>> result = metadataService.getOperationMetadata(location); assertSuccessResult(result); ComponentMetadataDescriptor<OperationModel> descriptor = result.get(); MetadataType param = descriptor.getModel().getOutput().getType(); assertThat(param, is(instanceOf(ArrayType.class))); assertMessageType(((ArrayType) param).getType(), TYPE_LOADER.load(String.class), TYPE_LOADER.load(StringAttributes.class)); }
@Test public void dynamicOutputAndContentWithCache() throws Exception { location = Location.builder().globalName(CONTENT_AND_OUTPUT_CACHE_RESOLVER).addProcessorsPart().addIndexPart(0).build(); final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadataWithKey(PERSON_METADATA_KEY); final OperationModel typedModel = metadataDescriptor.getModel(); MetadataType outputType = typedModel.getOutput().getType(); MetadataType contentType = getParameter(typedModel, "content").getType(); assertThat(contentType, is(equalTo(outputType))); }
@Test public void dynamicOutputWithoutContentParam() throws Exception { // Resolver for content and output type, no @Content param, resolves only output, with keysResolver and KeyId location = Location.builder().globalName(OUTPUT_ONLY_WITHOUT_CONTENT_PARAM).addProcessorsPart().addIndexPart(0).build(); final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadataWithKey(PERSON_METADATA_KEY); final OperationModel typedModel = metadataDescriptor.getModel(); assertExpectedOutput(typedModel, personType, void.class); assertExpectedType(getParameter(typedModel, "type"), String.class); }
@Test public void failingNonBlockingConnectedOperation() throws Exception { expectedException.expectFailingComponent(is(locator .find(Location.builder().globalName("fireMissile").addProcessorsPart().addIndexPart(1).build()).get())); expectedException.expectMessage(is(MISSILE_PROOF)); expectedException.expectCause(instanceOf(UnsupportedOperationException.class)); Villain villain = new MissileProofVillain(); flowRunner("fireMissile").withPayload(villain).run(); assertThat(villain.isAlive(), is(true)); }
@Test public void getNativeQueryOutputArrayMetadata() throws Exception { location = builder().globalName(NATIVE_QUERY_LIST_FLOW).addProcessorsPart().addIndexPart(0).build(); MetadataKey nativeKey = newKey(NATIVE_QUERY).build(); MetadataResult<ComponentMetadataDescriptor<OperationModel>> entityMetadata = getComponentDynamicMetadata(nativeKey); assertThat(entityMetadata.isSuccess(), is(true)); MetadataType generatedType = entityMetadata.get().getModel().getOutput().getType(); assertThat(generatedType, is(instanceOf(ArrayType.class))); assertCircleType((ObjectType) ((ArrayType) generatedType).getType()); }
@Test public void getOperationMetadataWithRuntimeException() throws Exception { location = builder().globalName(FAIL_WITH_RUNTIME_EXCEPTION).addProcessorsPart().addIndexPart(0).build(); MetadataResult<ComponentMetadataDescriptor<OperationModel>> metadata = getComponentDynamicMetadata(PERSON_METADATA_KEY); assertFailureResult(metadata, 2); assertMetadataFailure(metadata.getFailures().get(0), "", UNKNOWN, "", OUTPUT_PAYLOAD); assertMetadataFailure(metadata.getFailures().get(1), "", UNKNOWN, "", INPUT, "content"); }
@Test public void getKeysWithRuntimeException() throws Exception { location = builder().globalName(FAIL_WITH_RUNTIME_EXCEPTION).addProcessorsPart().addIndexPart(0).build(); MetadataResult<MetadataKeysContainer> metadata = metadataService.getMetadataKeys(location); assertFailureResult(metadata, 1); assertMetadataFailure(metadata.getFailures().get(0), "", UNKNOWN, RuntimeException.class.getName(), KEYS); }
@Test public void testConnection() { when(mockConnectivityTestingStrategy.testConnectivity(fakeConnectivityTestingObject)).thenReturn(success()); ConnectionValidationResult validationResult = connectivityTestingService.testConnection(builder().globalName(TEST_IDENTIFIER).build()); assertThat(validationResult.isValid(), is(true)); }