Search in sources :

Example 26 with Event

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

the class ProcessManagerRepositoryShould method testDispatchEvent.

private void testDispatchEvent(Message eventMessage) {
    final CommandContext commandContext = requestFactory.createCommandContext();
    // EventContext should have CommandContext with appropriate TenantId to avoid usage
    // of different storages during command and event dispatching.
    final EventContext eventContextWithTenantId = GivenEvent.context().toBuilder().setCommandContext(commandContext).build();
    final Event event = GivenEvent.withMessage(eventMessage).toBuilder().setContext(eventContextWithTenantId).build();
    repository().dispatch(EventEnvelope.of(event));
    assertTrue(TestProcessManager.processed(eventMessage));
}
Also used : EventContext(io.spine.core.EventContext) CommandContext(io.spine.core.CommandContext) GivenEvent(io.spine.core.given.GivenEvent) Event(io.spine.core.Event)

Example 27 with Event

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

the class ProcessManagerShould method testDispatchCommand.

private List<Event> testDispatchCommand(Message commandMsg) {
    final CommandEnvelope envelope = CommandEnvelope.of(requestFactory.command().create(commandMsg));
    final List<Event> events = dispatch(processManager, envelope);
    assertEquals(pack(commandMsg), processManager.getState());
    return events;
}
Also used : CommandEnvelope(io.spine.core.CommandEnvelope) Event(io.spine.core.Event)

Example 28 with Event

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

the class ProcessManagerShould method dispatch_command_and_return_events.

@Test
public void dispatch_command_and_return_events() {
    final List<Event> events = testDispatchCommand(createProject());
    assertEquals(1, events.size());
    final Event event = events.get(0);
    assertNotNull(event);
    final PmProjectCreated message = unpack(event.getMessage());
    assertEquals(ID, message.getProjectId());
}
Also used : Event(io.spine.core.Event) PmProjectCreated(io.spine.test.procman.event.PmProjectCreated) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 29 with Event

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

the class ProcessManagerShould method route_commands.

/**
 * Tests command routing.
 *
 * @see TestProcessManager#handle(PmStartProject, CommandContext)
 */
@Test
public void route_commands() {
    // Add dispatcher for the routed command. Otherwise the command would reject the command.
    final AddTaskDispatcher dispatcher = new AddTaskDispatcher();
    commandBus.register(dispatcher);
    processManager.injectCommandBus(commandBus);
    final List<Event> events = testDispatchCommand(startProject());
    // There's only one event generated.
    assertEquals(1, events.size());
    final Event event = events.get(0);
    // The producer of the event is our Process Manager.
    assertEquals(processManager.getId(), Events.getProducer(event.getContext()));
    final Message message = AnyPacker.unpack(event.getMessage());
    // The event type is CommandRouted.
    assertThat(message, instanceOf(CommandRouted.class));
    final CommandRouted commandRouted = (CommandRouted) message;
    // The source of the command is StartProject.
    assertThat(getMessage(commandRouted.getSource()), instanceOf(PmStartProject.class));
    final List<CommandEnvelope> dispatchedCommands = dispatcher.getCommands();
    assertSize(1, dispatchedCommands);
    final CommandEnvelope dispatchedCommand = dispatcher.getCommands().get(0);
    assertEquals(commandRouted.getProduced(0), dispatchedCommand.getCommand());
}
Also used : AddTaskDispatcher(io.spine.server.procman.given.ProcessManagerTestEnv.AddTaskDispatcher) TypeConverter.toMessage(io.spine.protobuf.TypeConverter.toMessage) Commands.getMessage(io.spine.core.Commands.getMessage) Message(com.google.protobuf.Message) PmStartProject(io.spine.test.procman.command.PmStartProject) Event(io.spine.core.Event) CommandEnvelope(io.spine.core.CommandEnvelope) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 30 with Event

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

the class ProcessManagerShould method testDispatchEvent.

private List<? extends Message> testDispatchEvent(Message eventMessage) {
    final Event event = eventFactory.createEvent(eventMessage);
    final List<Event> result = dispatch(processManager, EventEnvelope.of(event));
    assertEquals(pack(eventMessage), processManager.getState());
    return result;
}
Also used : Event(io.spine.core.Event)

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