Search in sources :

Example 6 with BasicActionMapperHelper

use of uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_GETMethodBodyTest method shouldPassActionToRestProcessor2.

@SuppressWarnings("unchecked")
@Test
public void shouldPassActionToRestProcessor2() throws Exception {
    generator.run(restRamlWithQueryApiDefaults().with(resource("/recipe").with(httpActionWithDefaultMapping(GET).with(mapping().withName("contextB.action1").withResponseType("application/vnd.ctx.query.mediatype1+json")).withResponseTypes("application/vnd.ctx.query.mediatype1+json"))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultQueryApiRecipeResource");
    final Object resourceObject = getInstanceOf(resourceClass);
    final Class<?> actionMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "DefaultQueryApiRecipeResourceActionMapper");
    final Object actionMapperObject = actionMapperClass.getConstructor(ActionMapperHelper.class).newInstance(new BasicActionMapperHelper());
    setField(resourceObject, "actionMapper", actionMapperObject);
    setField(resourceObject, "headers", headersWith("Accept", "application/vnd.ctx.query.mediatype1+json"));
    final Method method = firstMethodOf(resourceClass).get();
    method.invoke(resourceObject);
    verify(restProcessor).process(anyString(), any(Function.class), eq("contextB.action1"), any(HttpHeaders.class), any(Collection.class));
}
Also used : Function(java.util.function.Function) HttpHeaders(javax.ws.rs.core.HttpHeaders) ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) Collection(java.util.Collection) 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 7 with BasicActionMapperHelper

use of uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_POSTMethodBodyTest method shouldPassActionToRestProcessor.

@SuppressWarnings("unchecked")
@Test
public void shouldPassActionToRestProcessor() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/user").with(httpActionWithDefaultMapping(POST).with(mapping().withName("contextA.someAction").withRequestType("application/vnd.somemediatype1+json")).withMediaTypeWithDefaultSchema("application/vnd.somemediatype1+json").withHttpActionResponseAndNoBody())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiUserResource");
    final Object resourceObject = getInstanceOf(resourceClass);
    final Class<?> actionMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "DefaultCommandApiUserResourceActionMapper");
    final Object actionMapperObject = actionMapperClass.getConstructor(ActionMapperHelper.class).newInstance(new BasicActionMapperHelper());
    setField(resourceObject, "actionMapper", actionMapperObject);
    setField(resourceObject, "headers", headersWith("Content-Type", "application/vnd.somemediatype1+json"));
    final Method method = firstMethodOf(resourceClass).get();
    method.invoke(resourceObject, NOT_USED_JSONOBJECT);
    verify(restProcessor).process(anyString(), any(Function.class), eq("contextA.someAction"), any(Optional.class), any(HttpHeaders.class), any(Collection.class));
}
Also used : Function(java.util.function.Function) HttpHeaders(javax.ws.rs.core.HttpHeaders) ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) Optional(java.util.Optional) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) JsonObject(javax.json.JsonObject) 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 8 with BasicActionMapperHelper

use of uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_ActionMapperTest method shouldReturnActionNameForGETResource2.

@Test
public void shouldReturnActionNameForGETResource2() throws Exception {
    generator.run(restRamlWithQueryApiDefaults().with(resource("/status").with(httpActionWithDefaultMapping(GET).with(mapping().withName("ctxA.actionA").withResponseType("application/vnd.ctx.query.mediatype1+json")).withResponseTypes("application/vnd.ctx.query.mediatype1+json"))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> mapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "DefaultQueryApiStatusResourceActionMapper");
    final Object mapperObject = mapperClass.getConstructor(ActionMapperHelper.class).newInstance(new BasicActionMapperHelper());
    final Method actionMethod = methodOf(mapperClass, "actionOf").get();
    final Object action = actionMethod.invoke(mapperObject, "getStatus", "GET", headersWith("Accept", "application/vnd.ctx.query.mediatype1+json"));
    assertThat(action, is("ctxA.actionA"));
}
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 9 with BasicActionMapperHelper

use of uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_ActionMapperTest method shouldReturnActionNameForGETResource.

@SuppressWarnings("unchecked")
@Test
public void shouldReturnActionNameForGETResource() throws Exception {
    generator.run(restRamlWithQueryApiDefaults().with(resource("/user").with(httpActionWithDefaultMapping(GET).with(mapping().withName("contextA.someAction").withResponseType("application/vnd.ctx.query.somemediatype1+json")).with(mapping().withName("contextA.someAction").withResponseType("application/vnd.ctx.query.somemediatype2+json")).with(mapping().withName("contextA.someOtherAction").withResponseType("application/vnd.ctx.query.somemediatype3+json")).withResponseTypes("application/vnd.ctx.query.somemediatype1+json", "application/vnd.ctx.query.somemediatype2+json", "application/vnd.ctx.query.somemediatype3+json"))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> mapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "DefaultQueryApiUserResourceActionMapper");
    final Object mapperObject = mapperClass.getConstructor(ActionMapperHelper.class).newInstance(new BasicActionMapperHelper());
    final Method actionMethod = methodOf(mapperClass, "actionOf").get();
    Object action = actionMethod.invoke(mapperObject, "getUser", "GET", headersWith("Accept", "application/vnd.ctx.query.somemediatype1+json"));
    assertThat(action, is("contextA.someAction"));
    action = actionMethod.invoke(mapperObject, "getUser", "GET", headersWith("Accept", "application/vnd.ctx.query.somemediatype2+json"));
    assertThat(action, is("contextA.someAction"));
    action = actionMethod.invoke(mapperObject, "getUser", "GET", headersWith("Accept", "application/vnd.ctx.query.somemediatype3+json"));
    assertThat(action, is("contextA.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 10 with BasicActionMapperHelper

use of uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_ActionMapperTest method shouldReturnActionNameForPOSTResource.

@Test
public void shouldReturnActionNameForPOSTResource() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/case").with(httpActionWithDefaultMapping(POST).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();
    Object action = actionMethod.invoke(mapperObject, "postContextBSomeActionCase", "POST", headersWith("Content-Type", "application/vnd.ctx.command.somemediatype1+json"));
    assertThat(action, is("contextB.someAction"));
    action = actionMethod.invoke(mapperObject, "postContextBSomeOtherActionCase", "POST", headersWith("Content-Type", "application/vnd.ctx.command.somemediatype2+json"));
    assertThat(action, 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)

Aggregations

Method (java.lang.reflect.Method)11 Test (org.junit.Test)11 ActionMapperHelper (uk.gov.justice.services.adapter.rest.mapping.ActionMapperHelper)11 BasicActionMapperHelper (uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper)11 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)11 Collection (java.util.Collection)3 Function (java.util.function.Function)3 HttpHeaders (javax.ws.rs.core.HttpHeaders)3 ThreadLocalHttpHeaders (org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders)3 Optional (java.util.Optional)1 JsonObject (javax.json.JsonObject)1