Search in sources :

Example 11 with Command

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

the class EventBusShould method store_an_event.

@Test
public void store_an_event() {
    final Command command = command(createProject());
    eventBus.register(new EBProjectCreatedNoOpSubscriber());
    commandBus.post(command, StreamObservers.<Ack>noOpObserver());
    final List<Event> events = readEvents(eventBus);
    assertSize(1, 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 12 with Command

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

the class EventBusShould method store_multiple_messages_passing_filters.

/**
 * Ensures that events are stored when all 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 store_multiple_messages_passing_filters() {
    eventBus.register(new EBTaskAddedNoOpSubscriber());
    final Command command = command(addTasks(newTask(false), newTask(false), newTask(false)));
    commandBus.post(command, StreamObservers.<Ack>noOpObserver());
    final List<Event> storedEvents = readEvents(eventBus);
    assertSize(3, 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)

Example 13 with Command

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

the class EventBusShould method store_only_events_passing_filters.

/**
 * Ensures that events which pass filters and the ones that don’t are treated independently when
 * sent in batch.
 *
 * <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 store_only_events_passing_filters() {
    eventBus.register(new EBTaskAddedNoOpSubscriber());
    final Command command = command(addTasks(newTask(false), newTask(true), newTask(false), newTask(true), newTask(true)));
    commandBus.post(command, StreamObservers.<Ack>noOpObserver());
    final List<Event> storedEvents = readEvents(eventBus);
    assertSize(2, storedEvents);
    for (Event event : storedEvents) {
        final EBTaskAdded contents = unpack(event.getMessage());
        final Task task = contents.getTask();
        assertFalse(task.getDone());
    }
}
Also used : EBTaskAdded(io.spine.test.event.EBTaskAdded) EventBusTestEnv.newTask(io.spine.server.event.given.EventBusTestEnv.newTask) Task(io.spine.test.event.Task) Command(io.spine.core.Command) GivenEvent(io.spine.server.event.given.EventBusTestEnv.GivenEvent) Event(io.spine.core.Event) Test(org.junit.Test)

Example 14 with Command

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

the class EventBusShould method not_store_an_invalid_event.

@Test
public void not_store_an_invalid_event() {
    final Command command = command(invalidArchiveProject());
    eventBus.register(new EBProjectArchivedSubscriber());
    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 15 with Command

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

the class EventBusShould method store_a_dead_event.

@Test
public void store_a_dead_event() {
    final Command command = command(createProject());
    commandBus.post(command, StreamObservers.<Ack>noOpObserver());
    final List<Event> events = readEvents(eventBus);
    assertSize(1, 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)

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