use of uk.gov.justice.domain.snapshot.AggregateSnapshot 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.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.
the class SnapshotRepositoryJdbcIT method shouldRemoveAllSnapshots.
@Test
public void shouldRemoveAllSnapshots() {
final UUID streamId = randomUUID();
final AggregateSnapshot aggregateSnapshot1 = createSnapshot(streamId, VERSION_ID + 1, TYPE, AGGREGATE);
final AggregateSnapshot aggregateSnapshot2 = createSnapshot(streamId, VERSION_ID + 2, TYPE, AGGREGATE);
final AggregateSnapshot aggregateSnapshot3 = createSnapshot(streamId, VERSION_ID + 3, TYPE, AGGREGATE);
final AggregateSnapshot aggregateSnapshot4 = createSnapshot(streamId, VERSION_ID + 4, TYPE, AGGREGATE);
final AggregateSnapshot aggregateSnapshot5 = createSnapshot(streamId, VERSION_ID + 6, TYPE, AGGREGATE);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot1);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot2);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot3);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot4);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot5);
snapshotJdbcRepository.removeAllSnapshots(streamId, TYPE);
final Optional<AggregateSnapshot<RecordingAggregate>> snapshots = snapshotJdbcRepository.getLatestSnapshot(streamId, TYPE);
assertThat(snapshots, notNullValue());
assertThat(snapshots.isPresent(), is(false));
}
use of uk.gov.justice.domain.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.
the class SnapshotRepositoryJdbcIT method shouldRetrieveLatestSnapshot.
@Test
public void shouldRetrieveLatestSnapshot() {
final UUID streamId = randomUUID();
final AggregateSnapshot aggregateSnapshot1 = createSnapshot(streamId, VERSION_ID + 1, TYPE, AGGREGATE);
final AggregateSnapshot aggregateSnapshot2 = createSnapshot(streamId, VERSION_ID + 2, TYPE, AGGREGATE);
final AggregateSnapshot aggregateSnapshot3 = createSnapshot(streamId, VERSION_ID + 3, TYPE, AGGREGATE);
final AggregateSnapshot aggregateSnapshot4 = createSnapshot(streamId, VERSION_ID + 4, TYPE, AGGREGATE);
final AggregateSnapshot aggregateSnapshot5 = createSnapshot(streamId, VERSION_ID + 5, TYPE, AGGREGATE);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot1);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot2);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot3);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot4);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot5);
final Optional<AggregateSnapshot<RecordingAggregate>> snapshot = snapshotJdbcRepository.getLatestSnapshot(streamId, TYPE);
assertThat(snapshot, notNullValue());
assertThat(snapshot, is(Optional.of(aggregateSnapshot5)));
}
use of uk.gov.justice.domain.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.
the class SnapshotRepositoryJdbcIT method shouldStoreAndRetrieveSnapshot.
@Test
public void shouldStoreAndRetrieveSnapshot() {
final UUID streamId = randomUUID();
final AggregateSnapshot aggregateSnapshot = createSnapshot(streamId, VERSION_ID, TYPE, AGGREGATE);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot);
final Optional<AggregateSnapshot<RecordingAggregate>> snapshot = snapshotJdbcRepository.getLatestSnapshot(streamId, TYPE);
assertThat(snapshot, notNullValue());
assertThat(snapshot, is(Optional.of(aggregateSnapshot)));
}
use of uk.gov.justice.domain.snapshot.AggregateSnapshot in project microservice_framework by CJSCommonPlatform.
the class SnapshotRepositoryJdbcIT method shouldRetrieveOptionalNullIfOnlySnapshotsOfDifferentTypesAvailable.
@Test
public void shouldRetrieveOptionalNullIfOnlySnapshotsOfDifferentTypesAvailable() {
final UUID streamId = randomUUID();
final AggregateSnapshot aggregateSnapshot1 = createSnapshot(streamId, VERSION_ID, OTHER_TYPE, AGGREGATE);
snapshotJdbcRepository.storeSnapshot(aggregateSnapshot1);
final Optional<AggregateSnapshot<RecordingAggregate>> snapshot = snapshotJdbcRepository.getLatestSnapshot(streamId, TYPE);
assertThat(snapshot.isPresent(), is(false));
}
Aggregations