use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldAddHeadersContext.
@Test
public void shouldAddHeadersContext() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(defaultPostResource().withRelativeUri("/some/path")).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathResource");
final Field dispatcher = resourceClass.getDeclaredField("headers");
assertThat(dispatcher, not(nullValue()));
assertThat(dispatcher.getType(), equalTo(HttpHeaders.class));
assertThat(dispatcher.getAnnotation(javax.ws.rs.core.Context.class), not(nullValue()));
assertThat(dispatcher.getModifiers(), is(0));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_GETMethodBodyTest method shouldPassOneQueryParamToRestProcessor.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void shouldPassOneQueryParamToRestProcessor() throws Exception {
generator.run(restRamlWithQueryApiDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(GET).with(queryParam("queryParam")).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, "paramValue1234");
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("stringValue", equalTo("paramValue1234")))));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_GETMethodBodyTest method shouldPassHttpHeadersToRestProcessor.
@SuppressWarnings("unchecked")
@Test
public void shouldPassHttpHeadersToRestProcessor() 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 HttpHeaders headers = new ThreadLocalHttpHeaders();
setField(resourceObject, "headers", headers);
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject);
verify(restProcessor).process(anyString(), any(Function.class), anyString(), eq(headers), any(Collection.class));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_GETMethodBodyTest method shouldPassOnePathParamToRestProcessor.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void shouldPassOnePathParamToRestProcessor() throws Exception {
generator.run(restRamlWithQueryApiDefaults().with(resource("/some/path/{paramA}", "paramA").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultQueryApiSomePathParamAResource");
final Object resourceObject = getInstanceOf(resourceClass);
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject, "paramValue1234");
final ArgumentCaptor<Collection> pathParamsCaptor = ArgumentCaptor.forClass(Collection.class);
verify(restProcessor).process(anyString(), any(Function.class), anyString(), any(HttpHeaders.class), pathParamsCaptor.capture());
Collection<Parameter> pathParams = pathParamsCaptor.getValue();
assertThat(pathParams, hasSize(1));
final Parameter pathParam = pathParams.iterator().next();
assertThat(pathParam.getName(), equalTo("paramA"));
assertThat(pathParam.getStringValue(), equalTo("paramValue1234"));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_GETMethodBodyTest method shouldRemoveOptionalQueryParamIfSetToNull.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void shouldRemoveOptionalQueryParamIfSetToNull() throws Exception {
generator.run(restRamlWithQueryApiDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(GET).with(queryParam("queryParam1").required(true), queryParam("queryParam2").required(false)).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();
boolean queryParam1IsFirstMethodParameter = method.getParameters()[0].getName().equals("queryParam1");
if (queryParam1IsFirstMethodParameter) {
method.invoke(resourceObject, "paramValueABC", NULL_STRING_VALUE);
} else {
method.invoke(resourceObject, NULL_STRING_VALUE, "paramValueABC");
}
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("queryParam1")), hasProperty("stringValue", equalTo("paramValueABC")))));
}
Aggregations