Search in sources :

Example 1 with TestAggregate

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

the class AggregateShould method traverse_the_history_iterating_through_newest_events_first.

@Test
public void traverse_the_history_iterating_through_newest_events_first() {
    final TenantId tenantId = newTenantId();
    final Command createCommand = command(createProject, tenantId);
    final Command startCommand = command(startProject, tenantId);
    final Command addTaskCommand = command(addTask, tenantId);
    final Command addTaskCommand2 = command(addTask, tenantId);
    final CommandBus commandBus = boundedContext.getCommandBus();
    final StreamObserver<Ack> noOpObserver = noOpObserver();
    commandBus.post(createCommand, noOpObserver);
    commandBus.post(addTaskCommand, noOpObserver);
    commandBus.post(newArrayList(addTaskCommand2, startCommand), noOpObserver);
    final TestAggregate aggregate = repository.loadAggregate(tenantId, ID);
    final Iterator<Event> history = aggregate.historyBackward();
    assertEquals(startCommand.getId(), getRootCommandId(history.next()));
    assertEquals(addTaskCommand2.getId(), getRootCommandId(history.next()));
    assertEquals(addTaskCommand.getId(), getRootCommandId(history.next()));
    assertEquals(createCommand.getId(), getRootCommandId(history.next()));
    assertFalse(history.hasNext());
}
Also used : AggregateTestEnv.newTenantId(io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId) TenantId(io.spine.core.TenantId) Command(io.spine.core.Command) AggregateMessageDispatcher.dispatchCommand(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand) TestAggregate(io.spine.server.aggregate.given.aggregate.TestAggregate) Ack(io.spine.core.Ack) Event(io.spine.core.Event) CommandBus(io.spine.server.commandbus.CommandBus) Test(org.junit.Test)

Example 2 with TestAggregate

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

the class AggregateShould method return_non_null_time_when_was_last_modified.

@Test
public void return_non_null_time_when_was_last_modified() {
    final Timestamp creationTime = new TestAggregate(ID).whenModified();
    assertNotNull(creationTime);
}
Also used : TestAggregate(io.spine.server.aggregate.given.aggregate.TestAggregate) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 3 with TestAggregate

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

the class AggregateShould method traverse_the_history_up_to_the_latest_snapshot.

@Test
public void traverse_the_history_up_to_the_latest_snapshot() {
    repository.setSnapshotTrigger(3);
    final TenantId tenantId = newTenantId();
    final Command createCommand = command(createProject, tenantId);
    final Command startCommand = command(startProject, tenantId);
    final Command addTaskCommand = command(addTask, tenantId);
    final Command addTaskCommand2 = command(addTask, tenantId);
    final CommandBus commandBus = boundedContext.getCommandBus();
    final StreamObserver<Ack> noOpObserver = noOpObserver();
    commandBus.post(createCommand, noOpObserver);
    commandBus.post(startCommand, noOpObserver);
    commandBus.post(newArrayList(addTaskCommand, addTaskCommand2), noOpObserver);
    final TestAggregate aggregate = repository.loadAggregate(tenantId, ID);
    final Iterator<Event> history = aggregate.historyBackward();
    assertEquals(addTaskCommand2.getId(), getRootCommandId(history.next()));
    assertFalse(history.hasNext());
}
Also used : AggregateTestEnv.newTenantId(io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId) TenantId(io.spine.core.TenantId) Command(io.spine.core.Command) AggregateMessageDispatcher.dispatchCommand(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand) TestAggregate(io.spine.server.aggregate.given.aggregate.TestAggregate) Ack(io.spine.core.Ack) Event(io.spine.core.Event) CommandBus(io.spine.server.commandbus.CommandBus) Test(org.junit.Test)

Example 4 with TestAggregate

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

the class AggregateShould method newAggregate.

private static TestAggregate newAggregate(ProjectId id) {
    final TestAggregate result = new TestAggregate(id);
    result.init();
    return result;
}
Also used : TestAggregate(io.spine.server.aggregate.given.aggregate.TestAggregate)

Aggregations

TestAggregate (io.spine.server.aggregate.given.aggregate.TestAggregate)4 Test (org.junit.Test)3 Ack (io.spine.core.Ack)2 Command (io.spine.core.Command)2 Event (io.spine.core.Event)2 TenantId (io.spine.core.TenantId)2 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)2 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)2 CommandBus (io.spine.server.commandbus.CommandBus)2 Timestamp (com.google.protobuf.Timestamp)1