use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_GETMethodBodyTest method shouldPassTwoPathParamsToRestProcessor.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void shouldPassTwoPathParamsToRestProcessor() throws Exception {
generator.run(restRamlWithQueryApiDefaults().with(resource("/some/path/{param1}/{param2}", "param1", "param2").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultQueryApiSomePathParam1Param2Resource");
final Object resourceObject = getInstanceOf(resourceClass);
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject, "paramValueABC", "paramValueDEF");
final ArgumentCaptor<Collection> pathParamsCaptor = ArgumentCaptor.forClass(Collection.class);
verify(restProcessor).process(anyString(), any(Function.class), anyString(), any(HttpHeaders.class), pathParamsCaptor.capture());
final Collection<Parameter> pathParams = pathParamsCaptor.getValue();
assertThat(pathParams, hasSize(2));
assertThat(pathParams, hasItems(allOf(hasProperty("name", equalTo("param1")), hasProperty("stringValue", equalTo("paramValueABC"))), allOf(hasProperty("name", equalTo("param2")), hasProperty("stringValue", equalTo("paramValueDEF")))));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_MultipartCodeStructureTest method shouldGenerateInterfaceThatContainsMethodWithMultipartParameter.
@Test
public void shouldGenerateInterfaceThatContainsMethodWithMultipartParameter() 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.getParameterCount(), is(1));
final Parameter parameter = method.getParameters()[0];
assertThat(parameter.getType(), equalTo(MultipartFormDataInput.class));
assertThat(parameter.getAnnotation(MultipartForm.class), not(nullValue()));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_POSTMethodBodyTest method shouldPassMapWithTwoPathParamsToRestProcessor.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void shouldPassMapWithTwoPathParamsToRestProcessor() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/some/path/{param1}/{param2}", "param1", "param2").with(httpActionWithDefaultMapping(POST).withHttpActionOfDefaultRequestType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathParam1Param2Resource");
final Object resourceObject = getInstanceOf(resourceClass);
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject, "paramValueABC", "paramValueDEF", NOT_USED_JSONOBJECT);
final ArgumentCaptor<Collection> pathParamsCaptor = ArgumentCaptor.forClass(Collection.class);
verify(restProcessor).process(anyString(), any(Function.class), anyString(), any(Optional.class), any(HttpHeaders.class), pathParamsCaptor.capture());
final Collection<Parameter> pathParams = pathParamsCaptor.getValue();
assertThat(pathParams, hasSize(2));
assertThat(pathParams, hasItems(allOf(hasProperty("name", equalTo("param1")), hasProperty("stringValue", equalTo("paramValueABC"))), allOf(hasProperty("name", equalTo("param2")), hasProperty("stringValue", equalTo("paramValueDEF")))));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_POSTMethodBodyTest method shouldReturnResponseGeneratedByRestProcessor.
@SuppressWarnings("unchecked")
@Test
public void shouldReturnResponseGeneratedByRestProcessor() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(POST).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();
final Object result = method.invoke(resourceObject, NOT_USED_JSONOBJECT);
assertThat(result, is(processorResponse));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_POSTMethodBodyTest method shouldPassHttpHeadersToRestProcessor.
@SuppressWarnings("unchecked")
@Test
public void shouldPassHttpHeadersToRestProcessor() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(POST).withHttpActionOfDefaultRequestType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiPathResource");
final Object resourceObject = getInstanceOf(resourceClass);
final HttpHeaders headers = new ThreadLocalHttpHeaders();
setField(resourceObject, "headers", headers);
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject, NOT_USED_JSONOBJECT);
verify(restProcessor).process(anyString(), any(Function.class), anyString(), any(Optional.class), eq(headers), any(Collection.class));
}
Aggregations