Search in sources :

Example 1 with Task

use of io.spine.test.event.Task 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 2 with Task

use of io.spine.test.event.Task in project core-java by SpineEventEngine.

the class EventBusTestEnv method addTasks.

public static EBAddTasks addTasks(Task... tasks) {
    final EBAddTasks.Builder builder = ((EBAddTasks.Builder) Sample.builderForType(EBAddTasks.class)).setProjectId(PROJECT_ID).clearTask();
    for (Task task : tasks) {
        builder.addTask(task);
    }
    final EBAddTasks command = builder.build();
    return command;
}
Also used : Task(io.spine.test.event.Task) EBAddTasks(io.spine.test.event.command.EBAddTasks)

Example 3 with Task

use of io.spine.test.event.Task in project core-java by SpineEventEngine.

the class EventRootCommandIdTestEnv method addTasks.

public static EvAddTasks addTasks(ProjectId id, int count) {
    checkNotNull(id);
    final EvAddTasks.Builder builder = EvAddTasks.newBuilder();
    for (int i = 0; i < count; i++) {
        final Task task = (Task) Sample.builderForType(Task.class).build();
        builder.addTask(task);
    }
    return builder.setProjectId(id).build();
}
Also used : Task(io.spine.test.event.Task) EvAddTasks(io.spine.test.event.command.EvAddTasks)

Aggregations

Task (io.spine.test.event.Task)3 Command (io.spine.core.Command)1 Event (io.spine.core.Event)1 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)1 EventBusTestEnv.newTask (io.spine.server.event.given.EventBusTestEnv.newTask)1 EBTaskAdded (io.spine.test.event.EBTaskAdded)1 EBAddTasks (io.spine.test.event.command.EBAddTasks)1 EvAddTasks (io.spine.test.event.command.EvAddTasks)1 Test (org.junit.Test)1