use of uk.gov.justice.services.core.enveloper.Enveloper 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)))))));
}
Aggregations