use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateClassContainingThreeQueryParams.
@Test
public void shouldGenerateClassContainingThreeQueryParams() throws Exception {
generator.run(restRamlWithQueryApiDefaults().with(resource("/users").with(httpActionWithDefaultMapping(GET).with(queryParam("surname"), queryParam("firstname"), queryParam("middlename")).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();
assertThat(method.getParameterCount(), is(3));
stream(method.getParameters()).forEach(parameter -> {
assertThat(parameter.getType(), equalTo(String.class));
assertThat(parameter.getAnnotations(), emptyArray());
});
final Class<?> iface = compiler.compiledInterfaceClassOf(BASE_PACKAGE, "resource", "QueryApiUsersResource");
assertThat(iface.isInterface(), is(true));
final Method interMethod = firstMethodOf(iface).get();
assertThat(interMethod.getParameterCount(), is(3));
stream(interMethod.getParameters()).forEach(parameter -> {
assertThat(parameter.getType(), equalTo(String.class));
assertThat(parameter.getAnnotations().length, is(1));
Annotation annotation = parameter.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 shouldGenerateClassContainingMethodWithThreePathParamsAndOneBodyParam.
@Test
public void shouldGenerateClassContainingMethodWithThreePathParamsAndOneBodyParam() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(defaultPostResource().withRelativeUri("/some/path/{paramA}/{paramB}/{paramC}").withPathParam("paramA").withPathParam("paramB").withPathParam("paramC")).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathParamAParamBParamCResource");
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(4));
final Parameter pathParam1 = method.getParameters()[0];
assertThat(pathParam1.getType(), equalTo(String.class));
assertThat(pathParam1.getAnnotations(), emptyArray());
final Parameter pathParam2 = method.getParameters()[1];
assertThat(pathParam2.getType(), equalTo(String.class));
assertThat(pathParam2.getAnnotations(), emptyArray());
final Parameter pathParam3 = method.getParameters()[2];
assertThat(pathParam3.getType(), equalTo(String.class));
assertThat(pathParam3.getAnnotations(), emptyArray());
final Parameter bodyParam = method.getParameters()[3];
assertThat(bodyParam.getType(), equalTo(JsonObject.class));
assertThat(bodyParam.getAnnotations(), emptyArray());
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateGETMethodWithTwoMediaTypeAnnotations.
@Test
public void shouldGenerateGETMethodWithTwoMediaTypeAnnotations() throws Exception {
generator.run(restRamlWithDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(GET).withResponseTypes("application/vnd.ctx.query.query1+json", "application/vnd.ctx.query.query2+json").with(mapping().withName("blah1").withResponseType("application/vnd.ctx.query.query1+json")).with(mapping().withName("blah2").withResponseType("application/vnd.ctx.query.query2+json")))).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.getReturnType(), equalTo(Response.class));
assertThat(method.getAnnotation(javax.ws.rs.GET.class), not(nullValue()));
assertThat(method.getAnnotation(Produces.class), not(nullValue()));
assertThat(method.getAnnotation(Produces.class).value(), arrayContainingInAnyOrder("application/vnd.ctx.query.query1+json", "application/vnd.ctx.query.query2+json"));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceInterfaceWithOneSynchronousPUTMethod.
@Test
public void shouldGenerateResourceInterfaceWithOneSynchronousPUTMethod() throws Exception {
generator.run(restRamlWithDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(PUT, "application/vnd.default+json").withResponseTypes("application/vnd.ctx.query.query1+json").with(mapping().withName("blah").withRequestType("application/vnd.default+json").withResponseType("application/vnd.ctx.query.query1+json")))).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.getReturnType(), equalTo(Response.class));
assertThat(method.getAnnotation(PUT.class), not(nullValue()));
assertThat(method.getAnnotation(Consumes.class), not(nullValue()));
assertThat(method.getAnnotation(Consumes.class).value(), is(new String[] { "application/vnd.default+json" }));
assertThat(method.getAnnotation(Produces.class), not(nullValue()));
assertThat(method.getAnnotation(Produces.class).value(), is(new String[] { "application/vnd.ctx.query.query1+json" }));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceClassWithOneSynchronousPOSTMethod.
@Test
public void shouldGenerateResourceClassWithOneSynchronousPOSTMethod() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(POST, "application/vnd.default+json").withResponseTypes("application/vnd.ctx.query.query1+json").with(mapping().withName("blah").withRequestType("application/vnd.default+json").withResponseType("application/vnd.ctx.query.query1+json")))).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