use of uk.gov.justice.domain.snapshot.VersionedAggregate in project microservice_framework by CJSCommonPlatform.
the class SnapshotAwareAggregateServiceTest method shouldCreateAggregateFromStreamWithOneEvent.
@Test
public void shouldCreateAggregateFromStreamWithOneEvent() throws AggregateChangeDetectedException {
Optional<VersionedAggregate<TestAggregate>> versionedAggregate = Optional.empty();
final EventA eventA = new EventA();
final JsonObject eventPayloadA = mock(JsonObject.class);
when(jsonObjectToObjectConverter.convert(eventPayloadA, EventA.class)).thenReturn(eventA);
when(eventStream.getId()).thenReturn(STREAM_ID);
when(eventStream.read()).thenReturn(of(envelopeFrom(metadataWithRandomUUID("eventA"), eventPayloadA)));
when(snapshotService.getLatestVersionedAggregate(STREAM_ID, TestAggregate.class)).thenReturn(versionedAggregate);
registerEvent(EventA.class, "eventA");
registerEvent(EventB.class, "eventB");
final TestAggregate aggregateActual = aggregateService.get(eventStream, TestAggregate.class);
assertThat(aggregateActual, notNullValue());
assertThat(aggregateActual.recordedEvents(), hasSize(1));
assertThat(aggregateActual.recordedEvents(), hasItems(eventA));
verify(logger).info("Registering event {}, {} with DefaultAggregateService", "eventA", EventA.class);
verify(logger).trace("Recreating aggregate for instance {} of aggregate type {}", STREAM_ID, TestAggregate.class);
verify(logger).trace("SnapshotAwareAggregateService Recreating aggregate for instance {} of aggregate type {}", STREAM_ID, TestAggregate.class);
}
use of uk.gov.justice.domain.snapshot.VersionedAggregate in project microservice_framework by CJSCommonPlatform.
the class SnapshotAwareAggregateServiceTest method shouldThrowExceptionForNonInstantiatableEvent.
@Test(expected = RuntimeException.class)
public void shouldThrowExceptionForNonInstantiatableEvent() throws AggregateChangeDetectedException {
defaultAggregateService.logger = logger;
defaultAggregateService.jsonObjectToObjectConverter = jsonObjectToObjectConverter;
final JsonObject eventPayloadA = mock(JsonObject.class);
final EventA eventA = mock(EventA.class);
when(snapshotService.getLatestVersionedAggregate(STREAM_ID, TestAggregate.class)).thenReturn(Optional.of(new VersionedAggregate<>(INITIAL_AGGREGATE_VERSION, new TestAggregate())));
when(jsonObjectToObjectConverter.convert(eventPayloadA, EventA.class)).thenReturn(eventA);
when(eventStream.readFrom(NEXT_AGGREGATE_VERSION)).thenReturn(of(envelopeFrom(metadataWithRandomUUID("eventA"), eventPayloadA)));
registerEvent(EventA.class, "eventA");
aggregateService.get(eventStream, PrivateAggregate.class);
}
Aggregations