use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_ApplicationTest method shouldIncludeStandardProviders.
@SuppressWarnings("unchecked")
@Test
public void shouldIncludeStandardProviders() throws Exception {
generator.run(restRamlWithDefaults().with(resource("/pathA").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
Set<Class<?>> compiledClasses = compiler.compiledClassesOf(BASE_PACKAGE);
Class<?> applicationClass = compiler.classOf(compiledClasses, BASE_PACKAGE, "CommandApiRestServiceApplication");
Object application = applicationClass.newInstance();
CommonProviders commonProviders = mock(CommonProviders.class);
when(commonProviders.providers()).thenReturn(newHashSet(JaxRsProviderA.class, JaxRsProviderB.class));
setField(application, "commonProviders", commonProviders);
Method method = applicationClass.getDeclaredMethod("getClasses");
Object result = method.invoke(application);
assertThat(result, is(instanceOf(Set.class)));
Set<Class<?>> classes = (Set<Class<?>>) result;
assertThat(classes, hasItems(JaxRsProviderA.class, JaxRsProviderB.class));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_ApplicationTest method shouldNotGenerateExistingClasses.
@SuppressWarnings("unchecked")
@Test
public void shouldNotGenerateExistingClasses() throws Exception {
Path sourcePath = existingFilePath();
generator.run(restRamlWithQueryApiDefaults().with(resource("/pathA").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties(), singletonList(sourcePath)));
Path outputPath = Paths.get(outputFolder.newFile().getAbsolutePath(), EXISTING_FILE_PATH);
assertThat(outputPath.toFile().exists(), equalTo(FALSE));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_ActionNameToMediaTypesMapperTest method shouldGenerateMediaTypeToSchemaIdMapper.
@Test
public void shouldGenerateMediaTypeToSchemaIdMapper() throws Exception {
final String actionName = "contextA.someAction";
generator.run(restRamlWithQueryApiDefaults().with(resource("/user").with(httpAction(GET).with(mapping().withName(actionName).withResponseType(MEDIA_TYPE_1.toString())).withResponseTypes(MEDIA_TYPE_1.toString()))).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).getResponseMediaType(), is(Optional.of(MEDIA_TYPE_1)));
assertThat(actionNameToMediaTypesMap.get(actionName).getRequestMediaType(), is(Optional.empty()));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_MediaTypeToSchemaIdMapperTest method shouldGenerateMediaTypeToSchemaIdMapper.
@Test
public void shouldGenerateMediaTypeToSchemaIdMapper() throws Exception {
final String schemaId = "http://justice.gov.uk/test/schema.json";
final MimeType mimeType_1 = createMimeTypeWith(MEDIA_TYPE_1.toString(), schemaId);
generator.run(restRamlWithQueryApiDefaults().with(resource("/user").with(httpAction(GET).with(mapping().withName("contextA.someAction").withResponseType(MEDIA_TYPE_1.toString())).withResponseTypes(mimeType_1))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> schemaIdMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", "WarnameMediaTypeToSchemaIdMapper");
final MediaTypeToSchemaIdMapper instance = (MediaTypeToSchemaIdMapper) schemaIdMapperClass.newInstance();
final Map<MediaType, String> mediaTypeToSchemaIdMap = instance.getMediaTypeToSchemaIdMap();
assertThat(mediaTypeToSchemaIdMap.size(), is(1));
assertThat(mediaTypeToSchemaIdMap.get(MEDIA_TYPE_1), is(schemaId));
}
use of uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_MultipartMethodBodyTest method shouldReturnResponseGeneratedByRestProcessor.
@SuppressWarnings("unchecked")
@Test
public void shouldReturnResponseGeneratedByRestProcessor() throws Exception {
generator.run(restRamlWithCommandApiDefaults().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<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathResource");
final Object resourceObject = getInstanceOf(resourceClass);
final Response processorResponse = Response.ok().build();
when(restProcessor.process(anyString(), any(Function.class), anyString(), any(HttpHeaders.class), any(Collection.class), any(List.class))).thenReturn(processorResponse);
final Method method = firstMethodOf(resourceClass).get();
final Object result = method.invoke(resourceObject, mock(MultipartFormDataInput.class));
assertThat(result, is(processorResponse));
}
Aggregations