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