use of uk.gov.justice.services.core.extension.EventFoundEvent in project microservice_framework by CJSCommonPlatform.
the class DefaultEnveloperTest method shouldRemoveStreamMetadata.
@Test
public void shouldRemoveStreamMetadata() throws Exception {
enveloper.register(new EventFoundEvent(TestEvent.class, TEST_EVENT_NAME));
final JsonEnvelope event = enveloper.withMetadataFrom(envelopeFrom(metadataBuilder().withId(COMMAND_UUID).withName(TEST_EVENT_NAME).withStreamId(randomUUID()).withVersion(123l), createObjectBuilder())).apply(new TestEvent());
assertThat(event.metadata().streamId(), is(empty()));
assertThat(event.metadata().version(), is(empty()));
}
use of uk.gov.justice.services.core.extension.EventFoundEvent in project microservice_framework by CJSCommonPlatform.
the class DefaultEnveloperTest method shouldEnvelopeEventObject.
@Test
public void shouldEnvelopeEventObject() throws Exception {
enveloper.register(new EventFoundEvent(TestEvent.class, TEST_EVENT_NAME));
final JsonEnvelope event = enveloper.withMetadataFrom(envelopeFrom(metadataBuilder().withId(COMMAND_UUID).withName(TEST_EVENT_NAME).withCausation(OLD_CAUSATION_ID), createObjectBuilder())).apply(new TestEvent("somePayloadValue"));
assertThat(event.metadata().id(), notNullValue());
assertThat(event.metadata().id(), not(equalTo(COMMAND_UUID)));
assertThat(event.metadata().name(), equalTo(TEST_EVENT_NAME));
assertThat(event.metadata().causation().size(), equalTo(2));
assertThat(event.metadata().causation().get(0), equalTo(OLD_CAUSATION_ID));
assertThat(event.metadata().causation().get(1), equalTo(COMMAND_UUID));
assertThat(event.payloadAsJsonObject().getString("somePayloadKey"), equalTo("somePayloadValue"));
}
use of uk.gov.justice.services.core.extension.EventFoundEvent in project microservice_framework by CJSCommonPlatform.
the class DefaultEnveloperTest method shouldEnvelopeObjectWithoutCausation.
@Test
public void shouldEnvelopeObjectWithoutCausation() throws Exception {
enveloper.register(new EventFoundEvent(TestEvent.class, TEST_EVENT_NAME));
final JsonEnvelope event = enveloper.withMetadataFrom(envelopeFrom(metadataBuilder().withId(COMMAND_UUID).withName(TEST_EVENT_NAME), createObjectBuilder())).apply(new TestEvent());
assertThat(event.metadata().id(), notNullValue());
assertThat(event.metadata().name(), equalTo(TEST_EVENT_NAME));
assertThat(event.metadata().causation().size(), equalTo(1));
assertThat(event.metadata().causation().get(0), equalTo(COMMAND_UUID));
}
use of uk.gov.justice.services.core.extension.EventFoundEvent in project microservice_framework by CJSCommonPlatform.
the class DefaultEnveloperProviderTest method shouldDelegateToDefaultEnveloperFromCdiToEnvelopeWithMetadateFrom.
@Test
public void shouldDelegateToDefaultEnveloperFromCdiToEnvelopeWithMetadateFrom() throws Exception {
final DefaultEnveloper enveloper = new DefaultEnveloper(new UtcClock(), new ObjectToJsonValueConverter(new ObjectMapperProducer().objectMapper()));
enveloper.register(new EventFoundEvent(DefaultEnveloperProviderTest.TestEvent.class, TEST_EVENT_NAME));
final Metadata metadata = createMetadata();
final TestPojo payload = new TestPojo(TEST_EVENT_NAME);
final Envelope<TestPojo> envelope = envelopeFrom(metadata, payload);
final Function<Object, JsonEnvelope> envelope1 = new DefaultEnveloperProvider().toEnvelopeWithMetadataFrom(envelope);
final TestEvent testEvent = new TestEvent();
assertThat(envelope1.apply(testEvent).metadata().name(), is(metadata.name()));
assertThat(envelope.payload(), is(payload));
}
use of uk.gov.justice.services.core.extension.EventFoundEvent in project microservice_framework by CJSCommonPlatform.
the class EnveloperFactory method createWithEvents.
public Enveloper createWithEvents(final Class<?>... events) {
final DefaultEnveloper enveloper = create();
stream(events).forEach(eventClass -> {
if (eventClass.isAnnotationPresent(Event.class)) {
final Event eventClassAnnotation = eventClass.getAnnotation(Event.class);
enveloper.register(new EventFoundEvent(eventClass, eventClassAnnotation.value()));
}
});
return enveloper;
}
Aggregations