use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class CommandHandlerMethodShould method set_producer_ID_if_entity.
@Test
public void set_producer_ID_if_entity() {
final RefCreateProject commandMessage = createProject();
final Aggregate<ProjectId, ?, ?> entity = new RejectingAggregate(commandMessage.getProjectId());
final CommandEnvelope cmd = requestFactory.createEnvelope(commandMessage);
try {
AggregateMessageDispatcher.dispatchCommand(entity, cmd);
} catch (HandlerMethodFailedException e) {
assertCauseAndId(e, entity.getId());
}
}
use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class CommandHandlerMethodShould method set_producer_ID_if_command_handler.
@Test
public void set_producer_ID_if_command_handler() {
final CommandHandler handler = new RejectingHandler();
final CommandEnvelope envelope = requestFactory.createEnvelope(createProject());
try {
handler.dispatch(envelope);
} catch (HandlerMethodFailedException e) {
assertCauseAndId(e, handler.getId());
}
}
use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class CommandHandlerMethodShould method throw_ISE_for_not_handled_command_type.
@Test(expected = IllegalStateException.class)
public void throw_ISE_for_not_handled_command_type() {
final CommandHandler handler = new ValidHandlerOneParam();
final CommandEnvelope cmd = requestFactory.createEnvelope(startProject());
handler.dispatch(cmd);
}
use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class AbstractCommandBusTestSuite method post_commands_in_bulk.
@Test
public void post_commands_in_bulk() {
final Command first = newCommand();
final Command second = newCommand();
final List<Command> commands = newArrayList(first, second);
// Some derived test suite classes may register the handler in setUp().
// This prevents the repeating registration (which is an illegal operation).
commandBus.unregister(createProjectHandler);
commandBus.register(createProjectHandler);
final CommandBus spy = spy(commandBus);
spy.post(commands, StreamObservers.<Ack>memoizingObserver());
@SuppressWarnings("unchecked") final ArgumentCaptor<Iterable<Command>> storingCaptor = forClass(Iterable.class);
verify(spy).store(storingCaptor.capture());
final Iterable<Command> storingArgs = storingCaptor.getValue();
assertSize(commands.size(), storingArgs);
assertContainsAll(storingArgs, first, second);
final ArgumentCaptor<CommandEnvelope> postingCaptor = forClass(CommandEnvelope.class);
verify(spy, times(2)).doPost(postingCaptor.capture());
final List<CommandEnvelope> postingArgs = postingCaptor.getAllValues();
assertSize(commands.size(), postingArgs);
assertEquals(commands.get(0), postingArgs.get(0).getCommand());
assertEquals(commands.get(1), postingArgs.get(1).getCommand());
commandBus.unregister(createProjectHandler);
}
use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class CommandHandlerShould method log_errors.
@Test
public void log_errors() {
final CommandEnvelope commandEnvelope = givenCommandEnvelope();
// Since we're in the tests mode `Environment` returns `SubstituteLogger` instance.
final SubstituteLogger log = (SubstituteLogger) handler.log();
// Restrict the queue size only to the number of calls we want to make.
final Queue<SubstituteLoggingEvent> queue = Queues.newArrayBlockingQueue(1);
log.setDelegate(new EventRecodingLogger(log, queue));
SubstituteLoggingEvent loggingEvent;
final RuntimeException exception = new RuntimeException("log_errors");
handler.onError(commandEnvelope, exception);
loggingEvent = queue.poll();
assertEquals(Level.ERROR, loggingEvent.getLevel());
assertEquals(commandEnvelope, handler.getLastErrorEnvelope());
assertEquals(exception, handler.getLastException());
}
Aggregations