@Override protected void onSource(WithSourcesDeclaration owner, SourceDeclaration source) { source.getModelProperty(ImplementingTypeModelProperty.class) .map(ImplementingTypeModelProperty::getType) .ifPresent(clazz -> { getOutputType(clazz).ifPresent(type -> declareCustomType(source.getOutput(), type)); getAttributesType(clazz).ifPresent(type -> declareCustomType(source.getOutputAttributes(), type)); }); source.getSuccessCallback().ifPresent(this::declareParametersCustomStaticTypes); source.getErrorCallback().ifPresent(this::declareParametersCustomStaticTypes); }
private void assertTestModuleMessageSource(ExtensionDeclaration extensionDeclaration) throws Exception { assertThat(extensionDeclaration.getMessageSources(), hasSize(1)); SourceDeclaration source = extensionDeclaration.getMessageSources().get(0); assertThat(source.getName(), is(DEA_SOURCE_NAME)); final MetadataType outputType = source.getOutput().getType(); assertThat(outputType, is(instanceOf(ArrayType.class))); MetadataType outputMetadataType = IntrospectionUtils.getReturnType(new TypeWrapper(Object.class, TYPE_LOADER)); assertMessageType(((ArrayType) outputType).getType(), STRING_TYPE, TYPE_LOADER.load(DEAOfficerAttributes.class)); assertThat(source.getOutputAttributes().getType(), equalTo(outputMetadataType)); ConfigurationDeclaration config = extensionDeclaration.getConfigurations().get(0); assertThat(config.getMessageSources(), hasSize(3)); assertHeisenbergSource(config.getMessageSources().get(0), ASYNC_SOURCE_NAME, AsyncHeisenbergSource.class); assertHeisenbergSource(config.getMessageSources().get(1), SOURCE_NAME, HeisenbergSource.class); }
@Override protected void onSource(WithSourcesDeclaration owner, SourceDeclaration source) { source.getModelProperty(ImplementingTypeModelProperty.class) .map(ImplementingTypeModelProperty::getType) .ifPresent(clazz -> { getOutputType(clazz).ifPresent(type -> declareCustomType(source.getOutput(), type)); getAttributesType(clazz).ifPresent(type -> declareCustomType(source.getOutputAttributes(), type)); }); source.getSuccessCallback().ifPresent(this::declareParametersCustomStaticTypes); source.getErrorCallback().ifPresent(this::declareParametersCustomStaticTypes); }
@Test public void declareStaticAndDynamicTypesInSource() { List<SourceDeclaration> messageSources = declaration.getConfigurations().get(0).getMessageSources(); SourceDeclaration sourceDynamicAttributes = getDeclaration(messageSources, "MetadataSource"); assertOutputType(sourceDynamicAttributes.getOutput(), TYPE_BUILDER.objectType() .with(new ClassInformationAnnotation(Map.class, asList(String.class, Object.class))) .openWith(TYPE_LOADER.load(Object.class)).build(), true); assertOutputType(sourceDynamicAttributes.getOutputAttributes(), toMetadataType(StringAttributes.class), false); assertParameterType(getDeclaration(sourceDynamicAttributes.getAllParameters(), "type"), toMetadataType(String.class)); messageSources = declaration.getMessageSources(); SourceDeclaration sourceStaticAttributes = getDeclaration(messageSources, "MetadataSourceWithMultilevel"); assertOutputType(sourceStaticAttributes.getOutput(), TYPE_BUILDER.objectType() .with(new ClassInformationAnnotation(Map.class, asList(String.class, Object.class))) .openWith(TYPE_LOADER.load(Object.class)).build(), true); assertOutputType(sourceStaticAttributes.getOutputAttributes(), toMetadataType(StringAttributes.class), false); List<ParameterDeclaration> locationKey = sourceStaticAttributes.getAllParameters(); assertParameterType(getDeclaration(locationKey, "continent"), toMetadataType(String.class)); assertParameterType(getDeclaration(locationKey, "country"), toMetadataType(String.class)); assertParameterType(getDeclaration(locationKey, "city"), toMetadataType(String.class)); }