use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class ActionNameToMediaTypesGeneratorTest method shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithPost.
@Test
public void shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithPost() throws Exception {
final String actionName = "contextA.someAction";
final String requestType = "application/vnd.ctx.query.somemediatype1+json";
final String responseType = "application/vnd.ctx.query.somemediatype2+json";
final String description = mappingDescriptionWith(mapping().withName(actionName).withRequestType(requestType).withResponseType(responseType)).build();
new ActionNameToMediaTypesGenerator().generateActionNameToMediaTypes(restRamlWithQueryApiDefaults().with(resource("/user").with(httpAction(POST).withDescription(description).withMediaTypeWithDefaultSchema(requestType).withResponseTypes(responseType))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> mediaTypesMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "WarnameActionNameToMediaTypesMapper");
final ActionNameToMediaTypesMapper instance = (ActionNameToMediaTypesMapper) mediaTypesMapperClass.newInstance();
final Map<String, MediaTypes> actionNameToMediaTypesMap = instance.getActionNameToMediaTypesMap();
assertThat(actionNameToMediaTypesMap.size(), is(1));
assertThat(actionNameToMediaTypesMap.get(actionName).getRequestMediaType(), is(Optional.of(new MediaType(requestType))));
assertThat(actionNameToMediaTypesMap.get(actionName).getResponseMediaType(), is(Optional.of(new MediaType(responseType))));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class ActionNameToMediaTypesGeneratorTest method shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithGet.
@Test
public void shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithGet() throws Exception {
final String actionName_1 = "contextA.someAction";
final String responseType_1 = "application/vnd.ctx.query.somemediatype1+json";
final String actionName_2 = "contextA.someOtherAction";
final String responseType_2 = "application/vnd.ctx.query.somemediatype2+json";
new ActionNameToMediaTypesGenerator().generateActionNameToMediaTypes(restRamlWithQueryApiDefaults().with(resource("/user").with(httpAction(GET).withDescription(mappingDescriptionWith(mapping().withName(actionName_1).withResponseType(responseType_1), mapping().withName(actionName_2).withResponseType(responseType_2)).build()).withResponseTypes(responseType_1, responseType_2))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> mediaTypesMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "WarnameActionNameToMediaTypesMapper");
final ActionNameToMediaTypesMapper instance = (ActionNameToMediaTypesMapper) mediaTypesMapperClass.newInstance();
final Map<String, MediaTypes> actionNameToMediaTypesMap = instance.getActionNameToMediaTypesMap();
assertThat(actionNameToMediaTypesMap.size(), is(2));
assertThat(actionNameToMediaTypesMap.get(actionName_1).getResponseMediaType(), is(Optional.of(new MediaType(responseType_1))));
assertThat(actionNameToMediaTypesMap.get(actionName_1).getRequestMediaType(), is(Optional.empty()));
assertThat(actionNameToMediaTypesMap.get(actionName_2).getResponseMediaType(), is(Optional.of(new MediaType(responseType_2))));
assertThat(actionNameToMediaTypesMap.get(actionName_2).getRequestMediaType(), is(Optional.empty()));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_CodeStructureTest method shouldGenerateResourceClassWithOneDELETEMethod.
@Test
public void shouldGenerateResourceClassWithOneDELETEMethod() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(defaultDeleteResource().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 shouldGenerateResourceInterfaceWithOneGETMethod.
@Test
public void shouldGenerateResourceInterfaceWithOneGETMethod() throws Exception {
generator.run(restRamlWithDefaults().with(resource("/some/path").with(httpActionWithDefaultMapping(GET).withResponseTypes("application/vnd.ctx.query.query1+json").with(mapping().withResponseType("application/vnd.ctx.query.query1+json").withName("blah")))).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(), 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 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" }));
}
Aggregations