use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_DELETEMethodBodyTest method shouldCallInterceptorChainProcessor.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldCallInterceptorChainProcessor() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(DELETE).withHttpActionOfDefaultRequestType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiPathResource");
final Object resourceObject = getInstanceOf(resourceClass);
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject, NOT_USED_JSONOBJECT);
final ArgumentCaptor<Function> functionCaptor = ArgumentCaptor.forClass(Function.class);
verify(restProcessor).process(anyString(), functionCaptor.capture(), anyString(), any(Optional.class), any(HttpHeaders.class), any(Collection.class));
final JsonEnvelope envelope = mock(JsonEnvelope.class);
final InterceptorContext interceptorContext = interceptorContextWithInput(envelope);
functionCaptor.getValue().apply(interceptorContext);
verify(interceptorChainProcessor).process(interceptorContext);
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceInterfaceWithTwoPOSTMethods.
@Test
public void shouldGenerateResourceInterfaceWithTwoPOSTMethods() throws Exception {
generator.run(restRamlWithDefaults().with(resource("/some/path/{p1}").with(httpActionWithDefaultMapping(POST, "application/vnd.ctx.command.cmd-a+json", "application/vnd.ctx.command.cmd-b+json").with(mapping().withName("blah1").withRequestType("application/vnd.ctx.command.cmd-a+json")).with(mapping().withName("blah2").withRequestType("application/vnd.ctx.command.cmd-b+json")))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> interfaceClass = compiler.compiledInterfaceOf(RESOURCE_PACKAGE);
final List<Method> methods = methodsOf(interfaceClass);
assertThat(methods, hasSize(2));
final Method method1 = methodWithConsumesAnnotationOf(methods, "application/vnd.ctx.command.cmd-a+json");
assertThat(method1.getReturnType(), equalTo(Response.class));
assertThat(method1.getAnnotation(POST.class), not(nullValue()));
assertThat(method1.getAnnotation(Consumes.class), not(nullValue()));
assertThat(method1.getAnnotation(Consumes.class).value(), is(new String[] { "application/vnd.ctx.command.cmd-a+json" }));
final Method method2 = methodWithConsumesAnnotationOf(methods, "application/vnd.ctx.command.cmd-b+json");
assertThat(method2.getReturnType(), equalTo(Response.class));
assertThat(method2.getAnnotation(POST.class), not(nullValue()));
assertThat(method2.getAnnotation(Consumes.class), not(nullValue()));
assertThat(method2.getAnnotation(Consumes.class).value(), is(new String[] { "application/vnd.ctx.command.cmd-b+json" }));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldAddInterceptorChainProcessorIfThereIsGETResourceInRAML.
@Test
public void shouldAddInterceptorChainProcessorIfThereIsGETResourceInRAML() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(defaultGetResource().withRelativeUri("/some/path")).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathResource");
final Field dispatcher = resourceClass.getDeclaredField(INTERCEPTOR_CHAIN_PROCESSOR);
assertThat(dispatcher, not(nullValue()));
assertThat(dispatcher.getType(), equalTo(InterceptorChainProcessor.class));
assertThat(dispatcher.getAnnotation(Inject.class), not(nullValue()));
assertThat(dispatcher.getModifiers(), is(0));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateInterfaceInSpecifiedPackage.
@Test
public void shouldGenerateInterfaceInSpecifiedPackage() throws Exception {
final String basePackageName = "uk.gov.test1";
java.nio.file.Path outputPath = get(outputFolder.getRoot().getAbsolutePath());
final GeneratorConfig config = new GeneratorConfig(outputPath, outputPath, basePackageName, new CommonGeneratorProperties(), singletonList(outputPath.getParent()));
generator.run(restRamlWithDefaults().with(defaultPostResource()).build(), config);
final Class<?> interfaceClass = compiler.compiledInterfaceOf(basePackageName + ".resource");
assertThat(interfaceClass.getPackage().getName(), is(basePackageName + ".resource"));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceClassWithOnePATCHMethod.
@Test
public void shouldGenerateResourceClassWithOnePATCHMethod() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(defaultPatchResource().withRelativeUri("/some/path")).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> class1 = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathResource");
final List<Method> methods = methodsOf(class1);
assertThat(methods, hasSize(1));
final Method method = methods.get(0);
assertThat(method.getReturnType(), equalTo(Response.class));
assertThat(method.getParameterCount(), is(1));
assertThat(method.getParameters()[0].getType(), equalTo(JsonObject.class));
}
Aggregations