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());
}
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());
}
Aggregations