Search in sources :

Example 31 with JsonEnvelope

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

Example 32 with JsonEnvelope

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

Example 33 with JsonEnvelope

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);
}
Also used : JsonValue(javax.json.JsonValue) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Envelope(uk.gov.justice.services.messaging.Envelope) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 34 with JsonEnvelope

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

Example 35 with JsonEnvelope

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));
}
Also used : JsonValue(javax.json.JsonValue) 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