Search in sources :

Example 1 with MediaTypeToSchemaIdMapper

use of uk.gov.justice.services.core.mapping.MediaTypeToSchemaIdMapper in project microservice_framework by CJSCommonPlatform.

the class RamlMediaTypeToSchemaIdGeneratorTest method shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithGet.

@Test
public void shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithGet() throws Exception {
    final String schemaId = "http://justice.gov.uk/test/schema.json";
    final MimeType mimeType_1 = createMimeTypeWith(MEDIA_TYPE_1.toString(), schemaId);
    new RamlMediaTypeToSchemaIdGenerator().generateMediaTypeToSchemaIdMapper(restRamlWithQueryApiDefaults().with(resource("/user").with(httpAction(GET).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 2 with MediaTypeToSchemaIdMapper

use of uk.gov.justice.services.core.mapping.MediaTypeToSchemaIdMapper in project microservice_framework by CJSCommonPlatform.

the class SubscriptionMediaTypeToSchemaIdGeneratorTest method shouldCreateMediaTypeToSchemaIdMapper.

@Test
public void shouldCreateMediaTypeToSchemaIdMapper() throws Exception {
    final String eventName_1 = "ctx.command.command1";
    final String mediaType_1 = "application/vnd." + eventName_1 + "+json";
    final String schemaId_1 = "http://justice.gov.uk/test/schema1.json";
    final String eventName_2 = "ctx.command.command2";
    final String mediaType_2 = "application/vnd." + eventName_2 + "+json";
    final String schemaId_2 = "http://justice.gov.uk/test/schema2.json";
    final String contextName = "my-context";
    final String componentName = "EVENT_LISTENER";
    final String generatedClassName = "MyContextEventListenerMediaTypeToSchemaIdMapper";
    final List<Event> events = asList(new Event(eventName_1, schemaId_1), new Event(eventName_2, schemaId_2));
    new SubscriptionMediaTypeToSchemaIdGenerator().generateMediaTypeToSchemaIdMapper(contextName, componentName, events, configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> schemaIdMapperClass = compiler.compiledClassOf(BASE_PACKAGE, "mapper", generatedClassName);
    final MediaTypeToSchemaIdMapper instance = (MediaTypeToSchemaIdMapper) schemaIdMapperClass.newInstance();
    final Map<MediaType, String> mediaTypeToSchemaIdMap = instance.getMediaTypeToSchemaIdMap();
    assertThat(mediaTypeToSchemaIdMap.size(), is(2));
    assertThat(mediaTypeToSchemaIdMap.get(new MediaType(mediaType_1)), is(schemaId_1));
    assertThat(mediaTypeToSchemaIdMap.get(new MediaType(mediaType_2)), is(schemaId_2));
}
Also used : Event(uk.gov.justice.subscription.domain.Event) 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) Test(org.junit.Test)

Example 3 with MediaTypeToSchemaIdMapper

use of uk.gov.justice.services.core.mapping.MediaTypeToSchemaIdMapper in project microservice_framework by CJSCommonPlatform.

the class SchemaIdMappingCacheMock method initialize.

public SchemaIdMappingCacheMock initialize(final String mapperPackage) {
    final Reflections reflections = new Reflections(mapperPackage);
    final Set<Class<? extends MediaTypeToSchemaIdMapper>> classes = reflections.getSubTypesOf(MediaTypeToSchemaIdMapper.class);
    final List<MediaTypeToSchemaIdMapper> mediaTypeToSchemaIdMappers = classes.stream().map(this::instantiate).collect(toList());
    mediaTypeToSchemaIdMappers.forEach(mapper -> mediaTypeToSchemaId.putAll(mapper.getMediaTypeToSchemaIdMap()));
    return this;
}
Also used : MediaTypeToSchemaIdMapper(uk.gov.justice.services.core.mapping.MediaTypeToSchemaIdMapper) Reflections(org.reflections.Reflections)

Example 4 with MediaTypeToSchemaIdMapper

use of uk.gov.justice.services.core.mapping.MediaTypeToSchemaIdMapper in project microservice_framework by CJSCommonPlatform.

the class RamlMediaTypeToSchemaIdGeneratorTest method shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithPost.

@Test
public void shouldCreateMediaTypeToSchemaIdMapperForGivenRamlWithPost() throws Exception {
    final String schemaId = "http://justice.gov.uk/test/schema.json";
    final MimeType mimeType_1 = createMimeTypeWith(MEDIA_TYPE_1.toString(), schemaId);
    new RamlMediaTypeToSchemaIdGenerator().generateMediaTypeToSchemaIdMapper(restRamlWithQueryApiDefaults().with(resource("/user").with(httpAction(POST).withMediaTypeWithDefaultSchema(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 5 with MediaTypeToSchemaIdMapper

use of uk.gov.justice.services.core.mapping.MediaTypeToSchemaIdMapper 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)

Aggregations

MediaTypeToSchemaIdMapper (uk.gov.justice.services.core.mapping.MediaTypeToSchemaIdMapper)5 Test (org.junit.Test)4 MediaType (uk.gov.justice.services.core.mapping.MediaType)4 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)4 MimeType (org.raml.model.MimeType)3 Reflections (org.reflections.Reflections)1 Event (uk.gov.justice.subscription.domain.Event)1