use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class ProcessManagerRepositoryShould method throw_exception_if_dispatch_unknown_command.
@Test(expected = IllegalArgumentException.class)
public void throw_exception_if_dispatch_unknown_command() {
final Command unknownCommand = requestFactory.createCommand(Int32Value.getDefaultInstance());
final CommandEnvelope request = CommandEnvelope.of(unknownCommand);
repository().dispatchCommand(request);
}
use of io.spine.core.CommandEnvelope 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.CommandEnvelope 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.CommandEnvelope in project core-java by SpineEventEngine.
the class CommandStoreShould method set_command_status_to_error_when_handler_throws_exception.
@Test
public void set_command_status_to_error_when_handler_throws_exception() {
ModelTests.clearModel();
final RuntimeException exception = new IllegalStateException("handler throws");
final Command command = givenThrowingHandler(exception);
final CommandEnvelope envelope = CommandEnvelope.of(command);
commandBus.post(command, observer);
// Check that the logging was called.
verify(log).errorHandling(eq(exception), eq(envelope.getMessage()), eq(envelope.getId()));
final String errorMessage = exception.getMessage();
assertHasErrorStatusWithMessage(envelope, errorMessage);
}
use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class CommandStoreShould method set_command_status_to_error_when_dispatcher_throws.
@Test
public void set_command_status_to_error_when_dispatcher_throws() {
final ThrowingDispatcher dispatcher = new ThrowingDispatcher();
commandBus.register(dispatcher);
final Command command = requestFactory.command().create(createProjectMessage());
commandBus.post(command, observer);
// Check that the logging was called.
final CommandEnvelope envelope = CommandEnvelope.of(command);
verify(log).errorHandling(dispatcher.exception, envelope.getMessage(), envelope.getId());
// Check that the command status has the correct code,
// and the error matches the thrown exception.
assertHasErrorStatusWithMessage(envelope, dispatcher.exception.getMessage());
}
Aggregations