Search in sources :

Example 96 with Command

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_rejection_react.

/**
 * Ensures that a {@linkplain io.spine.server.tuple.Pair pair} with an empty second optional
 * value returned from a reaction on a rejection stores a single event.
 *
 * <p>The rejection is fired by the {@link TaskAggregate#handle(AggReassignTask)
 * TaskAggregate.handle(AggReassignTask)}
 * and handled by the {@link TaskAggregate#on(Rejections.AggCannotReassignUnassignedTask)
 * TaskAggregate.on(AggCannotReassignUnassignedTask)}.
 */
@Test
public void create_single_event_for_a_pair_of_events_with_empty_for_a_rejection_react() {
    final BoundedContext boundedContext = newTaskBoundedContext();
    final TenantId tenantId = newTenantId();
    final Command command = command(reassignTask(), 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);
    final Event reactionEvent = events.get(0);
    final TypeUrl userNotifiedType = TypeUrl.from(AggUserNotified.getDescriptor());
    assertEquals(typeUrlOf(reactionEvent), userNotifiedType);
}
Also used : Ack(io.spine.core.Ack) Error(io.spine.base.Error) TypeUrl(io.spine.type.TypeUrl) AggregateMessageDispatcher.dispatchRejection(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchRejection) Rejection(io.spine.core.Rejection) 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) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) AggregateTestEnv.newTaskBoundedContext(io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTaskBoundedContext) Test(org.junit.Test)

Example 97 with Command

use of io.spine.core.Command in project core-java by SpineEventEngine.

the class IdempotencyGuardShould method throw_DuplicateCommandException_when_the_command_was_handled_since_last_snapshot.

@Test(expected = DuplicateCommandException.class)
public void throw_DuplicateCommandException_when_the_command_was_handled_since_last_snapshot() {
    final TenantId tenantId = newTenantId();
    final ProjectId projectId = newProjectId();
    final Command createCommand = command(createProject(projectId), tenantId);
    final CommandBus commandBus = boundedContext.getCommandBus();
    final StreamObserver<Ack> noOpObserver = noOpObserver();
    commandBus.post(createCommand, noOpObserver);
    final IgTestAggregate aggregate = repository.loadAggregate(tenantId, projectId);
    final IdempotencyGuard guard = new IdempotencyGuard(aggregate);
    guard.check(of(createCommand));
}
Also used : IdempotencyGuardTestEnv.newTenantId(io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newTenantId) TenantId(io.spine.core.TenantId) Command(io.spine.core.Command) IgTestAggregate(io.spine.server.aggregate.given.aggregate.IgTestAggregate) IdempotencyGuardTestEnv.newProjectId(io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newProjectId) ProjectId(io.spine.test.aggregate.ProjectId) Ack(io.spine.core.Ack) CommandBus(io.spine.server.commandbus.CommandBus) Test(org.junit.Test)

Example 98 with Command

use of io.spine.core.Command in project core-java by SpineEventEngine.

the class AggregateMessageDeliveryTestEnv method cannotStartProject.

public static Rejection cannotStartProject() {
    final ProjectId projectId = projectId();
    final AggStartProject cmdMessage = AggStartProject.newBuilder().setProjectId(projectId).build();
    final Command command = createCommand(cmdMessage);
    final Rejection result = Rejections.toRejection(new io.spine.test.aggregate.rejection.AggCannotStartArchivedProject(projectId, Lists.<ProjectId>newArrayList()), command);
    return result;
}
Also used : Rejection(io.spine.core.Rejection) Command(io.spine.core.Command) ProjectId(io.spine.test.aggregate.ProjectId) AggStartProject(io.spine.test.aggregate.command.AggStartProject)

Example 99 with Command

use of io.spine.core.Command in project core-java by SpineEventEngine.

the class EventBusShould method not_store_an_invalid_dead_event.

@Test
public void not_store_an_invalid_dead_event() {
    final Command command = command(invalidArchiveProject());
    commandBus.post(command, StreamObservers.<Ack>noOpObserver());
    final List<Event> events = readEvents(eventBus);
    assertSize(0, events);
}
Also used : Command(io.spine.core.Command) GivenEvent(io.spine.server.event.given.EventBusTestEnv.GivenEvent) Event(io.spine.core.Event) Test(org.junit.Test)

Example 100 with Command

use of io.spine.core.Command in project core-java by SpineEventEngine.

the class EventBusShould method not_store_any_events_when_they_are_failing_filtering.

/**
 * Ensures that events are not stored when none of them pass the filters.
 *
 * <p> To filter the {@link EBTaskAdded} events the {@linkplain EventBus} has a custom filter.
 * The {@link TaskCreatedFilter} filters out {@link EBTaskAdded} events with
 * {@link Task#getDone()} set to {@code true}.
 *
 * <p> The {@link EBTaskAddedNoOpSubscriber} is registered so that the event would not get
 * filtered out by the {@link io.spine.server.bus.DeadMessageFilter}.
 */
@Test
public void not_store_any_events_when_they_are_failing_filtering() {
    eventBus.register(new EBTaskAddedNoOpSubscriber());
    final Command command = command(addTasks(newTask(true), newTask(true), newTask(true)));
    commandBus.post(command, StreamObservers.<Ack>noOpObserver());
    final List<Event> storedEvents = readEvents(eventBus);
    assertSize(0, storedEvents);
}
Also used : Command(io.spine.core.Command) GivenEvent(io.spine.server.event.given.EventBusTestEnv.GivenEvent) Event(io.spine.core.Event) Test(org.junit.Test)

Aggregations

Command (io.spine.core.Command)137 Test (org.junit.Test)87 Event (io.spine.core.Event)19 TenantId (io.spine.core.TenantId)17 Ack (io.spine.core.Ack)15 Message (com.google.protobuf.Message)14 Rejection (io.spine.core.Rejection)13 CommandEnvelope (io.spine.core.CommandEnvelope)11 Timestamp (com.google.protobuf.Timestamp)9 Error (io.spine.base.Error)9 CommandContext (io.spine.core.CommandContext)9 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)8 CommandRecord (io.spine.server.commandbus.CommandRecord)8 ProjectId (io.spine.test.aggregate.ProjectId)8 CommandBus (io.spine.server.commandbus.CommandBus)7 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)7 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)7 Any (com.google.protobuf.Any)6 CommandId (io.spine.core.CommandId)6 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)6