Search in sources :

Example 81 with Event

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

the class AggregateMessageDeliveryTestEnv method projectStarted.

public static Event projectStarted() {
    final ProjectId projectId = projectId();
    final TestEventFactory eventFactory = TestEventFactory.newInstance(pack(projectId), AggregateMessageDeliveryTestEnv.class);
    final AggProjectStarted msg = AggProjectStarted.newBuilder().setProjectId(projectId).build();
    final Event result = eventFactory.createEvent(msg);
    return result;
}
Also used : TestEventFactory(io.spine.server.command.TestEventFactory) ProjectId(io.spine.test.aggregate.ProjectId) Event(io.spine.core.Event) AggProjectStarted(io.spine.test.aggregate.event.AggProjectStarted)

Example 82 with Event

use of io.spine.core.Event 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 83 with Event

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

the class EventBusShould method not_call_dispatchers_if_dispatcher_event_execution_postponed.

@Test
public void not_call_dispatchers_if_dispatcher_event_execution_postponed() {
    final BareDispatcher dispatcher = new BareDispatcher();
    eventBusWithPosponedExecution.register(dispatcher);
    final Event event = GivenEvent.projectCreated();
    eventBusWithPosponedExecution.post(event);
    assertFalse(dispatcher.isDispatchCalled());
    final boolean eventPostponed = postponedDispatcherDelivery.isPostponed(event, dispatcher);
    assertTrue(eventPostponed);
}
Also used : GivenEvent(io.spine.server.event.given.EventBusTestEnv.GivenEvent) Event(io.spine.core.Event) Test(org.junit.Test)

Example 84 with Event

use of io.spine.core.Event 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)

Example 85 with Event

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

the class EventBusShould method call_subscriber_when_event_posted.

@Test
public void call_subscriber_when_event_posted() {
    final ProjectCreatedSubscriber subscriber = new ProjectCreatedSubscriber();
    final Event event = GivenEvent.projectCreated();
    eventBus.register(subscriber);
    eventBus.post(event);
    // Exclude event ID from comparison.
    assertEquals(Events.getMessage(event), subscriber.getEventMessage());
    assertEquals(event.getContext(), subscriber.getEventContext());
}
Also used : GivenEvent(io.spine.server.event.given.EventBusTestEnv.GivenEvent) Event(io.spine.core.Event) Test(org.junit.Test)

Aggregations

Event (io.spine.core.Event)115 Test (org.junit.Test)75 Command (io.spine.core.Command)19 EventContext (io.spine.core.EventContext)12 BoundedContext (io.spine.server.BoundedContext)12 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)12 Version (io.spine.core.Version)10 TestEventFactory (io.spine.server.command.TestEventFactory)10 Message (com.google.protobuf.Message)9 EventEnvelope (io.spine.core.EventEnvelope)9 InMemoryTransportFactory (io.spine.server.integration.memory.InMemoryTransportFactory)9 Timestamp (com.google.protobuf.Timestamp)6 Ack (io.spine.core.Ack)6 TenantId (io.spine.core.TenantId)6 Error (io.spine.base.Error)5 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)5 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)5 StringValue (com.google.protobuf.StringValue)4 GivenEvent (io.spine.core.given.GivenEvent)4 Duration (com.google.protobuf.Duration)3