use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldAddAnnotatedRestProcessorProperty.
@Test
public void shouldAddAnnotatedRestProcessorProperty() 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("restProcessor");
assertThat(dispatcher, not(nullValue()));
assertThat(dispatcher.getType(), equalTo(RestProcessor.class));
assertThat(dispatcher.getAnnotation(Inject.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_CodeStructureTest method shouldAddLoggerConstant.
@Test
public void shouldAddLoggerConstant() 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 logger = resourceClass.getDeclaredField("LOGGER");
assertThat(logger, not(nullValue()));
assertThat(logger.getType(), equalTo(Logger.class));
assertThat(isPrivate(logger.getModifiers()), is(true));
assertThat(isStatic(logger.getModifiers()), is(true));
assertThat(isFinal(logger.getModifiers()), is(true));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateClassContainingMethodWithPathParamAndBodyParam.
@Test
public void shouldGenerateClassContainingMethodWithPathParamAndBodyParam() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(defaultPostResource().withRelativeUri("/some/path/{paramA}").withPathParam("paramA")).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathParamAResource");
assertThat(clazz.isInterface(), is(false));
final List<Method> methods = methodsOf(clazz);
assertThat(methods, hasSize(1));
final Method method = methods.get(0);
assertThat(method.getParameterCount(), is(2));
final Parameter methodParam1 = method.getParameters()[0];
assertThat(methodParam1.getType(), equalTo(String.class));
assertThat(methodParam1.getAnnotations(), emptyArray());
final Parameter methodParam2 = method.getParameters()[1];
assertThat(methodParam2.getType(), equalTo(JsonObject.class));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateClassContainingQueryParam.
@Test
public void shouldGenerateClassContainingQueryParam() throws Exception {
generator.run(restRamlWithQueryApiDefaults().with(resource("/users").with(httpActionWithDefaultMapping(GET).with(queryParam("surname")).withResponseTypes("application/vnd.people.query.search-users+json").with(mapping().withName("blah").withResponseType("application/vnd.people.query.search-users+json")))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> implementation = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultQueryApiUsersResource");
assertThat(implementation.isInterface(), is(false));
final Method method = firstMethodOf(implementation).get();
final Parameter param = method.getParameters()[0];
assertThat(param.getType(), equalTo(String.class));
assertThat(param.getAnnotations(), emptyArray());
final Class<?> iface = compiler.compiledInterfaceClassOf(BASE_PACKAGE, "resource", "QueryApiUsersResource");
final Method interMethod = firstMethodOf(iface).get();
final Parameter interParam = interMethod.getParameters()[0];
assertThat(interParam.getType(), equalTo(String.class));
assertThat(interParam.getAnnotations().length, is(1));
final Annotation annotation = interParam.getAnnotations()[0];
assertThat(annotation.annotationType(), equalTo(QueryParam.class));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceClassWithOnePOSTMethod.
@Test
public void shouldGenerateResourceClassWithOnePOSTMethod() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(defaultPostResource().withRelativeUri("/some/path")).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> class1 = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathResource");
final List<Method> methods = methodsOf(class1);
assertThat(methods, hasSize(1));
final Method method = methods.get(0);
assertThat(method.getReturnType(), equalTo(Response.class));
assertThat(method.getParameterCount(), is(1));
assertThat(method.getParameters()[0].getType(), equalTo(JsonObject.class));
}
Aggregations