Search in sources :

Example 1 with AddTaskDispatcher

use of io.spine.server.procman.given.ProcessManagerTestEnv.AddTaskDispatcher 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 2 with AddTaskDispatcher

use of io.spine.server.procman.given.ProcessManagerTestEnv.AddTaskDispatcher in project core-java by SpineEventEngine.

the class ProcessManagerShould method dispatch_several_commands.

@Test
public void dispatch_several_commands() {
    commandBus.register(new AddTaskDispatcher());
    processManager.injectCommandBus(commandBus);
    testDispatchCommand(createProject());
    testDispatchCommand(addTask());
    testDispatchCommand(startProject());
}
Also used : AddTaskDispatcher(io.spine.server.procman.given.ProcessManagerTestEnv.AddTaskDispatcher) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Aggregations

AddTaskDispatcher (io.spine.server.procman.given.ProcessManagerTestEnv.AddTaskDispatcher)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 Test (org.junit.Test)2 Message (com.google.protobuf.Message)1 CommandEnvelope (io.spine.core.CommandEnvelope)1 Commands.getMessage (io.spine.core.Commands.getMessage)1 Event (io.spine.core.Event)1 TypeConverter.toMessage (io.spine.protobuf.TypeConverter.toMessage)1 PmStartProject (io.spine.test.procman.command.PmStartProject)1