use of org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_MediaTypeToSchemaIdMapperTest method createMimeTypeWith.
private MimeType createMimeTypeWith(final String type, final String schemaId) {
final MimeType mimeType = new MimeType();
mimeType.setType(type);
mimeType.setSchema(format(VALID_JSON_SCHEMA, schemaId));
return mimeType;
}
use of org.raml.model.MimeType 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 org.raml.model.MimeType in project microservice_framework by CJSCommonPlatform.
the class GeneratorsTest method shouldSortMimeTypes.
@Test
public void shouldSortMimeTypes() throws Exception {
final MimeType mimeTypeA = new MimeType("application/vnd.a+json");
final MimeType mimeTypeB = new MimeType("application/vnd.b+json");
final MimeType mimeTypeC = new MimeType("application/vnd.c+json");
final List<MimeType> mimeTypes = Arrays.asList(mimeTypeB, mimeTypeC, mimeTypeA);
assertThat(mimeTypes, contains(mimeTypeB, mimeTypeC, mimeTypeA));
final List<MimeType> orderedMimeTypes = mimeTypes.stream().sorted(Generators.byMimeTypeOrder()).collect(Collectors.toList());
assertThat(orderedMimeTypes, contains(mimeTypeA, mimeTypeB, mimeTypeC));
}
Aggregations