use of uk.gov.justice.services.core.json.SchemaLoadingException in project microservice_framework by CJSCommonPlatform.
the class EnvelopeValidatorTest method shouldHandleASchemaLoadingException.
@Test
public void shouldHandleASchemaLoadingException() throws Exception {
final SchemaLoadingException schemaLoadingException = new SchemaLoadingException("Ooops");
final String actionName = "exaple.action-name";
final String payloadJson = "{\"some\": \"json\"}";
final Optional<MediaType> mediaType = of(new MediaType("application/vnd.example.action-name+json"));
final JsonEnvelope jsonEnvelope = mock(JsonEnvelope.class);
final JsonValue payload = mock(JsonValue.class);
when(jsonEnvelope.payload()).thenReturn(payload);
when(objectMapper.writeValueAsString(payload)).thenReturn(payloadJson);
doThrow(schemaLoadingException).when(jsonSchemaValidator).validate(payloadJson, actionName, mediaType);
envelopeValidator.validate(jsonEnvelope, actionName, mediaType);
verify(envelopeValidationExceptionHandler).handle(exceptionArgumentCaptor.capture());
final EnvelopeValidationException envelopeValidationException = exceptionArgumentCaptor.getValue();
assertThat(envelopeValidationException.getMessage(), is("Could not load json schema that matches message type exaple.action-name."));
assertThat(envelopeValidationException.getCause(), is(schemaLoadingException));
}
Aggregations