Search in sources :

Example 1 with SchemaLoadingException

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));
}
Also used : JsonValue(javax.json.JsonValue) SchemaLoadingException(uk.gov.justice.services.core.json.SchemaLoadingException) MediaType(uk.gov.justice.services.core.mapping.MediaType) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Aggregations

JsonValue (javax.json.JsonValue)1 Test (org.junit.Test)1 SchemaLoadingException (uk.gov.justice.services.core.json.SchemaLoadingException)1 MediaType (uk.gov.justice.services.core.mapping.MediaType)1 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)1