use of uk.gov.justice.domain.aggregate.TestAggregate in project microservice_framework by CJSCommonPlatform.
the class DefaultSnapshotServiceTest method shouldCreateSnapshotIfStrategyMandatesCreation.
@Test
public void shouldCreateSnapshotIfStrategyMandatesCreation() throws AggregateChangeDetectedException {
final TestAggregate aggregate = new TestAggregate();
final Optional<AggregateSnapshot<TestAggregate>> aggregateSnapshot = Optional.empty();
final Long currentSnapshotVersion = 0l;
final Long currentAggregateVersionId = 26l;
when(snapshotRepository.getLatestSnapshot(STREAM_ID, TestAggregate.class)).thenReturn(aggregateSnapshot);
when(snapshotRepository.getLatestSnapshotVersion(STREAM_ID, TestAggregate.class)).thenReturn(currentSnapshotVersion);
when(snapshotStrategy.shouldCreateSnapshot(currentAggregateVersionId, currentSnapshotVersion)).thenReturn(true);
snapshotService.attemptAggregateStore(STREAM_ID, currentAggregateVersionId, aggregate);
verify(snapshotRepository, times(1)).storeSnapshot(snapshotArgumentCaptor.capture());
assertThat(snapshotArgumentCaptor.getValue(), notNullValue());
assertThat(snapshotArgumentCaptor.getValue().getVersionId(), is(currentAggregateVersionId));
}
use of uk.gov.justice.domain.aggregate.TestAggregate in project microservice_framework by CJSCommonPlatform.
the class DefaultSnapshotServiceTest method shouldNotCreateAggregateIfStrategyDoesNotMandatesCreation.
@Test
public void shouldNotCreateAggregateIfStrategyDoesNotMandatesCreation() throws AggregateChangeDetectedException {
final Long currentSnapshotVersion = 0l;
final Long currentAggregateVersionId = 26l;
final TestAggregate aggregate = new TestAggregate();
when(snapshotRepository.getLatestSnapshotVersion(STREAM_ID, TestAggregate.class)).thenReturn(currentSnapshotVersion);
when(snapshotStrategy.shouldCreateSnapshot(currentAggregateVersionId, currentSnapshotVersion)).thenReturn(false);
snapshotService.attemptAggregateStore(STREAM_ID, currentAggregateVersionId, aggregate);
verify(snapshotRepository, never()).storeSnapshot(any(AggregateSnapshot.class));
}
use of uk.gov.justice.domain.aggregate.TestAggregate in project microservice_framework by CJSCommonPlatform.
the class DefaultAggregateServiceIT method shouldCreateAggregateFromEmptyStream.
@Test
public void shouldCreateAggregateFromEmptyStream() {
final EventStream eventStream = eventSource.getStreamById(STREAM_ID);
final TestAggregate aggregate = aggregateService.get(eventStream, TestAggregate.class);
assertThat(aggregate, notNullValue());
assertThat(aggregate.recordedEvents(), empty());
assertThat(rowCount(SQL_EVENT_STREAM_COUNT_BY_STREAM_ID, STREAM_ID), is(0));
}
use of uk.gov.justice.domain.aggregate.TestAggregate 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.domain.aggregate.TestAggregate 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));
}
Aggregations