Search in sources :

Example 1 with CommonGeneratorProperties

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

the class ActionNameToMediaTypesGeneratorTest method shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithPost.

@Test
public void shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithPost() throws Exception {
    final String actionName = "contextA.someAction";
    final String requestType = "application/vnd.ctx.query.somemediatype1+json";
    final String responseType = "application/vnd.ctx.query.somemediatype2+json";
    final String description = mappingDescriptionWith(mapping().withName(actionName).withRequestType(requestType).withResponseType(responseType)).build();
    new ActionNameToMediaTypesGenerator().generateActionNameToMediaTypes(restRamlWithQueryApiDefaults().with(resource("/user").with(httpAction(POST).withDescription(description).withMediaTypeWithDefaultSchema(requestType).withResponseTypes(responseType))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> mediaTypesMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "WarnameActionNameToMediaTypesMapper");
    final ActionNameToMediaTypesMapper instance = (ActionNameToMediaTypesMapper) mediaTypesMapperClass.newInstance();
    final Map<String, MediaTypes> actionNameToMediaTypesMap = instance.getActionNameToMediaTypesMap();
    assertThat(actionNameToMediaTypesMap.size(), is(1));
    assertThat(actionNameToMediaTypesMap.get(actionName).getRequestMediaType(), is(Optional.of(new MediaType(requestType))));
    assertThat(actionNameToMediaTypesMap.get(actionName).getResponseMediaType(), is(Optional.of(new MediaType(responseType))));
}
Also used : ActionNameToMediaTypesMapper(uk.gov.justice.services.core.mapping.ActionNameToMediaTypesMapper) MediaType(uk.gov.justice.services.core.mapping.MediaType) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) MediaTypes(uk.gov.justice.services.core.mapping.MediaTypes) Test(org.junit.Test)

Example 2 with CommonGeneratorProperties

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

the class ActionNameToMediaTypesGeneratorTest method shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithGet.

@Test
public void shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithGet() throws Exception {
    final String actionName_1 = "contextA.someAction";
    final String responseType_1 = "application/vnd.ctx.query.somemediatype1+json";
    final String actionName_2 = "contextA.someOtherAction";
    final String responseType_2 = "application/vnd.ctx.query.somemediatype2+json";
    new ActionNameToMediaTypesGenerator().generateActionNameToMediaTypes(restRamlWithQueryApiDefaults().with(resource("/user").with(httpAction(GET).withDescription(mappingDescriptionWith(mapping().withName(actionName_1).withResponseType(responseType_1), mapping().withName(actionName_2).withResponseType(responseType_2)).build()).withResponseTypes(responseType_1, responseType_2))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> mediaTypesMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "WarnameActionNameToMediaTypesMapper");
    final ActionNameToMediaTypesMapper instance = (ActionNameToMediaTypesMapper) mediaTypesMapperClass.newInstance();
    final Map<String, MediaTypes> actionNameToMediaTypesMap = instance.getActionNameToMediaTypesMap();
    assertThat(actionNameToMediaTypesMap.size(), is(2));
    assertThat(actionNameToMediaTypesMap.get(actionName_1).getResponseMediaType(), is(Optional.of(new MediaType(responseType_1))));
    assertThat(actionNameToMediaTypesMap.get(actionName_1).getRequestMediaType(), is(Optional.empty()));
    assertThat(actionNameToMediaTypesMap.get(actionName_2).getResponseMediaType(), is(Optional.of(new MediaType(responseType_2))));
    assertThat(actionNameToMediaTypesMap.get(actionName_2).getRequestMediaType(), is(Optional.empty()));
}
Also used : ActionNameToMediaTypesMapper(uk.gov.justice.services.core.mapping.ActionNameToMediaTypesMapper) MediaType(uk.gov.justice.services.core.mapping.MediaType) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) MediaTypes(uk.gov.justice.services.core.mapping.MediaTypes) Test(org.junit.Test)

Example 3 with CommonGeneratorProperties

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

the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceClassWithOneDELETEMethod.

@Test
public void shouldGenerateResourceClassWithOneDELETEMethod() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(defaultDeleteResource().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)

Example 4 with CommonGeneratorProperties

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

the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceInterfaceWithOneGETMethod.

@Test
public void shouldGenerateResourceInterfaceWithOneGETMethod() throws Exception {
    generator.run(restRamlWithDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(GET).withResponseTypes("application/vnd.ctx.query.query1+json").with(mapping().withResponseType("application/vnd.ctx.query.query1+json").withName("blah")))).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(javax.ws.rs.GET.class), not(nullValue()));
    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) Produces(javax.ws.rs.Produces) GET(org.raml.model.ActionType.GET) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 5 with CommonGeneratorProperties

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

the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceInterfaceWithOnePOSTMethod.

@Test
public void shouldGenerateResourceInterfaceWithOnePOSTMethod() throws Exception {
    generator.run(restRamlWithDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(POST, "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(POST.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) 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)

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