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"));
}
}
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);
}
Aggregations