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()));
}
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"));
}
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));
}
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));
}
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);
}
Aggregations