Search in sources :

Example 1 with POST

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" }));
}
Also used : Response(javax.ws.rs.core.Response) POST(javax.ws.rs.POST) POST(org.raml.model.ActionType.POST) Consumes(javax.ws.rs.Consumes) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 2 with POST

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" }));
}
Also used : Response(javax.ws.rs.core.Response) POST(javax.ws.rs.POST) POST(org.raml.model.ActionType.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 3 with POST

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()));
}
Also used : Response(javax.ws.rs.core.Response) POST(org.raml.model.ActionType.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 4 with POST

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" }));
}
Also used : Response(javax.ws.rs.core.Response) POST(javax.ws.rs.POST) POST(org.raml.model.ActionType.POST) Consumes(javax.ws.rs.Consumes) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)4 Consumes (javax.ws.rs.Consumes)4 Response (javax.ws.rs.core.Response)4 Test (org.junit.Test)4 POST (org.raml.model.ActionType.POST)4 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)4 POST (javax.ws.rs.POST)3 Produces (javax.ws.rs.Produces)2