use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_POSTMethodBodyTest method shouldProcessAsynchronouslyIfAcceptedResponseTypePresent.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldProcessAsynchronouslyIfAcceptedResponseTypePresent() throws Exception {
final Map<String, org.raml.model.Response> responses = new HashMap<>();
responses.put(valueOf(INTERNAL_SERVER_ERROR.getStatusCode()), response().build());
responses.put(valueOf(BAD_REQUEST.getStatusCode()), response().build());
responses.put(valueOf(ACCEPTED.getStatusCode()), response().build());
generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(POST).withHttpActionOfDefaultRequestType().withResponsesFrom(responses))).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);
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_POSTMethodBodyTest method shouldPassMapWithOnePathParamToRestProcessor.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void shouldPassMapWithOnePathParamToRestProcessor() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/some/path/{paramA}", "paramA").with(httpActionWithDefaultMapping(POST).withHttpActionOfDefaultRequestType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathParamAResource");
final Object resourceObject = getInstanceOf(resourceClass);
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject, "paramValue1234", 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("paramA"));
assertThat(pathParam.getStringValue(), is("paramValue1234"));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_SynchronousPATCHMethodBodyTest method shouldReturnResponseGeneratedByRestProcessor.
@SuppressWarnings("unchecked")
@Test
public void shouldReturnResponseGeneratedByRestProcessor() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(PATCH).withHttpActionOfDefaultRequestAndResponseType())).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_SynchronousPUTMethodBodyTest method shouldReturnResponseGeneratedByRestProcessor.
@SuppressWarnings("unchecked")
@Test
public void shouldReturnResponseGeneratedByRestProcessor() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(PUT).withHttpActionOfDefaultRequestAndResponseType())).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_PATCHMethodBodyTest method shouldCallInterceptorChainProcessor.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldCallInterceptorChainProcessor() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(PATCH).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