use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class JmsLoggerMetadataInterceptorTest method shouldAddMetadataFromEnvelopeToMappedDiagnosticContext.
@Test
@SuppressWarnings("deprecation")
public void shouldAddMetadataFromEnvelopeToMappedDiagnosticContext() throws Exception {
final UUID messageId = randomUUID();
final String clientCorrelationId = randomUUID().toString();
final String name = "someName";
final JsonEnvelope jsonEnvelope = envelopeFrom(metadataBuilder().withId(messageId).withName(name).withClientCorrelationId(clientCorrelationId), createObjectBuilder().add("data", "someData"));
final TextMessage textMessage = mock(TextMessage.class);
final JsonObject jsonObject = createObjectBuilder().add("id", messageId.toString()).build();
when(context.getParameters()).thenReturn(new Object[] { textMessage });
when(textMessage.getText()).thenReturn(jsonEnvelope.toDebugStringPrettyPrint());
when(jmsMessageLoggerHelper.metadataAsJsonObject(textMessage)).thenReturn(jsonObject);
when(context.proceed()).thenAnswer(invocationOnMock -> {
assertThat(MDC.get(REQUEST_DATA), isJson(withJsonPath("$.metadata.id", equalTo(messageId.toString()))));
return null;
});
jmsLoggerMetadataInterceptor.addRequestDataToMappedDiagnosticContext(context);
assertThat(MDC.get(REQUEST_DATA), nullValue());
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class CakesQueryViewTest method shouldReturnCakes.
@Test
public void shouldReturnCakes() throws Exception {
final UUID id1 = randomUUID();
final String name1 = "Chocolate cake";
final JsonEnvelope query = envelope().with(metadataWithDefaults()).build();
final UUID id2 = randomUUID();
final String name2 = "Cheese cake";
when(service.cakes()).thenReturn(new CakesView(asList(new CakeView(id1, name1), new CakeView(id2, name2))));
final JsonEnvelope response = queryView.cakes(query);
assertThat(response, jsonEnvelope().withPayloadOf(payloadIsJson(allOf(withJsonPath("$.cakes[0].id", equalTo(id1.toString())), withJsonPath("$.cakes[0].name", equalTo(name1)), withJsonPath("$.cakes[1].id", equalTo(id2.toString())), withJsonPath("$.cakes[1].name", equalTo(name2))))));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class DispatcherDelegateTest method requestMethodShouldDelegateToDispatcher.
@Test
public void requestMethodShouldDelegateToDispatcher() throws Exception {
final JsonEnvelope envelope = mock(JsonEnvelope.class);
when(envelopePayloadTypeConverter.convert(any(Envelope.class), eq(JsonValue.class))).thenReturn(envelope);
when(jsonEnvelopeRepacker.repack(envelope)).thenReturn(envelope);
dispatcherDelegate.request(envelope);
verify(dispatcher).dispatch(envelope);
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class DispatcherDelegateTest method sendAsAdminMethodShouldDelegateEnvelopeReturnedBySystemUserUtil.
@Test
public void sendAsAdminMethodShouldDelegateEnvelopeReturnedBySystemUserUtil() {
final JsonEnvelope envelope = mock(JsonEnvelope.class);
final JsonEnvelope envelopeWithSysUserId = mock(JsonEnvelope.class);
when(systemUserUtil.asEnvelopeWithSystemUserId(envelope)).thenReturn(envelopeWithSysUserId);
dispatcherDelegate.sendAsAdmin(envelope);
verify(dispatcher).dispatch(envelopeWithSysUserId);
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class DispatcherTest method shouldDispatchAsynchronouslyToAValidHandler.
@Test
public void shouldDispatchAsynchronouslyToAValidHandler() throws Exception {
final AsynchronousTestHandler asynchronousTestHandler = new AsynchronousTestHandler();
final JsonValue payload = createObjectBuilder().add("aField", "aValue").build();
final JsonEnvelope envelope = envelopeFrom(metadata, payload);
dispatcher.register(asynchronousTestHandler);
dispatcher.dispatch(envelope);
final List<JsonEnvelope> dispatchedEnvelopes = asynchronousTestHandler.recordedEnvelopes();
assertThat(dispatchedEnvelopes, hasSize(1));
assertThat(dispatchedEnvelopes.get(0), equalTo(envelope));
}
Aggregations