Search in sources :

Example 51 with CommonGeneratorProperties

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

the class RestAdapterGenerator_ActionMapperTest method shouldReturnActionNameForPATCHResource.

@Test
public void shouldReturnActionNameForPATCHResource() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/case").with(httpActionWithDefaultMapping(PATCH).with(mapping().withName("contextB.someAction").withRequestType("application/vnd.ctx.command.somemediatype1+json")).with(mapping().withName("contextB.someOtherAction").withRequestType("application/vnd.ctx.command.somemediatype2+json")).withMediaTypeWithDefaultSchema("application/vnd.ctx.command.somemediatype1+json").withMediaTypeWithDefaultSchema("application/vnd.ctx.command.somemediatype2+json"))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> mapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "DefaultCommandApiCaseResourceActionMapper");
    final Object mapperObject = mapperClass.getConstructor(ActionMapperHelper.class).newInstance(new BasicActionMapperHelper());
    final Method actionMethod = methodOf(mapperClass, "actionOf").get();
    final Object firstAction = actionMethod.invoke(mapperObject, "patchContextBSomeActionCase", "PATCH", headersWith("Content-Type", "application/vnd.ctx.command.somemediatype1+json"));
    assertThat(firstAction, is("contextB.someAction"));
    final Object secondAction = actionMethod.invoke(mapperObject, "patchContextBSomeOtherActionCase", "PATCH", headersWith("Content-Type", "application/vnd.ctx.command.somemediatype2+json"));
    assertThat(secondAction, is("contextB.someOtherAction"));
}
Also used : CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) ActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.ActionMapperHelper) BasicActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper) Method(java.lang.reflect.Method) BasicActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper) Test(org.junit.Test)

Example 52 with CommonGeneratorProperties

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

the class RestAdapterGenerator_ActionMapperTest method shouldReturnActionNameForPUTResource.

@Test
public void shouldReturnActionNameForPUTResource() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/case").with(httpActionWithDefaultMapping(PUT).with(mapping().withName("contextB.someAction").withRequestType("application/vnd.ctx.command.somemediatype1+json")).with(mapping().withName("contextB.someOtherAction").withRequestType("application/vnd.ctx.command.somemediatype2+json")).withMediaTypeWithDefaultSchema("application/vnd.ctx.command.somemediatype1+json").withMediaTypeWithDefaultSchema("application/vnd.ctx.command.somemediatype2+json"))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> mapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "DefaultCommandApiCaseResourceActionMapper");
    final Object mapperObject = mapperClass.getConstructor(ActionMapperHelper.class).newInstance(new BasicActionMapperHelper());
    final Method actionMethod = methodOf(mapperClass, "actionOf").get();
    final Object firstAction = actionMethod.invoke(mapperObject, "putContextBSomeActionCase", "PUT", headersWith("Content-Type", "application/vnd.ctx.command.somemediatype1+json"));
    assertThat(firstAction, is("contextB.someAction"));
    final Object secondAction = actionMethod.invoke(mapperObject, "putContextBSomeOtherActionCase", "PUT", headersWith("Content-Type", "application/vnd.ctx.command.somemediatype2+json"));
    assertThat(secondAction, is("contextB.someOtherAction"));
}
Also used : CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) ActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.ActionMapperHelper) BasicActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper) Method(java.lang.reflect.Method) BasicActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper) Test(org.junit.Test)

Example 53 with CommonGeneratorProperties

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

the class RestAdapterGenerator_ActionMapperTest method shouldReturnActionNameForPOSTAndGETResource.

@Test
public void shouldReturnActionNameForPOSTAndGETResource() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/case").with(httpActionWithDefaultMapping(POST).with(mapping().withName("contextC.commandAction").withRequestType("application/vnd.somemediatype1+json")).withMediaTypeWithDefaultSchema("application/vnd.somemediatype1+json")).with(httpActionWithDefaultMapping(GET).with(mapping().withName("contextC.queryAction").withResponseType("application/vnd.mediatype1+json")).withResponseTypes("application/vnd.mediatype1+json"))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> mapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "DefaultCommandApiCaseResourceActionMapper");
    final Object mapperObject = mapperClass.getConstructor(ActionMapperHelper.class).newInstance(new BasicActionMapperHelper());
    final Method actionMethod = methodOf(mapperClass, "actionOf").get();
    Object action = actionMethod.invoke(mapperObject, "postContextCCommandActionCase", "POST", headersWith("Content-Type", "application/vnd.somemediatype1+json"));
    assertThat(action, is("contextC.commandAction"));
    action = actionMethod.invoke(mapperObject, "getCase", "GET", headersWith("Accept", "application/vnd.mediatype1+json"));
    assertThat(action, is("contextC.queryAction"));
}
Also used : CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) ActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.ActionMapperHelper) BasicActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper) Method(java.lang.reflect.Method) BasicActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper) Test(org.junit.Test)

Example 54 with CommonGeneratorProperties

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

the class RestAdapterGenerator_ActionMapperTest method shouldReturnActionNameForDELETEResource.

@Test
public void shouldReturnActionNameForDELETEResource() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/case").with(httpActionWithDefaultMapping(DELETE).with(mapping().withName("contextB.someAction").withRequestType("application/vnd.ctx.command.somemediatype1+json")).with(mapping().withName("contextB.someOtherAction").withRequestType("application/vnd.ctx.command.somemediatype2+json")).withMediaTypeWithDefaultSchema("application/vnd.ctx.command.somemediatype1+json").withMediaTypeWithDefaultSchema("application/vnd.ctx.command.somemediatype2+json"))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> mapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "DefaultCommandApiCaseResourceActionMapper");
    final Object mapperObject = mapperClass.getConstructor(ActionMapperHelper.class).newInstance(new BasicActionMapperHelper());
    final Method actionMethod = methodOf(mapperClass, "actionOf").get();
    final Object firstAction = actionMethod.invoke(mapperObject, "deleteContextBSomeActionCase", "DELETE", headersWith("Content-Type", "application/vnd.ctx.command.somemediatype1+json"));
    assertThat(firstAction, is("contextB.someAction"));
    final Object secondAction = actionMethod.invoke(mapperObject, "deleteContextBSomeOtherActionCase", "DELETE", headersWith("Content-Type", "application/vnd.ctx.command.somemediatype2+json"));
    assertThat(secondAction, is("contextB.someOtherAction"));
}
Also used : CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) ActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.ActionMapperHelper) BasicActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper) Method(java.lang.reflect.Method) BasicActionMapperHelper(uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper) Test(org.junit.Test)

Example 55 with CommonGeneratorProperties

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

the class RestAdapterGenerator_DELETEMethodBodyTest method shouldReturnResponseGeneratedByRestProcessor.

@SuppressWarnings("unchecked")
@Test
public void shouldReturnResponseGeneratedByRestProcessor() 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 Response processorResponse = Response.ok().build();
    when(restProcessor.process(anyString(), any(Function.class), anyString(), any(Optional.class), any(HttpHeaders.class), any(Collection.class))).thenReturn(processorResponse);
    final Method method = firstMethodOf(resourceClass).get();
    Object result = method.invoke(resourceObject, NOT_USED_JSONOBJECT);
    assertThat(result, is(processorResponse));
}
Also used : Response(javax.ws.rs.core.Response) Function(java.util.function.Function) HttpHeaders(javax.ws.rs.core.HttpHeaders) Optional(java.util.Optional) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) JsonObject(javax.json.JsonObject) 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