use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_GETMethodBodyTest method shouldPassBooleanParamToRestProcessor.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void shouldPassBooleanParamToRestProcessor() throws Exception {
generator.run(restRamlWithQueryApiDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(GET).with(queryParam("queryParam").withType(BOOLEAN)).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultQueryApiSomePathResource");
final Object resourceObject = getInstanceOf(resourceClass);
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject, "false");
final ArgumentCaptor<Collection> queryParamsCaptor = ArgumentCaptor.forClass(Collection.class);
verify(restProcessor).process(anyString(), any(Function.class), anyString(), any(HttpHeaders.class), queryParamsCaptor.capture());
final Collection<Parameter> queryParams = queryParamsCaptor.getValue();
assertThat(queryParams, hasSize(1));
assertThat(queryParams, hasItems(allOf(hasProperty("name", equalTo("queryParam")), hasProperty("booleanValue", equalTo(false)))));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_GETMethodBodyTest method shouldCallInterceptorChainProcessor.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldCallInterceptorChainProcessor() throws Exception {
generator.run(restRamlWithQueryApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultQueryApiPathResource");
final Object resourceObject = getInstanceOf(resourceClass);
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject);
ArgumentCaptor<Function> consumerCaptor = ArgumentCaptor.forClass(Function.class);
verify(restProcessor).process(anyString(), consumerCaptor.capture(), anyString(), any(HttpHeaders.class), any(Collection.class));
final InterceptorContext interceptorContext = interceptorContextWithInput(mock(JsonEnvelope.class));
consumerCaptor.getValue().apply(interceptorContext);
verify(interceptorChainProcessor).process(interceptorContext);
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties 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.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_MultipartCodeStructureTest method shouldGenerateResourceInterfaceWithOnePOSTMethod.
@Test
public void shouldGenerateResourceInterfaceWithOnePOSTMethod() throws Exception {
generator.run(restRamlWithDefaults().with(resource("/some/path").with(httpAction().withHttpActionType(POST).withMediaTypeWithoutSchema(multipartWithFileFormParameter("photoId")).with(mapping().withName("upload").withRequestType(MULTIPART_FORM_DATA)))).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.POST.class), not(nullValue()));
assertThat(method.getAnnotation(Consumes.class), not(nullValue()));
assertThat(method.getAnnotation(Consumes.class).value(), is(new String[] { MULTIPART_FORM_DATA }));
assertThat(method.getAnnotation(Produces.class), is(nullValue()));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_MultipartCodeStructureTest method shouldGenerateInterfaceThatContainsMethodWithTwoPathParamsAndMultipartParameter.
@Test
public void shouldGenerateInterfaceThatContainsMethodWithTwoPathParamsAndMultipartParameter() throws Exception {
generator.run(restRamlWithDefaults().with(resource("/some/path").with(httpAction().withHttpActionType(POST).withMediaTypeWithoutSchema(multipartWithFileFormParameter("photoId")).with(mapping().withName("upload").withRequestType(MULTIPART_FORM_DATA))).withRelativeUri("/some/path/{paramA}/abc/{paramB}").withPathParam("paramA").withPathParam("paramB")).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.getParameterCount(), is(3));
final Parameter methodParam1 = method.getParameters()[0];
assertThat(methodParam1.getType(), equalTo(String.class));
assertThat(methodParam1.getAnnotations(), arrayWithSize(1));
assertThat(methodParam1.getAnnotations()[0].annotationType(), equalTo(PathParam.class));
assertThat(methodParam1.getAnnotation(PathParam.class).value(), is("paramA"));
final Parameter methodParam2 = method.getParameters()[1];
assertThat(methodParam2.getType(), equalTo(String.class));
assertThat(methodParam2.getAnnotations(), arrayWithSize(1));
assertThat(methodParam2.getAnnotations()[0].annotationType(), equalTo(PathParam.class));
assertThat(methodParam2.getAnnotation(PathParam.class).value(), is("paramB"));
final Parameter methodParam3 = method.getParameters()[2];
assertThat(methodParam3.getType(), equalTo(MultipartFormDataInput.class));
assertThat(methodParam3.getAnnotation(MultipartForm.class), not(nullValue()));
}
Aggregations