Search in sources :

Example 21 with JsonEnvelope

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));
}
Also used : InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) DefaultInterceptorContext(uk.gov.justice.services.core.interceptor.DefaultInterceptorContext) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) DefaultJsonEnvelopeProvider(uk.gov.justice.services.messaging.spi.DefaultJsonEnvelopeProvider) DefaultInterceptorContext(uk.gov.justice.services.core.interceptor.DefaultInterceptorContext) Test(org.junit.Test)

Example 22 with JsonEnvelope

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));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 23 with JsonEnvelope

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));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 24 with JsonEnvelope

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));
}
Also used : StreamBufferEvent(uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent) StreamCloseSpy(uk.gov.justice.services.test.utils.common.stream.StreamCloseSpy) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 25 with JsonEnvelope

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));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) StreamStatus(uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) 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