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));
}
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);
}
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);
}
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));
}
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));
}
Aggregations