Search in sources :

Example 46 with JsonEnvelope

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

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

Example 48 with JsonEnvelope

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

Example 49 with JsonEnvelope

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()));
}
Also used : EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 50 with JsonEnvelope

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));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope)

Aggregations

JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)276 Test (org.junit.Test)249 UUID (java.util.UUID)69 UUID.randomUUID (java.util.UUID.randomUUID)64 JsonObject (javax.json.JsonObject)30 JsonValue (javax.json.JsonValue)26 InterceptorContext (uk.gov.justice.services.core.interceptor.InterceptorContext)24 Metadata (uk.gov.justice.services.messaging.Metadata)18 Method (java.lang.reflect.Method)17 Function (java.util.function.Function)14 StreamBufferEvent (uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent)10 EventStream (uk.gov.justice.services.eventsourcing.source.core.EventStream)9 JsonObjects.getJsonObject (uk.gov.justice.services.messaging.JsonObjects.getJsonObject)9 EndpointDefinition (uk.gov.justice.services.clients.core.EndpointDefinition)8 MediaType (uk.gov.justice.services.core.mapping.MediaType)8 StreamStatus (uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus)7 ZonedDateTime (java.time.ZonedDateTime)6 Collection (java.util.Collection)6 Optional (java.util.Optional)6 HttpHeaders (javax.ws.rs.core.HttpHeaders)6