Search in sources :

Example 11 with ProjectAggregate

use of io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate in project core-java by SpineEventEngine.

the class AggregateRepositoryShould method throw_ISE_if_unable_to_load_entity_by_id_from_storage_index.

@Test(expected = IllegalStateException.class)
public void throw_ISE_if_unable_to_load_entity_by_id_from_storage_index() {
    // Store a valid aggregate.
    givenStoredAggregate();
    // Store a troublesome entity, which cannot be loaded.
    final TenantAwareOperation op = new TenantAwareOperation(newUuid()) {

        @Override
        public void run() {
            givenStoredAggregateWithId(ProjectAggregateRepository.troublesome.getId());
        }
    };
    op.execute();
    final Iterator<ProjectAggregate> iterator = repository.iterator(Predicates.<ProjectAggregate>alwaysTrue());
    // This should iterate through all and fail.
    Lists.newArrayList(iterator);
}
Also used : ProjectAggregate(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation) Test(org.junit.Test)

Example 12 with ProjectAggregate

use of io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate in project core-java by SpineEventEngine.

the class AggregateRepositoryShould method restore_aggregate_using_snapshot.

@Test
public void restore_aggregate_using_snapshot() {
    final ProjectId id = Sample.messageOfType(ProjectId.class);
    final ProjectAggregate expected = GivenAggregate.withUncommittedEvents(id);
    repository.setSnapshotTrigger(expected.uncommittedEventsCount());
    repository.store(expected);
    final ProjectAggregate actual = repository.find(id).get();
    assertEquals(expected.getId(), actual.getId());
    assertEquals(expected.getState(), actual.getState());
}
Also used : ProjectAggregate(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate) ProjectId(io.spine.test.aggregate.ProjectId) Test(org.junit.Test)

Example 13 with ProjectAggregate

use of io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate in project core-java by SpineEventEngine.

the class AggregateRepositoryShould method store_snapshot_and_set_event_count_to_zero_if_needed.

@Test
public void store_snapshot_and_set_event_count_to_zero_if_needed() {
    final ProjectAggregate aggregate = GivenAggregate.withUncommittedEvents();
    // This should make the repository write the snapshot.
    repository.setSnapshotTrigger(aggregate.uncommittedEventsCount());
    repository.store(aggregate);
    final AggregateStateRecord record = readRecord(aggregate);
    assertTrue(record.hasSnapshot());
    assertEquals(0, repository.aggregateStorage().readEventCountAfterLastSnapshot(aggregate.getId()));
}
Also used : ProjectAggregate(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate) 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