Search in sources :

Example 1 with EventFoundEvent

use of uk.gov.justice.services.core.extension.EventFoundEvent in project microservice_framework by CJSCommonPlatform.

the class DefaultEnveloperTest method shouldRemoveStreamMetadataWithName.

@Test
public void shouldRemoveStreamMetadataWithName() 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()), "new.name").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 2 with EventFoundEvent

use of uk.gov.justice.services.core.extension.EventFoundEvent in project microservice_framework by CJSCommonPlatform.

the class SnapshotAwareAggregateServiceIT method init.

@Before
public void init() throws Exception {
    final InitialContext initialContext = new InitialContext();
    initialContext.bind("java:/app/SnapshotAwareAggregateServiceIT/DS.eventstore", dataSource);
    initEventDatabase();
    defaultAggregateService.register(new EventFoundEvent(EventA.class, "context.eventA"));
}
Also used : EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) EventA(uk.gov.justice.domain.event.EventA) InitialContext(javax.naming.InitialContext) Before(org.junit.Before)

Example 3 with EventFoundEvent

use of uk.gov.justice.services.core.extension.EventFoundEvent in project microservice_framework by CJSCommonPlatform.

the class DefaultAggregateServiceIT method shouldCreateAggregateFromSingletonStream.

@Test
public void shouldCreateAggregateFromSingletonStream() throws EventStreamException {
    final EventStream eventStream = eventSource.getStreamById(STREAM_ID);
    aggregateService.register(new EventFoundEvent(EventA.class, "context.eventA"));
    aggregateService.get(eventStream, TestAggregate.class);
    eventStream.append(Stream.of(envelopeFrom("context.eventA")));
    final TestAggregate aggregate = aggregateService.get(eventSource.getStreamById(STREAM_ID), TestAggregate.class);
    assertThat(aggregate, notNullValue());
    assertThat(aggregate.recordedEvents(), hasSize(1));
    assertThat(aggregate.recordedEvents().get(0).getClass(), equalTo(EventA.class));
    assertThat(rowCount(SQL_EVENT_LOG_COUNT_BY_STREAM_ID, STREAM_ID), is(1));
    assertThat(rowCount(SQL_EVENT_STREAM_COUNT_BY_STREAM_ID, STREAM_ID), is(1));
}
Also used : EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) TestAggregate(uk.gov.justice.domain.aggregate.TestAggregate) EventA(uk.gov.justice.services.core.aggregate.event.EventA) Test(org.junit.Test)

Example 4 with EventFoundEvent

use of uk.gov.justice.services.core.extension.EventFoundEvent in project microservice_framework by CJSCommonPlatform.

the class DefaultAggregateServiceIT method shouldCreateAggregateFromStreamOfTwo.

@Test
public void shouldCreateAggregateFromStreamOfTwo() throws EventStreamException {
    final EventStream eventStream = eventSource.getStreamById(STREAM_ID);
    aggregateService.register(new EventFoundEvent(EventA.class, "context.eventA"));
    aggregateService.register(new EventFoundEvent(EventB.class, "context.eventB"));
    aggregateService.get(eventStream, TestAggregate.class);
    eventStream.append(Stream.of(envelopeFrom("context.eventA"), envelopeFrom("context.eventB")));
    final TestAggregate aggregate = aggregateService.get(eventSource.getStreamById(STREAM_ID), TestAggregate.class);
    assertThat(aggregate, notNullValue());
    assertThat(aggregate.recordedEvents(), hasSize(2));
    assertThat(aggregate.recordedEvents().get(0).getClass(), equalTo(EventA.class));
    assertThat(aggregate.recordedEvents().get(1).getClass(), equalTo(EventB.class));
    assertThat(rowCount(SQL_EVENT_LOG_COUNT_BY_STREAM_ID, STREAM_ID), is(2));
    assertThat(rowCount(SQL_EVENT_STREAM_COUNT_BY_STREAM_ID, STREAM_ID), is(1));
}
Also used : EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) EventB(uk.gov.justice.services.core.aggregate.event.EventB) EventStream(uk.gov.justice.services.eventsourcing.source.core.EventStream) EnvelopeEventStream(uk.gov.justice.services.eventsourcing.source.core.EnvelopeEventStream) TestAggregate(uk.gov.justice.domain.aggregate.TestAggregate) EventA(uk.gov.justice.services.core.aggregate.event.EventA) Test(org.junit.Test)

Example 5 with EventFoundEvent

use of uk.gov.justice.services.core.extension.EventFoundEvent in project microservice_framework by CJSCommonPlatform.

the class DefaultAggregateServiceTest method shouldCreateAggregateFromStreamOfThreeWithAFilteredOutSystemEvent.

@Test
public void shouldCreateAggregateFromStreamOfThreeWithAFilteredOutSystemEvent() {
    JsonObject eventPayloadA = mock(JsonObject.class);
    JsonObject eventPayloadB = mock(JsonObject.class);
    EventA eventA = mock(EventA.class);
    EventB eventB = mock(EventB.class);
    when(jsonObjectToObjectConverter.convert(eventPayloadA, EventA.class)).thenReturn(eventA);
    when(jsonObjectToObjectConverter.convert(eventPayloadB, EventB.class)).thenReturn(eventB);
    when(eventStream.read()).thenReturn(Stream.of(envelopeFrom(metadataWithRandomUUID("eventA"), eventPayloadA), envelopeFrom(metadataWithRandomUUID("eventB"), eventPayloadB), envelopeFrom(metadataWithRandomUUID("system.events.eventC"), eventPayloadB)));
    when(eventStream.getId()).thenReturn(STREAM_ID);
    aggregateService.register(new EventFoundEvent(EventA.class, "eventA"));
    aggregateService.register(new EventFoundEvent(EventB.class, "eventB"));
    TestAggregate aggregate = aggregateService.get(eventStream, TestAggregate.class);
    assertThat(aggregate, notNullValue());
    assertThat(aggregate.recordedEvents(), hasSize(2));
    assertThat(aggregate.recordedEvents().get(0), equalTo(eventA));
    assertThat(aggregate.recordedEvents().get(1), equalTo(eventB));
    verify(logger).info("Registering event {}, {} with DefaultAggregateService", "eventA", EventA.class);
    verify(logger).info("Registering event {}, {} with DefaultAggregateService", "eventB", EventB.class);
    verify(logger).trace("Recreating aggregate for instance {} of aggregate type {}", STREAM_ID, TestAggregate.class);
}
Also used : EventB(uk.gov.justice.services.core.aggregate.event.EventB) EventFoundEvent(uk.gov.justice.services.core.extension.EventFoundEvent) TestAggregate(uk.gov.justice.domain.aggregate.TestAggregate) JsonObject(javax.json.JsonObject) EventA(uk.gov.justice.services.core.aggregate.event.EventA) Test(org.junit.Test)

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