Search in sources :

Example 11 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class EventStreamMockHelperTest method shouldVerifyAppendCallAndReturnStreamOfJsonEnvelopes.

@Test
public void shouldVerifyAppendCallAndReturnStreamOfJsonEnvelopes() throws Exception {
    final EventStream eventStream = mock(EventStream.class);
    final JsonEnvelope jsonEnvelope_1 = mock(JsonEnvelope.class);
    final JsonEnvelope jsonEnvelope_2 = mock(JsonEnvelope.class);
    eventStream.append(Stream.of(jsonEnvelope_1, jsonEnvelope_2));
    final Stream<JsonEnvelope> jsonEnvelopeStream = EventStreamMockHelper.verifyAppendAndGetArgumentFrom(eventStream);
    final List<JsonEnvelope> jsonEnvelopes = jsonEnvelopeStream.collect(toList());
    assertThat(jsonEnvelopes, contains(jsonEnvelope_1, jsonEnvelope_2));
}
Also used : EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 12 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class EventStreamMatcherTest method shouldMatchJsonEnvelopeStreamAppendedAfterVersionOfEventStream.

@Test
public void shouldMatchJsonEnvelopeStreamAppendedAfterVersionOfEventStream() throws Exception {
    final JsonEnvelope event_1 = jsonEnvelopeWith(ID_1, NAME_1);
    final JsonEnvelope event_2 = jsonEnvelopeWith(ID_2, NAME_2);
    eventStream.appendAfter(Stream.of(event_1, event_2), VERSION);
    assertThat(eventStream, EventStreamMatcher.eventStreamAppendedAfter(VERSION).with(streamContaining(jsonEnvelope(metadata().withName("event.action"), payloadIsJson(allOf(withJsonPath("$.someId", equalTo(ID_1.toString())), withJsonPath("$.name", equalTo(NAME_1))))), jsonEnvelope(metadata().withName("event.action"), payloadIsJson(allOf(withJsonPath("$.someId", equalTo(ID_2.toString())), withJsonPath("$.name", equalTo(NAME_2))))))));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 13 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class EventStreamMatcherTest method shouldNotMatchJsonEnvelopeStreamAppendedAfterVersionOfEventStreamIfJsonEnvelopeIsMissing.

@Test(expected = AssertionError.class)
public void shouldNotMatchJsonEnvelopeStreamAppendedAfterVersionOfEventStreamIfJsonEnvelopeIsMissing() throws Exception {
    final JsonEnvelope event_1 = jsonEnvelopeWith(ID_1, NAME_1);
    final JsonEnvelope event_2 = jsonEnvelopeWith(ID_2, NAME_2);
    eventStream.appendAfter(Stream.of(event_1, event_2), VERSION);
    assertThat(eventStream, EventStreamMatcher.eventStreamAppendedAfter(VERSION).with(streamContaining(jsonEnvelope(metadata().withName("event.action"), payloadIsJson(allOf(withJsonPath("$.someId", equalTo(ID_1.toString())), withJsonPath("$.name", equalTo(NAME_1))))))));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 14 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class EventStreamMatcherTest method shouldNotMatchANonEmptyStream.

@Test(expected = AssertionError.class)
public void shouldNotMatchANonEmptyStream() throws Exception {
    final JsonEnvelope event_1 = jsonEnvelopeWith(ID_1, NAME_1);
    eventStream.append(Stream.of(event_1));
    assertThat(eventStream, EventStreamMatcher.eventStreamWithEmptyStream());
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 15 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class EventStreamMatcherTest method shouldNotMatchJsonEnvelopesStreamAppendedToEventStreamIfJsonEnvelopeIsMissing.

@Test(expected = AssertionError.class)
public void shouldNotMatchJsonEnvelopesStreamAppendedToEventStreamIfJsonEnvelopeIsMissing() throws Exception {
    final JsonEnvelope event_1 = jsonEnvelopeWith(ID_1, NAME_1);
    final JsonEnvelope event_2 = jsonEnvelopeWith(ID_2, NAME_2);
    eventStream.append(Stream.of(event_1, event_2));
    assertThat(eventStream, EventStreamMatcher.eventStreamAppendedWith(streamContaining(jsonEnvelope(metadata().withName("event.action"), payloadIsJson(allOf(withJsonPath("$.someId", equalTo(ID_1.toString())), withJsonPath("$.name", equalTo(NAME_1))))))));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

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