Search in sources :

Example 56 with CommonGeneratorProperties

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);
}
Also used : Function(java.util.function.Function) HttpHeaders(javax.ws.rs.core.HttpHeaders) Optional(java.util.Optional) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) JsonObject(javax.json.JsonObject) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 57 with CommonGeneratorProperties

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" }));
}
Also used : Response(javax.ws.rs.core.Response) POST(javax.ws.rs.POST) POST(org.raml.model.ActionType.POST) Consumes(javax.ws.rs.Consumes) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 58 with CommonGeneratorProperties

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));
}
Also used : Inject(javax.inject.Inject) Field(java.lang.reflect.Field) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) InterceptorChainProcessor(uk.gov.justice.services.core.interceptor.InterceptorChainProcessor) Test(org.junit.Test)

Example 59 with CommonGeneratorProperties

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"));
}
Also used : CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) GeneratorConfig(uk.gov.justice.maven.generator.io.files.parser.core.GeneratorConfig) Test(org.junit.Test)

Example 60 with CommonGeneratorProperties

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));
}
Also used : Response(javax.ws.rs.core.Response) JsonObject(javax.json.JsonObject) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)96 Test (org.junit.Test)93 Method (java.lang.reflect.Method)72 Collection (java.util.Collection)33 HttpHeaders (javax.ws.rs.core.HttpHeaders)33 Function (java.util.function.Function)32 JsonObject (javax.json.JsonObject)31 Response (javax.ws.rs.core.Response)30 ThreadLocalHttpHeaders (org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders)21 Optional (java.util.Optional)18 ActionMapperHelper (uk.gov.justice.services.adapter.rest.mapping.ActionMapperHelper)11 BasicActionMapperHelper (uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper)11 Parameter (uk.gov.justice.services.adapter.rest.parameter.Parameter)10 Consumes (javax.ws.rs.Consumes)9 Field (java.lang.reflect.Field)7 Parameter (java.lang.reflect.Parameter)7 Produces (javax.ws.rs.Produces)6 InterceptorContext (uk.gov.justice.services.core.interceptor.InterceptorContext)6 MediaType (uk.gov.justice.services.core.mapping.MediaType)6 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)6