use of io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method not_store_snapshot_if_not_needed.
@Test
public void not_store_snapshot_if_not_needed() {
final ProjectAggregate aggregate = GivenAggregate.withUncommittedEvents();
repository.store(aggregate);
final AggregateStateRecord record = readRecord(aggregate);
assertFalse(record.hasSnapshot());
}
use of io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method route_events_to_aggregates.
@Test
public void route_events_to_aggregates() {
final ProjectAggregate parent = givenStoredAggregate();
final ProjectAggregate child = givenStoredAggregate();
assertTrue(repository.find(parent.getId()).isPresent());
assertTrue(repository.find(child.getId()).isPresent());
final TestEventFactory factory = TestEventFactory.newInstance(getClass());
final AggProjectArchived msg = AggProjectArchived.newBuilder().setProjectId(parent.getId()).addChildProjectId(child.getId()).build();
final Event event = factory.createEvent(msg);
boundedContext.getEventBus().post(event);
// Check that the child aggregate was archived.
final Optional<ProjectAggregate> childAfterArchive = repository.find(child.getId());
assertTrue(childAfterArchive.isPresent());
assertTrue(childAfterArchive.get().isArchived());
// The parent should not be archived since the dispatch route uses only
// child aggregates from the `ProjectArchived` event.
final Optional<ProjectAggregate> parentAfterArchive = repository.find(parent.getId());
assertTrue(parentAfterArchive.isPresent());
assertFalse(parentAfterArchive.get().isArchived());
}
use of io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method pass_updated_snapshot_trigger_to_AggregateReadRequest.
@SuppressWarnings("unchecked")
@Test
public void pass_updated_snapshot_trigger_to_AggregateReadRequest() {
final AggregateRepository<ProjectId, ProjectAggregate> repositorySpy = spy(repository);
final AggregateStorage<ProjectId> storageSpy = spy(repositorySpy.aggregateStorage());
doReturn(storageSpy).when(repositorySpy).aggregateStorage();
final int nonDefaultSnapshotTrigger = DEFAULT_SNAPSHOT_TRIGGER * 2;
repositorySpy.setSnapshotTrigger(nonDefaultSnapshotTrigger);
final ProjectId id = Sample.messageOfType(ProjectId.class);
repositorySpy.loadOrCreate(id);
final ArgumentCaptor<AggregateReadRequest<ProjectId>> requestCaptor = ArgumentCaptor.forClass(AggregateReadRequest.class);
verify(storageSpy).read(requestCaptor.capture());
final AggregateReadRequest<ProjectId> passedRequest = requestCaptor.getValue();
assertEquals(id, passedRequest.getRecordId());
assertEquals(nonDefaultSnapshotTrigger, passedRequest.getBatchSize());
}
use of io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method find_archived_aggregates.
@Test
public void find_archived_aggregates() {
final ProjectAggregate aggregate = givenStoredAggregate();
final AggregateTransaction tx = AggregateTransaction.start(aggregate);
aggregate.setArchived(true);
tx.commit();
repository.store(aggregate);
assertTrue(repository.find(aggregate.getId()).isPresent());
}
use of io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method do_not_create_new_aggregates_on_find.
@Test
public void do_not_create_new_aggregates_on_find() {
final ProjectId newId = Sample.messageOfType(ProjectId.class);
final Optional<ProjectAggregate> optional = repository.find(newId);
assertFalse(optional.isPresent());
}
Aggregations