use of uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_GETMethodBodyTest method shouldPassActionToRestProcessor.
@SuppressWarnings("unchecked")
@Test
public void shouldPassActionToRestProcessor() throws Exception {
generator.run(restRamlWithQueryApiDefaults().with(resource("/cake").with(httpActionWithDefaultMapping(GET).with(mapping().withName("contextA.action1").withResponseType("application/vnd.ctx.query.somemediatype1+json")).with(mapping().withName("contextA.action1").withResponseType("application/vnd.ctx.query.somemediatype2+json")).with(mapping().withName("contextA.action2").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<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultQueryApiCakeResource");
final Object resourceObject = getInstanceOf(resourceClass);
final Class<?> actionMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "DefaultQueryApiCakeResourceActionMapper");
final Object actionMapperObject = actionMapperClass.getConstructor(ActionMapperHelper.class).newInstance(new BasicActionMapperHelper());
setField(resourceObject, "actionMapper", actionMapperObject);
setField(resourceObject, "headers", headersWith("Accept", "application/vnd.ctx.query.somemediatype1+json"));
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject);
verify(restProcessor).process(anyString(), any(Function.class), eq("contextA.action1"), any(HttpHeaders.class), any(Collection.class));
}
use of uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper 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"));
}
use of uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper 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"));
}
use of uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper 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"));
}
use of uk.gov.justice.services.adapter.rest.mapping.BasicActionMapperHelper 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"));
}
Aggregations