Search in sources :

Example 1 with CommonProviders

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")));
}
Also used : Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Set(java.util.Set) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) CommonProviders(uk.gov.justice.services.adapter.rest.application.CommonProviders) Test(org.junit.Test)

Example 2 with CommonProviders

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));
}
Also used : Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Set(java.util.Set) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) CommonProviders(uk.gov.justice.services.adapter.rest.application.CommonProviders) Test(org.junit.Test)

Aggregations

Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 Method (java.lang.reflect.Method)2 Set (java.util.Set)2 Test (org.junit.Test)2 CommonProviders (uk.gov.justice.services.adapter.rest.application.CommonProviders)2 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)2