Search in sources :

Example 1 with SchemaParsingException

use of uk.gov.justice.services.generators.commons.mapping.SchemaParsingException in project microservice_framework by CJSCommonPlatform.

the class MimeTypeToEventConverterTest method shouldThrowASchemaParsingExceptionIfTheSchemaIdIsNotFound.

@Test
public void shouldThrowASchemaParsingExceptionIfTheSchemaIdIsNotFound() throws Exception {
    final String eventName = "something-happened";
    final String mimeTypeString = "application/vnd.context.events.something-happened+json";
    final MimeType mimeType = mock(MimeType.class);
    when(mimeType.getType()).thenReturn(mimeTypeString);
    when(eventNameExtractor.extractEventName(mimeType.getType())).thenReturn(eventName);
    when(schemaIdParser.schemaIdFrom(mimeType)).thenReturn(empty());
    try {
        mimeTypeToEventConverter.asEvent(mimeType);
        fail();
    } catch (final SchemaParsingException expected) {
        assertThat(expected.getMessage(), is("Schema for media type: application/vnd.context.events.something-happened+json has no schema id"));
    }
}
Also used : SchemaParsingException(uk.gov.justice.services.generators.commons.mapping.SchemaParsingException) MimeType(org.raml.model.MimeType) Test(org.junit.Test)

Example 2 with SchemaParsingException

use of uk.gov.justice.services.generators.commons.mapping.SchemaParsingException in project microservice_framework by CJSCommonPlatform.

the class MimeTypeToEventConverter method asEvent.

public Event asEvent(final MimeType mimeType) {
    final String eventName = eventNameExtractor.extractEventName(mimeType.getType());
    final String schemaUri = schemaIdParser.schemaIdFrom(mimeType).orElseThrow(() -> new SchemaParsingException(format("Schema for media type: %s has no schema id", mimeType.getType())));
    return new Event(eventName, schemaUri);
}
Also used : Event(uk.gov.justice.subscription.domain.Event) SchemaParsingException(uk.gov.justice.services.generators.commons.mapping.SchemaParsingException)

Aggregations

SchemaParsingException (uk.gov.justice.services.generators.commons.mapping.SchemaParsingException)2 Test (org.junit.Test)1 MimeType (org.raml.model.MimeType)1 Event (uk.gov.justice.subscription.domain.Event)1