Search in sources :

Example 1 with ProjectAggregate

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());
}
Also used : ProjectAggregate(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate) Test(org.junit.Test)

Example 2 with ProjectAggregate

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());
}
Also used : ProjectAggregate(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate) TestEventFactory(io.spine.server.command.TestEventFactory) Event(io.spine.core.Event) AggProjectArchived(io.spine.test.aggregate.event.AggProjectArchived) Test(org.junit.Test)

Example 3 with ProjectAggregate

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());
}
Also used : ProjectAggregate(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate) ProjectId(io.spine.test.aggregate.ProjectId) Test(org.junit.Test)

Example 4 with ProjectAggregate

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());
}
Also used : ProjectAggregate(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate) Test(org.junit.Test)

Example 5 with ProjectAggregate

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());
}
Also used : ProjectAggregate(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate) ProjectId(io.spine.test.aggregate.ProjectId) Test(org.junit.Test)

Aggregations

ProjectAggregate (io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate)13 Test (org.junit.Test)11 ProjectId (io.spine.test.aggregate.ProjectId)7 Event (io.spine.core.Event)1 TestEventFactory (io.spine.server.command.TestEventFactory)1 TenantAwareOperation (io.spine.server.tenant.TenantAwareOperation)1 AggProjectArchived (io.spine.test.aggregate.event.AggProjectArchived)1