use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceClassWithOnePUTMethod.
@Test
public void shouldGenerateResourceClassWithOnePUTMethod() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(defaultPutResource().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));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateInterfaceThatContainsMethodWithPathParamAndBodyParam.
@Test
public void shouldGenerateInterfaceThatContainsMethodWithPathParamAndBodyParam() throws Exception {
generator.run(restRamlWithDefaults().with(defaultPostResource().withRelativeUri("/some/path/{param1}").withPathParam("param1")).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> interfaceClass = compiler.compiledInterfaceOf(RESOURCE_PACKAGE);
assertThat(interfaceClass.isInterface(), is(true));
final List<Method> methods = methodsOf(interfaceClass);
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(), arrayWithSize(1));
assertThat(methodParam1.getAnnotations()[0].annotationType(), equalTo(PathParam.class));
assertThat(methodParam1.getAnnotation(PathParam.class).value(), is("param1"));
final Parameter methodParam2 = method.getParameters()[1];
assertThat(methodParam2.getType(), equalTo(JsonObject.class));
assertThat(methodParam2.getAnnotations(), emptyArray());
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceClassWithOneSynchronousPATCHMethod.
@Test
public void shouldGenerateResourceClassWithOneSynchronousPATCHMethod() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(PATCH, "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));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateClassInSpecifiedPackage.
@Test
public void shouldGenerateClassInSpecifiedPackage() throws Exception {
final String basePackageName = "uk.gov.test2";
java.nio.file.Path outputPath = get(outputFolder.getRoot().getAbsolutePath());
generator.run(restRamlWithCommandApiDefaults().with(defaultPostResource().withRelativeUri("/some/path")).build(), new GeneratorConfig(outputPath, outputPath, basePackageName, new CommonGeneratorProperties(), singletonList(outputPath.getParent())));
final Class<?> resourceImplementation = compiler.compiledClassOf(basePackageName, "resource", "DefaultCommandApiSomePathResource");
assertThat(resourceImplementation.getPackage().getName(), is(basePackageName + ".resource"));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateInterfaceThatContainsMethodWithTwoPathParamsAndBodyParam.
@Test
public void shouldGenerateInterfaceThatContainsMethodWithTwoPathParamsAndBodyParam() throws Exception {
generator.run(restRamlWithDefaults().with(defaultPostResource().withRelativeUri("/some/path/{paramA}/abc/{paramB}").withPathParam("paramA").withPathParam("paramB")).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.getParameterCount(), is(3));
final Parameter methodParam1 = method.getParameters()[0];
assertThat(methodParam1.getType(), equalTo(String.class));
assertThat(methodParam1.getAnnotations(), arrayWithSize(1));
assertThat(methodParam1.getAnnotations()[0].annotationType(), equalTo(PathParam.class));
assertThat(methodParam1.getAnnotation(PathParam.class).value(), is("paramA"));
final Parameter methodParam2 = method.getParameters()[1];
assertThat(methodParam2.getType(), equalTo(String.class));
assertThat(methodParam2.getAnnotations(), arrayWithSize(1));
assertThat(methodParam2.getAnnotations()[0].annotationType(), equalTo(PathParam.class));
assertThat(methodParam2.getAnnotation(PathParam.class).value(), is("paramB"));
final Parameter methodParam3 = method.getParameters()[2];
assertThat(methodParam3.getType(), equalTo(JsonObject.class));
assertThat(methodParam3.getAnnotations(), emptyArray());
}
Aggregations