Search in sources :

Example 11 with BasicActionMapperHelper

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

the class RestAdapterGenerator_ActionMapperTest method shouldReturnActionNameForPOSTResourceSameActionMappedToTwoMediaTypes.

@Test
public void shouldReturnActionNameForPOSTResourceSameActionMappedToTwoMediaTypes() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/case").with(httpActionWithDefaultMapping(POST).with(mapping().withName("contextC.someAction").withRequestType("application/vnd.ctx.command.somemediatype1+json")).with(mapping().withName("contextD.someAction").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, "postContextCSomeActionCase", "POST", headersWith("Content-Type", "application/vnd.ctx.command.somemediatype1+json"));
    assertThat(action, is("contextC.someAction"));
    action = actionMethod.invoke(mapperObject, "postContextDSomeActionCase", "POST", headersWith("Content-Type", "application/vnd.ctx.command.somemediatype2+json"));
    assertThat(action, is("contextD.someAction"));
}
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