Search in sources :

Example 1 with Enveloper

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

Aggregations

UUID (java.util.UUID)1 JsonObject (javax.json.JsonObject)1 Test (org.junit.Test)1 Enveloper (uk.gov.justice.services.core.enveloper.Enveloper)1 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)1