use of io.spine.core.Command in project core-java by SpineEventEngine.
the class AggregateRepositoryViewsShould method postCommand.
/**
* Creates a command and posts it to {@code CommandBus}
* for being processed by the repository.
*/
private void postCommand(String cmd) {
final Command command = requestFactory.command().create(RepoOfAggregateWithLifecycle.createCommandMessage(id, cmd));
boundedContext.getCommandBus().post(command, StreamObservers.<Ack>noOpObserver());
}
use of io.spine.core.Command 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());
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class AggregateShould method create_single_event_for_a_pair_of_events_with_empty_for_a_command_dispatch.
/**
* Ensures that a {@linkplain io.spine.server.tuple.Pair pair} with an empty second
* optional value returned from a command handler stores a single event.
*
* <p>The command handler that should return a pair is
* {@link TaskAggregate#handle(AggAssignTask)
* TaskAggregate#handle(AggAssignTask)}.
*/
@Test
public void create_single_event_for_a_pair_of_events_with_empty_for_a_command_dispatch() {
final BoundedContext boundedContext = newTaskBoundedContext();
final TenantId tenantId = newTenantId();
final Command command = command(createTask(), tenantId);
final MemoizingObserver<Ack> observer = memoizingObserver();
boundedContext.getCommandBus().post(command, observer);
assertNull(observer.getError());
final List<Ack> responses = observer.responses();
assertSize(1, responses);
final Ack response = responses.get(0);
final io.spine.core.Status status = response.getStatus();
final Error emptyError = Error.getDefaultInstance();
assertEquals(emptyError, status.getError());
final Rejection emptyRejection = Rejection.getDefaultInstance();
assertEquals(emptyRejection, status.getRejection());
final List<Event> events = readAllEvents(boundedContext, tenantId);
assertSize(1, events);
}
use of io.spine.core.Command 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());
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class IdempotencyGuardShould method not_throw_if_the_command_was_not_handled.
@Test
public void not_throw_if_the_command_was_not_handled() {
final TenantId tenantId = newTenantId();
final ProjectId projectId = newProjectId();
final Command createCommand = command(createProject(projectId), tenantId);
final IgTestAggregate aggregate = new IgTestAggregate(projectId);
final IdempotencyGuard guard = new IdempotencyGuard(aggregate);
guard.check(of(createCommand));
}
Aggregations