use of org.raml.model.ActionType.POST in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceInterfaceWithOnePOSTMethod.
@Test
public void shouldGenerateResourceInterfaceWithOnePOSTMethod() throws Exception {
generator.run(restRamlWithDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(POST, "application/vnd.default+json").with(mapping().withName("blah").withRequestType("application/vnd.default+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(POST.class), not(nullValue()));
assertThat(method.getAnnotation(Consumes.class), not(nullValue()));
assertThat(method.getAnnotation(Consumes.class).value(), is(new String[] { "application/vnd.default+json" }));
}
use of org.raml.model.ActionType.POST in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceInterfaceWithOneSynchronousPOSTMethod.
@Test
public void shouldGenerateResourceInterfaceWithOneSynchronousPOSTMethod() throws Exception {
generator.run(restRamlWithDefaults().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<?> 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(POST.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 org.raml.model.ActionType.POST in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_MultipartCodeStructureTest method shouldGenerateResourceInterfaceWithOnePOSTMethod.
@Test
public void shouldGenerateResourceInterfaceWithOnePOSTMethod() throws Exception {
generator.run(restRamlWithDefaults().with(resource("/some/path").with(httpAction().withHttpActionType(POST).withMediaTypeWithoutSchema(multipartWithFileFormParameter("photoId")).with(mapping().withName("upload").withRequestType(MULTIPART_FORM_DATA)))).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.POST.class), not(nullValue()));
assertThat(method.getAnnotation(Consumes.class), not(nullValue()));
assertThat(method.getAnnotation(Consumes.class).value(), is(new String[] { MULTIPART_FORM_DATA }));
assertThat(method.getAnnotation(Produces.class), is(nullValue()));
}
use of org.raml.model.ActionType.POST in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceInterfaceWithTwoPOSTMethods.
@Test
public void shouldGenerateResourceInterfaceWithTwoPOSTMethods() throws Exception {
generator.run(restRamlWithDefaults().with(resource("/some/path/{p1}").with(httpActionWithDefaultMapping(POST, "application/vnd.ctx.command.cmd-a+json", "application/vnd.ctx.command.cmd-b+json").with(mapping().withName("blah1").withRequestType("application/vnd.ctx.command.cmd-a+json")).with(mapping().withName("blah2").withRequestType("application/vnd.ctx.command.cmd-b+json")))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> interfaceClass = compiler.compiledInterfaceOf(RESOURCE_PACKAGE);
final List<Method> methods = methodsOf(interfaceClass);
assertThat(methods, hasSize(2));
final Method method1 = methodWithConsumesAnnotationOf(methods, "application/vnd.ctx.command.cmd-a+json");
assertThat(method1.getReturnType(), equalTo(Response.class));
assertThat(method1.getAnnotation(POST.class), not(nullValue()));
assertThat(method1.getAnnotation(Consumes.class), not(nullValue()));
assertThat(method1.getAnnotation(Consumes.class).value(), is(new String[] { "application/vnd.ctx.command.cmd-a+json" }));
final Method method2 = methodWithConsumesAnnotationOf(methods, "application/vnd.ctx.command.cmd-b+json");
assertThat(method2.getReturnType(), equalTo(Response.class));
assertThat(method2.getAnnotation(POST.class), not(nullValue()));
assertThat(method2.getAnnotation(Consumes.class), not(nullValue()));
assertThat(method2.getAnnotation(Consumes.class).value(), is(new String[] { "application/vnd.ctx.command.cmd-b+json" }));
}
Aggregations