Search in sources :

Example 11 with CommonGeneratorProperties

use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_CodeStructureTest method shouldAddInterceptorChainProcessorIfThereIsPOSTResourceInRAML.

@Test
public void shouldAddInterceptorChainProcessorIfThereIsPOSTResourceInRAML() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(defaultPostResource().withRelativeUri("/some/path")).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathResource");
    final Field chainProcess = resourceClass.getDeclaredField(INTERCEPTOR_CHAIN_PROCESSOR);
    assertThat(chainProcess, not(nullValue()));
    assertThat(chainProcess.getType(), equalTo(InterceptorChainProcessor.class));
    assertThat(chainProcess.getAnnotation(Inject.class), not(nullValue()));
    assertThat(chainProcess.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 12 with CommonGeneratorProperties

use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceInterfaceWithOneDELETEMethod.

@Test
public void shouldGenerateResourceInterfaceWithOneDELETEMethod() throws Exception {
    generator.run(restRamlWithDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(DELETE, "application/vnd.default+json").with(mapping().withName("blah").withRequestType("application/vnd.default+json")))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> interfaceClass = compiler.compiledInterfaceOf(RESOURCE_PACKAGE);
    final List<Method> methods = methodsOf(interfaceClass);
    assertThat(methods, hasSize(1));
    final Method method = methods.get(0);
    assertThat(method.getReturnType(), equalTo(Response.class));
    assertThat(method.getAnnotation(DELETE.class), not(nullValue()));
    assertThat(method.getAnnotation(Consumes.class), not(nullValue()));
    assertThat(method.getAnnotation(Consumes.class).value(), is(new String[] { "application/vnd.default+json" }));
}
Also used : Response(javax.ws.rs.core.Response) DELETE(javax.ws.rs.DELETE) DELETE(org.raml.model.ActionType.DELETE) Consumes(javax.ws.rs.Consumes) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 13 with CommonGeneratorProperties

use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_CodeStructureTest method shouldAddActionMapperBean.

@Test
public void shouldAddActionMapperBean() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/user").with(defaultGetAction())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiUserResource");
    final Field mapping = resourceClass.getDeclaredField("actionMapper");
    assertThat(mapping, not(nullValue()));
    assertThat(mapping.getType(), equalTo(ActionMapper.class));
    assertThat(mapping.getAnnotation(Inject.class), not(nullValue()));
    assertThat(mapping.getAnnotation(Named.class), not(nullValue()));
    assertThat(mapping.getAnnotation(Named.class).value(), is("DefaultCommandApiUserResourceActionMapper"));
    assertThat(mapping.getModifiers(), is(0));
}
Also used : Inject(javax.inject.Inject) Field(java.lang.reflect.Field) Named(javax.inject.Named) ActionMapper(uk.gov.justice.services.adapter.rest.mapping.ActionMapper) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Test(org.junit.Test)

Example 14 with CommonGeneratorProperties

use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceInterfaceWithOneSynchronousPOSTMethod.

@Test
public void shouldGenerateResourceInterfaceWithOneSynchronousPOSTMethod() throws Exception {
    generator.run(restRamlWithDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(POST, "application/vnd.default+json").withResponseTypes("application/vnd.ctx.query.query1+json").with(mapping().withName("blah").withRequestType("application/vnd.default+json").withResponseType("application/vnd.ctx.query.query1+json")))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> interfaceClass = compiler.compiledInterfaceOf(RESOURCE_PACKAGE);
    final List<Method> methods = methodsOf(interfaceClass);
    assertThat(methods, hasSize(1));
    final Method method = methods.get(0);
    assertThat(method.getReturnType(), equalTo(Response.class));
    assertThat(method.getAnnotation(POST.class), not(nullValue()));
    assertThat(method.getAnnotation(Consumes.class), not(nullValue()));
    assertThat(method.getAnnotation(Consumes.class).value(), is(new String[] { "application/vnd.default+json" }));
    assertThat(method.getAnnotation(Produces.class), not(nullValue()));
    assertThat(method.getAnnotation(Produces.class).value(), is(new String[] { "application/vnd.ctx.query.query1+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) Produces(javax.ws.rs.Produces) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 15 with CommonGeneratorProperties

use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceInterfaceWithOneSynchronousPATCHMethod.

@Test
public void shouldGenerateResourceInterfaceWithOneSynchronousPATCHMethod() throws Exception {
    generator.run(restRamlWithDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(PATCH, "application/vnd.default+json").withResponseTypes("application/vnd.ctx.query.query1+json").with(mapping().withName("blah").withRequestType("application/vnd.default+json").withResponseType("application/vnd.ctx.query.query1+json")))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> interfaceClass = compiler.compiledInterfaceOf(RESOURCE_PACKAGE);
    final List<Method> methods = methodsOf(interfaceClass);
    assertThat(methods, hasSize(1));
    final Method method = methods.get(0);
    assertThat(method.getReturnType(), equalTo(Response.class));
    assertThat(method.getAnnotation(PATCH.class), not(nullValue()));
    assertThat(method.getAnnotation(Consumes.class), not(nullValue()));
    assertThat(method.getAnnotation(Consumes.class).value(), is(new String[] { "application/vnd.default+json" }));
    assertThat(method.getAnnotation(Produces.class), not(nullValue()));
    assertThat(method.getAnnotation(Produces.class).value(), is(new String[] { "application/vnd.ctx.query.query1+json" }));
}
Also used : Response(javax.ws.rs.core.Response) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) PATCH(uk.gov.justice.services.adapter.rest.annotation.PATCH) PATCH(org.raml.model.ActionType.PATCH) 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