use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class DefaultInterceptorContextProviderTest method shouldProvideInterceptorContext.
@Test
public void shouldProvideInterceptorContext() {
final DefaultInterceptorContextProvider provider = new DefaultInterceptorContextProvider();
final JsonEnvelope jsonEnvelope = new DefaultJsonEnvelopeProvider().envelopeFrom(metadata, payload);
InterceptorContext interceptorContext = provider.interceptorContextWithInput(jsonEnvelope);
assertThat(interceptorContext, instanceOf(DefaultInterceptorContext.class));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class CustomServiceComponentHandlerIT method shouldHandleFrameWorkComponentByName.
@Test
public void shouldHandleFrameWorkComponentByName() {
final UUID metadataId = randomUUID();
final JsonEnvelope jsonEnvelope = envelopeFrom(metadataBuilder().withId(metadataId).withName(CUSTOM_XYZ).withStreamId(randomUUID()).withVersion(1L), createObjectBuilder());
interceptorChainProcessor.process(interceptorContextWithInput(jsonEnvelope));
assertThat(customComponentHandler.firstRecordedEnvelope(), not(nullValue()));
assertThat(customComponentHandler.firstRecordedEnvelope().metadata().id(), equalTo(metadataId));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class SenderRequesterHandlerIT method shouldSendToCorrectRequesterWithFieldLevelServiceComponentAnnotation.
@Test
public void shouldSendToCorrectRequesterWithFieldLevelServiceComponentAnnotation() throws Exception {
UUID metadataId = randomUUID();
final JsonEnvelope response = queryControllerRequester.request(envelopeFrom(metadataBuilder().withId(metadataId).withName("contexta.query.aaa"), createObjectBuilder().add("someField1", "abc")));
assertThat(testQueryController.recordedEnvelopes(), hasSize(1));
assertThat(testQueryController.firstRecordedEnvelope().metadata().id(), equalTo(metadataId));
assertThat(testQueryController.firstRecordedEnvelope().metadata().name(), equalTo("contexta.query.aaa"));
assertThat(response.metadata().name(), equalTo("contexta.response.aaa"));
assertThat(response.payloadAsJsonObject().getString("someField1"), equalTo("abc"));
assertThat(testQueryApi.recordedEnvelopes(), hasSize(0));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class ConsecutiveEventBufferServiceTest method shoulCloseSourceStreamOnConsecutiveStreamClose.
@Test
public void shoulCloseSourceStreamOnConsecutiveStreamClose() {
final UUID streamId = randomUUID();
final String source = "source";
final String eventName = "source.event.name";
when(bufferInitialisationStrategy.initialiseBuffer(eq(streamId), eq(source))).thenReturn(2L);
final StreamCloseSpy sourceStreamSpy = new StreamCloseSpy();
when(streamBufferRepository.findStreamByIdAndSource(streamId, source)).thenReturn(Stream.of(new StreamBufferEvent(streamId, 4L, "someEventContent4", source), new StreamBufferEvent(streamId, 8L, "someEventContent8", source)).onClose(sourceStreamSpy));
final JsonEnvelope bufferedEvent4 = mock(JsonEnvelope.class);
when(jsonObjectEnvelopeConverter.asEnvelope("someEventContent4")).thenReturn(bufferedEvent4);
final JsonEnvelope incomingEvent = envelope().with(metadataWithDefaults().withName(eventName).withStreamId(streamId).withVersion(3L)).build();
final Stream<JsonEnvelope> returnedEvents = bufferService.currentOrderedEventsWith(incomingEvent);
returnedEvents.close();
assertThat(sourceStreamSpy.streamClosed(), is(true));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class ConsecutiveEventBufferServiceTest method shouldIncrementVersionOnIncomingEventInCorrectOrder.
@Test
public void shouldIncrementVersionOnIncomingEventInCorrectOrder() {
final UUID streamId = randomUUID();
final String source = "source";
final JsonEnvelope incomingEvent = envelope().with(metadataWithDefaults().withName(source).withStreamId(streamId).withVersion(5L)).build();
when(bufferInitialisationStrategy.initialiseBuffer(streamId, source)).thenReturn(4L);
when(streamBufferRepository.findStreamByIdAndSource(streamId, source)).thenReturn(Stream.empty());
bufferService.currentOrderedEventsWith(incomingEvent);
verify(streamStatusRepository).update(new StreamStatus(streamId, 5L, source));
}
Aggregations