@Test public void pagedOperationResultMetadataTestCase() throws Exception { location = Location.builder().globalName(PAGED_OPERATION_METADATA_RESULT).addProcessorsPart().addIndexPart(0).build(); ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadata(PERSON_METADATA_KEY); MetadataType param = metadataDescriptor.getModel().getOutput().getType(); assertThat(param, is(instanceOf(ArrayType.class))); assertThat(getId(param).get(), is(Iterator.class.getName())); assertMessageType(((ArrayType) param).getType(), personType, TYPE_LOADER.load(Animal.class)); }
@Test public void operationReceivesListOfObjects() throws Exception { location = Location.builder().globalName("objectListAsInput").addProcessorsPart().addIndexPart(0).build(); MetadataResult<ComponentMetadataDescriptor<OperationModel>> operationMetadata = metadataService.getOperationMetadata(location); MetadataType objects = getParameter(operationMetadata.get().getModel(), "objects").getType(); assertThat(objects, is(instanceOf(ArrayType.class))); assertThat(((ArrayType) objects).getType(), is(personType)); }
@Test public void getMultilevelKeys() throws Exception { location = Location.builder().globalName(SIMPLE_MULTILEVEL_KEY_RESOLVER).addProcessorsPart().addIndexPart(0).build(); final MetadataResult<MetadataKeysContainer> metadataKeysResult = metadataService.getMetadataKeys(location); assertSuccessResult(metadataKeysResult); final Set<MetadataKey> continents = getKeysFromContainer(metadataKeysResult.get()); assertThat(continents, hasSize(2)); assertThat(continents, hasItem(metadataKeyWithId(AMERICA).withDisplayName(AMERICA).withPartName(CONTINENT))); assertThat(continents, hasItem(metadataKeyWithId(EUROPE).withDisplayName(EUROPE).withPartName(CONTINENT))); }
@Test public void operationWhichReturnsDynamicListOfObjects() throws Exception { location = Location.builder().globalName("dynamicListOfObjects").addProcessorsPart().addIndexPart(0).build(); MetadataType param = getResolvedTypeFromList(); assertExpectedType(((ArrayType) param).getType(), personType); }
@Test public void defaultValueMetadataKey() throws Exception { location = Location.builder().globalName(METADATA_KEY_DEFAULT_VALUE).addProcessorsPart().addIndexPart(0).build(); final MetadataResult<ComponentMetadataDescriptor<OperationModel>> result = metadataService.getOperationMetadata(location); assertSuccessResult(result); assertResolvedKey(result, CAR_KEY); ComponentMetadataDescriptor<OperationModel> descriptor = result.get(); MetadataType type = descriptor.getModel().getOutput().getType(); assertThat(type, is(instanceOf(ObjectType.class))); assertThat(((ObjectType) type).getFields(), hasSize(2)); }
@Test public void getContentMetadataWithoutRequiredKeyId() throws Exception { location = Location.builder().globalName(CONTENT_METADATA_WITH_KEY_ID).addProcessorsPart().addIndexPart(0).build(); final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadata(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 messageAttributesStringTypeMetadata() throws Exception { location = Location.builder().globalName(MESSAGE_ATTRIBUTES_PERSON_TYPE_METADATA).addProcessorsPart().addIndexPart(0).build(); final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadataWithKey(PERSON_METADATA_KEY); final OperationModel typedModel = metadataDescriptor.getModel(); assertExpectedOutput(typedModel, personType, StringAttributes.class); assertExpectedType(getParameter(typedModel, "type"), String.class); }
@Test public void dynamicContentWithoutOutput() throws Exception { // Resolver for content and output type, no return type, resolves only @Content, with key and KeyId location = Location.builder().globalName(CONTENT_ONLY_IGNORES_OUTPUT).addProcessorsPart().addIndexPart(0).build(); final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadataWithKey(PERSON_METADATA_KEY); final OperationModel typedModel = metadataDescriptor.getModel(); assertExpectedOutput(typedModel, void.class, void.class); assertExpectedType(getParameter(typedModel, "type"), String.class); assertExpectedType(getParameter(typedModel, "content"), personType, true); }
@Test public void injectComposedMetadataKeyIdInstanceInMetadataResolver() throws Exception { location = Location.builder().globalName(SIMPLE_MULTILEVEL_KEY_RESOLVER).addProcessorsPart().addIndexPart(0).build(); MetadataKey key = LOCATION_MULTILEVEL_KEY; final MetadataResult<ComponentMetadataDescriptor<OperationModel>> metadataResult = metadataService.getOperationMetadata(location, key); assertSuccessResult(metadataResult); assertResolvedKey(metadataResult, LOCATION_MULTILEVEL_KEY); }
@Test public void getNativeQueryOutputMetadata() throws Exception { location = builder().globalName(NATIVE_QUERY_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(); assertCircleType((ObjectType) generatedType); }
@Test public void resolveMetadataWithNoRefStaticConfig() throws Exception { location = builder().globalName(RESOLVER_WITH_IMPLICIT_STATIC_CONFIG).addProcessorsPart() .addIndexPart(0).build(); getSuccessComponentDynamicMetadata(LOCATION_MULTILEVEL_KEY); } }
@Test public void failToGetMetadataWithMissingMetadataKeyLevels() throws Exception { assumeThat(resolutionType, is(ResolutionType.EXPLICIT_RESOLUTION)); location = builder().globalName(INCOMPLETE_MULTILEVEL_KEY_RESOLVER).addProcessorsPart().addIndexPart(0).build(); final MetadataKey metadataKey = newKey(AMERICA, CONTINENT).withChild(newKey(USA, COUNTRY)).build(); final MetadataResult<ComponentMetadataDescriptor<OperationModel>> result = getComponentDynamicMetadata(metadataKey); assertMetadataFailure(result.getFailures().get(0), "Missing levels: [city]", INVALID_METADATA_KEY, "", COMPONENT); }
@Test public void failWithDynamicConfigurationWhenRetrievingMetadata() throws IOException { location = builder().globalName(RESOLVER_WITH_DYNAMIC_CONFIG).addProcessorsPart().addIndexPart(0).build(); MetadataKey key = newKey(AMERICA, CONTINENT).withChild(newKey(USA, COUNTRY).withChild(newKey(SAN_FRANCISCO, CITY))).build(); MetadataResult<ComponentMetadataDescriptor<OperationModel>> result = getComponentDynamicMetadata(key); assertFailureResult(result, 1); assertMetadataFailure(result.getFailures().get(0), CONFIGURATION_CANNOT_BE_DYNAMIC, INVALID_CONFIGURATION, MetadataResolvingException.class.getName(), COMPONENT); }
@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); }