@Before public void before() { when(extensionLoadingContext.getExtensionDeclarer()).thenReturn(extensionDeclarer); when(extensionDeclarer.getDeclaration()).thenReturn(extensionDeclaration); when(extensionDeclaration.getMessageSources()).thenReturn(asList(sourceDeclaration)); when(sourceDeclaration.getParameterGroup(DEFAULT_GROUP_NAME)).thenReturn(parameterGroup); when(sourceDeclaration.getSuccessCallback()).thenReturn(empty()); when(sourceDeclaration.getErrorCallback()).thenReturn(empty()); }
@Before public void before() { when(extensionLoadingContext.getExtensionDeclarer()).thenReturn(extensionDeclarer); when(extensionDeclarer.getDeclaration()).thenReturn(extensionDeclaration); when(extensionDeclaration.getOperations()).thenReturn(singletonList(operation)); when(extensionDeclaration.getMessageSources()).thenReturn(singletonList(source)); when(source.getSuccessCallback()).thenReturn(empty()); when(source.getErrorCallback()).thenReturn(empty()); when(source.getModelProperty(ExtensionTypeDescriptorModelProperty.class)).thenReturn(empty()); when(operation.getModelProperty(ExtensionOperationDescriptorModelProperty.class)).thenReturn(empty()); when(operation.getParameterGroup(DEFAULT_GROUP_NAME)).thenReturn(new ParameterGroupDeclaration(DEFAULT_GROUP_NAME)); when(source.getParameterGroup(DEFAULT_GROUP_NAME)).thenReturn(new ParameterGroupDeclaration(DEFAULT_GROUP_NAME)); mockMediaType(operation, false); mockMediaType(source, false); }
@Test public void deprecatedSourceTestCase() { ExtensionDeclaration extensionDeclaration = getEnrichedExtensionDeclaration(DeprecatedExtension.class); SourceDeclaration sourceDeclaration = (SourceDeclaration) getNamedDeclaration(extensionDeclaration.getMessageSources(), "DeprecatedSource"); assertTrue(sourceDeclaration.getDeprecation().isPresent()); assertThat(sourceDeclaration.getDeprecation().get().getMessage(), is("Use NonDeprecatedSource instead")); assertThat(sourceDeclaration.getDeprecation().get().getDeprecatedSince(), is("2.4.0")); assertTrue(sourceDeclaration.getDeprecation().get().getToRemoveIn().isPresent()); assertThat(sourceDeclaration.getDeprecation().get().getToRemoveIn().get(), is("3.0.0")); }
@Test public void nonDeprecatedSourceTestCase() { ExtensionDeclaration extensionDeclaration = getEnrichedExtensionDeclaration(DeprecatedExtension.class); SourceDeclaration sourceDeclaration = (SourceDeclaration) getNamedDeclaration(extensionDeclaration.getMessageSources(), "NonDeprecatedSource"); assertFalse(sourceDeclaration.getDeprecation().isPresent()); }
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); }
@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)); }