use of io.spine.envelope.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() {
final RuntimeException exception = new IllegalStateException("handler throws");
final Command command = givenThrowingHandler(exception);
final CommandEnvelope envelope = CommandEnvelope.of(command);
commandBus.post(command, responseObserver);
// Check that the logging was called.
verify(log).errorHandling(eq(exception), eq(envelope.getMessage()), eq(envelope.getCommandId()));
final String errorMessage = exception.getMessage();
assertHasErrorStatusWithMessage(envelope, errorMessage);
}
use of io.spine.envelope.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, responseObserver);
// Check that the logging was called.
final CommandEnvelope envelope = CommandEnvelope.of(command);
verify(log).errorHandling(dispatcher.exception, envelope.getMessage(), envelope.getCommandId());
// Check that the command status has the correct code,
// and the error matches the thrown exception.
assertHasErrorStatusWithMessage(envelope, dispatcher.exception.getMessage());
}
use of io.spine.envelope.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() throws InvocationTargetException {
final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(getClass());
final Command unknownCommand = factory.createCommand(Int32Value.getDefaultInstance());
final CommandEnvelope request = CommandEnvelope.of(unknownCommand);
repository.dispatchCommand(request);
}
use of io.spine.envelope.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 ProcManTransaction<?, ?, ?> tx = start(processManager);
final List<Event> events = processManager.dispatchCommand(envelope);
tx.commit();
assertEquals(AnyPacker.pack(commandMsg), processManager.getState());
return events;
}
use of io.spine.envelope.CommandEnvelope in project core-java by SpineEventEngine.
the class AbstractCommandRouterShould method setUp.
@Before
public void setUp() {
final BoundedContext boundedContext = BoundedContext.newBuilder().build();
final CommandBus commandBus = boundedContext.getCommandBus();
// Register dispatcher for `StringValue` message type.
// Otherwise we won't be able to post.
commandBus.register(new CommandDispatcher() {
@Override
public Set<CommandClass> getMessageClasses() {
return CommandClass.setOf(StringValue.class);
}
@Override
public void dispatch(CommandEnvelope envelope) {
// Do nothing.
}
});
sourceMessage = Wrapper.forString(getClass().getSimpleName());
sourceContext = requestFactory.createCommandContext();
router = createRouter(commandBus, sourceMessage, sourceContext);
router.addAll(messages);
}
Aggregations