use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_MultipartCodeStructureTest method shouldGenerateResourceClassWithInjectedFileInputDetailsFactory.
@Test
public void shouldGenerateResourceClassWithInjectedFileInputDetailsFactory() throws Exception {
generator.run(restRamlWithCommandApiDefaults().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<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathResource");
final Field chainProcess = resourceClass.getDeclaredField("fileInputDetailsFactory");
assertThat(chainProcess, not(nullValue()));
assertThat(chainProcess.getType(), equalTo(FileInputDetailsFactory.class));
assertThat(chainProcess.getAnnotation(Inject.class), not(nullValue()));
assertThat(chainProcess.getModifiers(), is(0));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_MultipleMethodBodyTest method shouldReturnResponseGeneratedByRestProcessor.
@SuppressWarnings("unchecked")
@Test
public void shouldReturnResponseGeneratedByRestProcessor() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(GET).withDefaultResponseType()).with(httpActionWithDefaultMapping(POST).withHttpActionOfDefaultRequestType()).with(httpActionWithDefaultMapping(PUT).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(HttpHeaders.class), any(Collection.class))).thenReturn(processorResponse);
when(restProcessor.process(anyString(), any(Function.class), anyString(), any(Optional.class), any(HttpHeaders.class), any(Collection.class))).thenReturn(processorResponse);
final List<Method> methods = methodsOf(resourceClass);
for (final Method method : methods) {
final int parameterCount = method.getParameterCount();
final boolean isGetMethod = parameterCount == 0;
final Object result = isGetMethod ? method.invoke(resourceObject) : 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 shouldInvoke2ndMethodAndPassMapWithOnePathParamToRestProcessor.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void shouldInvoke2ndMethodAndPassMapWithOnePathParamToRestProcessor() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/some/path/{p1}", "p1").with(httpActionWithDefaultMapping(POST, "application/vnd.type-aa+json", "application/vnd.type-bb+json").with(mapping().withName("cmd-aa").withRequestType("application/vnd.type-aa+json")).with(mapping().withName("cmd-bb").withRequestType("application/vnd.type-bb+json")))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathP1Resource");
final Object resourceObject = getInstanceOf(resourceClass);
final List<Method> methods = methodsOf(resourceClass);
final Method secondMethod = methods.get(1);
secondMethod.invoke(resourceObject, "paramValueXYZ", 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(1));
final Parameter pathParam = pathParams.iterator().next();
assertThat(pathParam.getName(), is("p1"));
assertThat(pathParam.getStringValue(), is("paramValueXYZ"));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_POSTMethodBodyTest method shouldPassJsonObjectToRestProcessor.
@SuppressWarnings("unchecked")
@Test
public void shouldPassJsonObjectToRestProcessor() 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 Optional<JsonObject> jsonObject = Optional.of(Json.createObjectBuilder().add("dummy", "abc").build());
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject, jsonObject.get());
verify(restProcessor).process(anyString(), any(Function.class), anyString(), eq(jsonObject), 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_POSTMethodBodyTest method shouldCallInterceptorChainProcessor.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldCallInterceptorChainProcessor() 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 Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject, NOT_USED_JSONOBJECT);
final ArgumentCaptor<Function> functionCaptor = ArgumentCaptor.forClass(Function.class);
verify(restProcessor).process(anyString(), functionCaptor.capture(), anyString(), any(Optional.class), any(HttpHeaders.class), any(Collection.class));
final JsonEnvelope envelope = mock(JsonEnvelope.class);
final InterceptorContext interceptorContext = interceptorContextWithInput(envelope);
functionCaptor.getValue().apply(interceptorContext);
verify(interceptorChainProcessor).process(interceptorContext);
}
Aggregations