use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class JsonEnvelopeRepackerTest method shouldHandleJsonEnvelope.
@Test
public void shouldHandleJsonEnvelope() throws JsonProcessingException {
final Envelope<JsonValue> envelope = mock(JsonEnvelope.class);
final JsonEnvelopeRepacker jsonEnvelopeRepacker = new JsonEnvelopeRepacker();
final JsonEnvelope jsonEnvelope = jsonEnvelopeRepacker.repack(envelope);
assertTrue(envelope == jsonEnvelope);
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class RequestResponseEnvelopeValidatorTest method shouldValidateARequestEnvelope.
@Test
public void shouldValidateARequestEnvelope() throws Exception {
final String actionName = "example.action-name";
final JsonEnvelope jsonEnvelope = mock(JsonEnvelope.class);
final MediaType mediaType = mock(MediaType.class);
when(envelopeInspector.getActionNameFor(jsonEnvelope)).thenReturn(actionName);
when(nameToMediaTypeConverter.convert(actionName)).thenReturn(mediaType);
requestResponseEnvelopeValidator.validateRequest(jsonEnvelope);
verify(envelopeValidator).validate(jsonEnvelope, actionName, of(mediaType));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class RequestResponseEnvelopeValidatorTest method shouldValidateAResponsetEnvelope.
@Test
public void shouldValidateAResponsetEnvelope() throws Exception {
final String actionName = "example.action-name";
final JsonEnvelope jsonEnvelope = mock(JsonEnvelope.class);
final Optional<MediaType> mediaType = of(mock(MediaType.class));
when(envelopeInspector.getActionNameFor(jsonEnvelope)).thenReturn(actionName);
when(mediaTypeProvider.getResponseMediaType(actionName)).thenReturn(mediaType);
requestResponseEnvelopeValidator.validateResponse(jsonEnvelope);
verify(envelopeValidator).validate(jsonEnvelope, actionName, mediaType);
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class DefaultEnveloperTest method shouldRemoveStreamMetadataWithName.
@Test
public void shouldRemoveStreamMetadataWithName() throws Exception {
enveloper.register(new EventFoundEvent(TestEvent.class, TEST_EVENT_NAME));
final JsonEnvelope event = enveloper.withMetadataFrom(envelopeFrom(metadataBuilder().withId(COMMAND_UUID).withName(TEST_EVENT_NAME).withStreamId(randomUUID()).withVersion(123l), createObjectBuilder()), "new.name").apply(new TestEvent());
assertThat(event.metadata().streamId(), is(empty()));
assertThat(event.metadata().version(), is(empty()));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class HandlerRegistryTest method assertHandlerMethodInvokesHandler.
private void assertHandlerMethodInvokesHandler(final HandlerMethod handlerMethod, final TestEnvelopeRecorder handler) {
assertThat(handlerMethod, notNullValue());
final JsonEnvelope envelope = mock(JsonEnvelope.class);
handlerMethod.execute(envelope);
assertThat(handler.firstRecordedEnvelope(), sameInstance(envelope));
}
Aggregations