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