Search in sources :

Example 1 with PmStartProject

use of io.spine.test.procman.command.PmStartProject 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 PmStartProject

use of io.spine.test.procman.command.PmStartProject in project core-java by SpineEventEngine.

the class PmMessageDeliveryTestEnv method cannotStartProject.

public static Rejection cannotStartProject() {
    final ProjectId projectId = projectId();
    final PmStartProject cmdMessage = PmStartProject.newBuilder().setProjectId(projectId).build();
    final Command command = createCommand(cmdMessage);
    final Rejection result = toRejection(throwableWith(projectId), command);
    return result;
}
Also used : Rejections.toRejection(io.spine.core.Rejections.toRejection) Rejection(io.spine.core.Rejection) PmStartProject(io.spine.test.procman.command.PmStartProject) Command(io.spine.core.Command) ProjectId(io.spine.test.procman.ProjectId)

Aggregations

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