use of uk.gov.justice.services.adapter.rest.application.CommonProviders in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_ApplicationTest method shouldReturnSetOfResourceClasses.
@SuppressWarnings("unchecked")
@Test
public void shouldReturnSetOfResourceClasses() throws Exception {
generator.run(raml().withBaseUri("http://localhost:8080/warname/command/api/rest/service").with(resource("/pathA").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).with(resource("/pathB").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
Set<Class<?>> compiledClasses = compiler.compiledClassesOf(BASE_PACKAGE);
Class<?> applicationClass = compiler.classOf(compiledClasses, BASE_PACKAGE, "CommandApiRestServiceApplication");
Object application = applicationClass.newInstance();
CommonProviders commonProviders = mock(CommonProviders.class);
when(commonProviders.providers()).thenReturn(newHashSet(JaxRsProviderA.class));
setField(application, "commonProviders", commonProviders);
Method method = applicationClass.getDeclaredMethod("getClasses");
Object result = method.invoke(application);
assertThat(result, is(instanceOf(Set.class)));
Set<Class<?>> classes = (Set<Class<?>>) result;
assertThat(classes, hasItems(compiler.classOf(compiledClasses, BASE_PACKAGE, "resource", "DefaultCommandApiPathAResource"), compiler.classOf(compiledClasses, BASE_PACKAGE, "resource", "DefaultCommandApiPathBResource")));
}
use of uk.gov.justice.services.adapter.rest.application.CommonProviders in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_ApplicationTest method shouldIncludeStandardProviders.
@SuppressWarnings("unchecked")
@Test
public void shouldIncludeStandardProviders() throws Exception {
generator.run(restRamlWithDefaults().with(resource("/pathA").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
Set<Class<?>> compiledClasses = compiler.compiledClassesOf(BASE_PACKAGE);
Class<?> applicationClass = compiler.classOf(compiledClasses, BASE_PACKAGE, "CommandApiRestServiceApplication");
Object application = applicationClass.newInstance();
CommonProviders commonProviders = mock(CommonProviders.class);
when(commonProviders.providers()).thenReturn(newHashSet(JaxRsProviderA.class, JaxRsProviderB.class));
setField(application, "commonProviders", commonProviders);
Method method = applicationClass.getDeclaredMethod("getClasses");
Object result = method.invoke(application);
assertThat(result, is(instanceOf(Set.class)));
Set<Class<?>> classes = (Set<Class<?>>) result;
assertThat(classes, hasItems(JaxRsProviderA.class, JaxRsProviderB.class));
}
Aggregations