Search in sources :

Example 36 with JsonEnvelope

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

the class EnvelopePayloadTypeConverterTest method shouldConvertJsonEnvelopeToJsonEnvelope.

@Test
public void shouldConvertJsonEnvelopeToJsonEnvelope() throws IOException {
    final JsonObject payload = createObjectBuilder().add("myString", "newTest").build();
    final JsonEnvelope inputEnvelope = getJsonEnvelope(payload);
    final Envelope<JsonValue> resultEnvelope = convert(inputEnvelope, JsonValue.class);
    final JsonObject returnedPayload = (JsonObject) resultEnvelope.payload();
    assertThat(returnedPayload.getValueType(), is(OBJECT));
    assertThat(returnedPayload.toString(), hasJsonPath("$.myString", equalTo("newTest")));
}
Also used : JsonValue(javax.json.JsonValue) JsonObject(javax.json.JsonObject) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 37 with JsonEnvelope

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

the class InterceptorChainProcessorProducerTest method shouldProduceProcessorThatDispatchesEnvelope_FromDirectAdapter.

@Test
public void shouldProduceProcessorThatDispatchesEnvelope_FromDirectAdapter() throws Exception {
    when(interceptorCache.getInterceptors("QUERY_API")).thenReturn(envelopeRecordingInterceptor());
    final MemberInjectionPoint injectionPoint = injectionPointWith(QueryApiDirectAdapter.class.getDeclaredField("processor"));
    interceptorChainProcessorProducer.dispatcherCache.dispatcherFor(injectionPoint).register(envelopeRecordingHandler);
    final InterceptorChainProcessor processor = interceptorChainProcessorProducer.produceProcessor(injectionPoint);
    final JsonEnvelope dispatchedEnvelope = envelopeFrom(metadataBuilder().withId(randomUUID()).withName(ACTION_NAME), createObjectBuilder());
    processor.process(interceptorContextWithInput(dispatchedEnvelope));
    assertThat(envelopeRecordingInterceptor.firstRecordedEnvelope(), is(dispatchedEnvelope));
    assertThat(envelopeRecordingHandler.firstRecordedEnvelope(), is(dispatchedEnvelope));
}
Also used : MemberInjectionPoint(uk.gov.justice.services.test.utils.common.MemberInjectionPoint) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 38 with JsonEnvelope

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

the class AllEventsHandlerIT method shouldHandleEventByTheAllEventsHandlerIfNamedHandlerNotFound.

@Test
public void shouldHandleEventByTheAllEventsHandlerIfNamedHandlerNotFound() {
    final UUID metadataId = randomUUID();
    final JsonEnvelope jsonEnvelope = envelopeFrom(metadataBuilder().withId(metadataId).withName("some.unregistered.event").withStreamId(randomUUID()).withVersion(1L), createObjectBuilder());
    interceptorChainProcessor.process(interceptorContextWithInput(jsonEnvelope));
    assertThat(allEventsHandler.firstRecordedEnvelope(), not(nullValue()));
    assertThat(allEventsHandler.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 39 with JsonEnvelope

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

the class EventHandlerIT method shouldHandleEventByName.

@Test
public void shouldHandleEventByName() {
    final UUID metadataId = randomUUID();
    final JsonEnvelope jsonEnvelope = envelopeFrom(metadataBuilder().withId(metadataId).withName(EVENT_ABC).withStreamId(randomUUID()).withVersion(1L), createObjectBuilder());
    interceptorChainProcessor.process(interceptorContextWithInput(jsonEnvelope));
    assertThat(abcEventHandler.firstRecordedEnvelope(), not(nullValue()));
    assertThat(abcEventHandler.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 40 with JsonEnvelope

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

the class DefaultInterceptorChainProcessorTest method shouldProcessJsonEnvelope.

@Test
public void shouldProcessJsonEnvelope() throws Exception {
    final JsonEnvelope inputEnvelope = mock(JsonEnvelope.class);
    final JsonEnvelope outputEnvelope = mock(JsonEnvelope.class);
    final String component = "component";
    when(interceptorCache.getInterceptors(component)).thenReturn(interceptors());
    when(dispatch.apply(inputEnvelope)).thenReturn(outputEnvelope);
    final DefaultInterceptorChainProcessor interceptorChainProcessor = new DefaultInterceptorChainProcessor(interceptorCache, dispatch, component);
    final Optional<JsonEnvelope> result = interceptorChainProcessor.process(inputEnvelope);
    assertThat(result.isPresent(), is(true));
    assertThat(result.get(), is(outputEnvelope));
}
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