use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class DefaultContextPayloadTest method shouldCreateContextPayloadWithEnvelope.
@Test
public void shouldCreateContextPayloadWithEnvelope() throws Exception {
final JsonEnvelope jsonEnvelope = mock(JsonEnvelope.class);
final ContextPayload contextPayload = contextPayloadWith(jsonEnvelope);
assertThat(contextPayload.getEnvelope(), is(Optional.of(jsonEnvelope)));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class DefaultContextPayloadTest method shouldCopyAllParametersAndAddEnvelope.
@Test
public void shouldCopyAllParametersAndAddEnvelope() throws Exception {
final JsonEnvelope jsonEnvelope = mock(JsonEnvelope.class);
final Object parameter = mock(Object.class);
final ContextPayload initialContext = contextPayloadWithNoEnvelope();
initialContext.setParameter("test", parameter);
final ContextPayload result = copyWithEnvelope(initialContext, jsonEnvelope);
assertThat(result.getEnvelope(), is(Optional.of(jsonEnvelope)));
assertThat(result.getParameter("test"), is(Optional.of(parameter)));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class AccessControlFailureMessageGeneratorTest method shouldGenerateAnErrorMessageWithUserIdEnvelopeNameAndFailureReason.
@Test
public void shouldGenerateAnErrorMessageWithUserIdEnvelopeNameAndFailureReason() throws Exception {
final String jsonEnvelopeString = "the: jsonEnvelope";
final String reason = "reason";
final AccessControlViolation accessControlViolation = new AccessControlViolation(reason);
final JsonEnvelope jsonEnvelope = mock(JsonEnvelope.class);
when(jsonEnvelope.toString()).thenReturn(jsonEnvelopeString);
final String errorMessage = accessControlFailureMessageGenerator.errorMessageFrom(jsonEnvelope, accessControlViolation);
assertThat(errorMessage, is("Access Control failed for json envelope 'the: jsonEnvelope'. Reason: reason"));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class SimpleAuditClientTest method shouldPrependTheAppNameToTheEnvelopeJsonAndLog.
@Test
public void shouldPrependTheAppNameToTheEnvelopeJsonAndLog() throws Exception {
final String serviceContextName = "the-service-context-name";
final String propertyValue = "value";
final String envelopeJson = new JSONObject().put("propertyName", propertyValue).toString();
final JsonEnvelope envelope = mock(JsonEnvelope.class);
when(envelope.toString()).thenReturn(envelopeJson);
when(serviceContextNameProvider.getServiceContextName()).thenReturn(serviceContextName);
simpleAuditClient.auditEntry(envelope, COMPONENT);
final ArgumentCaptor<String> argumentCaptor = forClass(String.class);
verify(logger).info(argumentCaptor.capture());
final String json = argumentCaptor.getValue();
with(json).assertEquals("serviceContext", serviceContextName).assertEquals("component", COMPONENT).assertEquals("envelope.propertyName", propertyValue);
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class EventsServiceTest method shouldReturnFirstEvents.
@Test
public void shouldReturnFirstEvents() throws Exception {
final UUID streamId = randomUUID();
final ZonedDateTime event1CreatedAt = now();
final ZonedDateTime event2CreatedAt = now();
final long pageSize = 2L;
final JsonObject payload1 = createObjectBuilder().add("field1", "value1").build();
final JsonObject payload2 = createObjectBuilder().add("field2", "value2").build();
final JsonEnvelope event1 = envelope().withPayloadOf("value1", "field1").with(metadataOf(streamId, "Test Name1").withVersion(1L).withStreamId(streamId).createdAt(event1CreatedAt)).build();
final JsonEnvelope event2 = envelope().withPayloadOf("value2", "field2").with(metadataOf(streamId, "Test Name2").withVersion(2L).withStreamId(streamId).createdAt(event2CreatedAt)).build();
final EventStream eventStream = mock(EventStream.class);
when(eventSource.getStreamById(streamId)).thenReturn(eventStream);
when(eventStream.size()).thenReturn(2L);
when(eventStream.readFrom(first().getPosition())).thenReturn(Stream.of(event1, event2));
final List<EventEntry> eventEntries = service.events(streamId, first(), FORWARD, pageSize);
assertThat(eventEntries, hasSize(2));
assertThat(eventEntries.get(0).getStreamId(), is(streamId.toString()));
assertThat(eventEntries.get(0).getName(), is("Test Name2"));
assertThat(eventEntries.get(0).getPosition(), is(2L));
assertThat(eventEntries.get(0).getCreatedAt(), is(ZonedDateTimes.toString(event2CreatedAt)));
assertThat(eventEntries.get(0).getPayload(), is(notNullValue()));
assertThat(eventEntries.get(0).getPayload(), is(payload2));
assertThat(eventEntries.get(1).getStreamId(), is(streamId.toString()));
assertThat(eventEntries.get(1).getName(), is("Test Name1"));
assertThat(eventEntries.get(1).getPosition(), is(1L));
assertThat(eventEntries.get(1).getPayload(), is(payload1));
assertThat(eventEntries.get(1).getCreatedAt(), is(ZonedDateTimes.toString(event1CreatedAt)));
}
Aggregations