Search in sources :

Example 6 with EventFoundEvent

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()));
}
Also used : EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 7 with EventFoundEvent

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"));
}
Also used : EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 8 with EventFoundEvent

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));
}
Also used : EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 9 with EventFoundEvent

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));
}
Also used : UtcClock(uk.gov.justice.services.common.util.UtcClock) Metadata(uk.gov.justice.services.messaging.Metadata) ObjectToJsonValueConverter(uk.gov.justice.services.common.converter.ObjectToJsonValueConverter) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) ObjectMapperProducer(uk.gov.justice.services.common.converter.jackson.ObjectMapperProducer) EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) DefaultEnveloper(uk.gov.justice.services.core.enveloper.DefaultEnveloper) Test(org.junit.Test)

Example 10 with EventFoundEvent

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;
}
Also used : EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) DefaultEnveloper(uk.gov.justice.services.core.enveloper.DefaultEnveloper) EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) Event(uk.gov.justice.domain.annotation.Event)

Aggregations

EventFoundEvent (uk.gov.justice.services.core.extension.EventFoundEvent)11 Test (org.junit.Test)9 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)5 EventA (uk.gov.justice.services.core.aggregate.event.EventA)4 TestAggregate (uk.gov.justice.domain.aggregate.TestAggregate)3 EnvelopeEventStream (uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream)3 EventStream (uk.gov.justice.services.eventsourcing.source.core.EventStream)3 EventB (uk.gov.justice.services.core.aggregate.event.EventB)2 DefaultEnveloper (uk.gov.justice.services.core.enveloper.DefaultEnveloper)2 JsonObject (javax.json.JsonObject)1 InitialContext (javax.naming.InitialContext)1 Before (org.junit.Before)1 Event (uk.gov.justice.domain.annotation.Event)1 EventA (uk.gov.justice.domain.event.EventA)1 ObjectToJsonValueConverter (uk.gov.justice.services.common.converter.ObjectToJsonValueConverter)1 ObjectMapperProducer (uk.gov.justice.services.common.converter.jackson.ObjectMapperProducer)1 UtcClock (uk.gov.justice.services.common.util.UtcClock)1 Metadata (uk.gov.justice.services.messaging.Metadata)1