use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class JsonEnvelopeBuilderTest method shouldBuildJsonEnvelopeContainingPayloadFromJsonEnvelope.
@Test
public void shouldBuildJsonEnvelopeContainingPayloadFromJsonEnvelope() throws Exception {
final UUID id = randomUUID();
final String name = "name";
final MetadataBuilder metadata = metadataBuilder().withId(id).withName(name);
final JsonObjectBuilder payload = createObjectBuilder().add("test", "value");
final JsonEnvelope envelope = JsonEnvelopeBuilder.envelope().withPayloadFrom(JsonEnvelope.envelopeFrom(metadata, payload)).build();
assertThat(envelope.metadata(), nullValue());
assertThat(envelope, jsonEnvelope().withPayloadOf(payloadIsJson(withJsonPath("$.test", equalTo("value")))));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class EnveloperFactoryTest method shouldCreateUsableEnveloper.
@Test
public void shouldCreateUsableEnveloper() throws Exception {
final JsonObject inputPayload = Json.createObjectBuilder().add("value", "init").build();
final JsonObject outputPayload = Json.createObjectBuilder().add("name", "output").build();
final JsonEnvelope envelope = EnvelopeFactory.createEnvelope("init.name", inputPayload);
final JsonEnvelope result = EnveloperFactory.createEnveloper().withMetadataFrom(envelope, "expected.name").apply(outputPayload);
assertThat(result, jsonEnvelope(metadata().withName("expected.name"), payloadIsJson(allOf(withJsonPath("$.name", equalTo("output")), withoutJsonPath("$.value")))));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class EnveloperFactoryTest method shouldCreateEnveloperWithRegisteredEventClasses.
@Test
public void shouldCreateEnveloperWithRegisteredEventClasses() throws Exception {
final UUID id1 = UUID.randomUUID();
final String name = "name";
final String id2 = "id2";
final String value = "value";
final JsonObject inputPayload = Json.createObjectBuilder().add(value, "init").build();
final JsonEnvelope envelope = EnvelopeFactory.createEnvelope("init.name", inputPayload);
final EnveloperFactoryTest.TestEvent1 testEvent_1 = new EnveloperFactoryTest.TestEvent1(id1, name);
final EnveloperFactoryTest.TestEvent2 testEvent_2 = new EnveloperFactoryTest.TestEvent2(id2, value);
final Stream<Object> events = Stream.of(testEvent_1, testEvent_2);
final Enveloper enveloper = EnveloperFactory.createEnveloperWithEvents(TestEvent1.class, TestEvent2.class);
final List<JsonEnvelope> resultEvents = events.map(enveloper.withMetadataFrom(envelope)).collect(toList());
assertThat(resultEvents, listContaining(jsonEnvelope(metadata().withName("test.event.1"), payloadIsJson(allOf(withJsonPath("$.id", equalTo(id1.toString())), withJsonPath("$.name", equalTo(name))))), jsonEnvelope(metadata().withName("test.event.2"), payloadIsJson(allOf(withJsonPath("$.id", equalTo(id2)), withJsonPath("$.value", equalTo(value)))))));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class EventConverterTest method shouldCreateEventLog.
@Test
public void shouldCreateEventLog() throws Exception {
JsonEnvelope envelope = envelopeFrom(metadataBuilder().withId(ID).withName(NAME).withStreamId(STREAM_ID).withVersion(SEQUENCE_ID).createdAt(clock.now()), createObjectBuilder().add(PAYLOAD_FIELD_NAME, PAYLOAD_FIELD_VALUE));
Event event = eventConverter.eventOf(envelope);
assertThat(event.getId(), equalTo(ID));
assertThat(event.getName(), equalTo(NAME));
assertThat(event.getStreamId(), equalTo(STREAM_ID));
assertThat(event.getSequenceId(), equalTo(SEQUENCE_ID));
assertThat(event.getCreatedAt(), is(clock.now()));
JSONAssert.assertEquals(METADATA_JSON, event.getMetadata(), false);
JSONAssert.assertEquals(envelope.payloadAsJsonObject().toString(), event.getPayload(), false);
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class EventConverterTest method shouldCreateEnvelope.
@Test
public void shouldCreateEnvelope() throws Exception {
JsonEnvelope actualEnvelope = eventConverter.envelopeOf(new Event(ID, STREAM_ID, SEQUENCE_ID, NAME, METADATA_JSON, PAYLOAD_JSON, new UtcClock().now()));
assertThat(actualEnvelope.metadata().id(), equalTo(ID));
assertThat(actualEnvelope.metadata().name(), equalTo(NAME));
String actualPayload = actualEnvelope.payloadAsJsonObject().toString();
JSONAssert.assertEquals(PAYLOAD_JSON, actualPayload, false);
}
Aggregations