Search in sources :

Example 36 with MimeType

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;
}
Also used : MimeType(org.raml.model.MimeType)

Example 37 with 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));
}
Also used : MediaTypeToSchemaIdMapper(uk.gov.justice.services.core.mapping.MediaTypeToSchemaIdMapper) MediaType(uk.gov.justice.services.core.mapping.MediaType) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Example 38 with MimeType

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));
}
Also used : MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Aggregations

MimeType (org.raml.model.MimeType)38 Test (org.junit.Test)30 Action (org.raml.model.Action)6 Event (uk.gov.justice.subscription.domain.Event)6 HttpActionBuilder.httpAction (uk.gov.justice.services.generators.test.utils.builder.HttpActionBuilder.httpAction)4 MediaType (uk.gov.justice.services.core.mapping.MediaType)3 MediaTypeToSchemaIdMapper (uk.gov.justice.services.core.mapping.MediaTypeToSchemaIdMapper)3 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)3 Subscription (uk.gov.justice.subscription.domain.Subscription)3 HashMap (java.util.HashMap)2 Resource (org.raml.model.Resource)2 ActionMimeTypeDefinition (uk.gov.justice.services.generators.commons.client.ActionMimeTypeDefinition)2 Eventsource (uk.gov.justice.subscription.domain.Eventsource)2 Location (uk.gov.justice.subscription.domain.Location)2 TypeSpec (com.squareup.javapoet.TypeSpec)1 ActionType (org.raml.model.ActionType)1 Response (org.raml.model.Response)1 SchemaParsingException (uk.gov.justice.services.generators.commons.mapping.SchemaParsingException)1 MappingBuilder (uk.gov.justice.services.generators.test.utils.builder.MappingBuilder)1 SubscriptionDescriptor (uk.gov.justice.subscription.domain.SubscriptionDescriptor)1