Search in sources :

Example 26 with JsonEnvelope

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

the class ConsecutiveEventBufferServiceTest method shouldReturnConsecutiveBufferedEventsIfIncomingEventFillsTheVersionGap.

@Test
public void shouldReturnConsecutiveBufferedEventsIfIncomingEventFillsTheVersionGap() {
    final UUID streamId = randomUUID();
    final String source = "source";
    final String eventName = "source.event.name";
    when(bufferInitialisationStrategy.initialiseBuffer(eq(streamId), eq(source))).thenReturn(2L);
    when(streamBufferRepository.findStreamByIdAndSource(streamId, source)).thenReturn(Stream.of(new StreamBufferEvent(streamId, 4L, "someEventContent4", "source_4"), new StreamBufferEvent(streamId, 5L, "someEventContent5", "source_5"), new StreamBufferEvent(streamId, 6L, "someEventContent6", "source_6"), new StreamBufferEvent(streamId, 8L, "someEventContent8", "source_8"), new StreamBufferEvent(streamId, 9L, "someEventContent9", "source_9"), new StreamBufferEvent(streamId, 10L, "someEventContent10", "source_10"), new StreamBufferEvent(streamId, 11L, "someEventContent11", "source_11")));
    final JsonEnvelope bufferedEvent4 = envelope().build();
    final JsonEnvelope bufferedEvent5 = envelope().build();
    final JsonEnvelope bufferedEvent6 = envelope().build();
    when(jsonObjectEnvelopeConverter.asEnvelope("someEventContent4")).thenReturn(bufferedEvent4);
    when(jsonObjectEnvelopeConverter.asEnvelope("someEventContent5")).thenReturn(bufferedEvent5);
    when(jsonObjectEnvelopeConverter.asEnvelope("someEventContent6")).thenReturn(bufferedEvent6);
    final JsonEnvelope incomingEvent = envelope().with(metadataWithDefaults().withName(eventName).withStreamId(streamId).withVersion(3L)).build();
    final Stream<JsonEnvelope> returnedEvents = bufferService.currentOrderedEventsWith(incomingEvent);
    assertThat(returnedEvents, contains(incomingEvent, bufferedEvent4, bufferedEvent5, bufferedEvent6));
}
Also used : StreamBufferEvent(uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 27 with JsonEnvelope

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

the class ConsecutiveEventBufferServiceTest method shouldRemoveEventsFromBufferOnceStreamed.

@Test
public void shouldRemoveEventsFromBufferOnceStreamed() {
    final UUID streamId = randomUUID();
    final String source = "source";
    final String eventName = "source.event.name";
    when(bufferInitialisationStrategy.initialiseBuffer(eq(streamId), eq(source))).thenReturn(2L);
    final StreamBufferEvent event4 = new StreamBufferEvent(streamId, 4L, "someEventContent4", "source_1");
    final StreamBufferEvent event5 = new StreamBufferEvent(streamId, 5L, "someEventContent5", "source_2");
    final StreamBufferEvent event6 = new StreamBufferEvent(streamId, 6L, "someEventContent6", "source_3");
    when(streamBufferRepository.findStreamByIdAndSource(streamId, source)).thenReturn(Stream.of(event4, event5, event6));
    final JsonEnvelope bufferedEvent4 = envelope().build();
    final JsonEnvelope bufferedEvent5 = envelope().build();
    final JsonEnvelope bufferedEvent6 = envelope().build();
    when(jsonObjectEnvelopeConverter.asEnvelope("someEventContent4")).thenReturn(bufferedEvent4);
    when(jsonObjectEnvelopeConverter.asEnvelope("someEventContent5")).thenReturn(bufferedEvent5);
    when(jsonObjectEnvelopeConverter.asEnvelope("someEventContent6")).thenReturn(bufferedEvent6);
    final JsonEnvelope incomingEvent = envelope().with(metadataWithDefaults().withName(eventName).withStreamId(streamId).withVersion(3L)).build();
    final Stream<JsonEnvelope> returnedEvents = bufferService.currentOrderedEventsWith(incomingEvent);
    assertThat(returnedEvents, contains(incomingEvent, bufferedEvent4, bufferedEvent5, bufferedEvent6));
    verify(streamBufferRepository).remove(event4);
    verify(streamBufferRepository).remove(event5);
    verify(streamBufferRepository).remove(event6);
}
Also used : StreamBufferEvent(uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 28 with JsonEnvelope

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

the class JmsEventPublisherTest method shouldPublishEnvelope.

@Test
public void shouldPublishEnvelope() {
    final JsonEnvelope envelope = envelope().with(metadataWithRandomUUID(EVENT_NAME)).build();
    when(eventDestinationResolver.destinationNameOf(EVENT_NAME)).thenReturn(DESTINATION_NAME);
    jmsEventPublisher.publish(envelope);
    verify(jmsEnvelopeSender).send(envelope, DESTINATION_NAME);
    verify(logger).trace("Publishing event {} to {}", EVENT_NAME, DESTINATION_NAME);
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 29 with JsonEnvelope

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

the class QueryApiDirectClientIT method shouldPassEnvelopeToAdapter.

@Test
public void shouldPassEnvelopeToAdapter() throws Exception {
    final JsonEnvelope envelopePassedToAdapter = envelope().with(metadataWithRandomUUID(GET_USER_ACTION)).build();
    requester.request(envelopePassedToAdapter);
    assertThat(testDirectAdapter.firstRecordedEnvelope(), is(envelopePassedToAdapter));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 30 with JsonEnvelope

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

the class RecordingInterceptorChainProcessor method process.

@Override
public Optional<JsonEnvelope> process(final InterceptorContext interceptorContext) {
    final JsonEnvelope envelope = interceptorContext.inputEnvelope();
    record(envelope);
    return Optional.ofNullable(responseTo(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