use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class StandPostShould method aggregateRepositoryDispatch.
private static BoundedContextAction aggregateRepositoryDispatch() {
return new BoundedContextAction() {
@Override
public void perform(BoundedContext context) {
// Init repository
final AggregateRepository<?, ?> repository = Given.aggregateRepo();
repository.initStorage(storageFactory(context.isMultitenant()));
try {
// Mock aggregate and mock stand are not able to handle events
// returned after command handling.
// This causes IllegalStateException to be thrown.
// Note that this is not the end of a test case,
// so we can't just "expect=IllegalStateException".
final CommandEnvelope cmd = CommandEnvelope.of(Given.validCommand());
repository.dispatch(cmd);
} catch (IllegalStateException e) {
// Proceed crash if it's not.
if (!e.getMessage().contains("No record found for command ID: EMPTY")) {
throw e;
}
}
}
};
}
use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class AggregateMessageDispatcherShould method dispatch_command.
@Test
public void dispatch_command() {
final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(getClass());
final int messageValue = 2017_07_28;
final UInt32Value message = UInt32Value.newBuilder().setValue(messageValue).build();
final CommandEnvelope commandEnvelope = CommandEnvelope.of(factory.createCommand(message));
final List<? extends Message> eventMessages = dispatchCommand(aggregate, commandEnvelope);
assertTrue(aggregate.getState().getValue().contains(String.valueOf(messageValue)));
assertEquals(1, eventMessages.size());
assertTrue(eventMessages.get(0) instanceof StringValue);
}
use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class CommandStoreShould method set_command_status_to_error_when_handler_throws_unknown_Throwable.
@Test
public void set_command_status_to_error_when_handler_throws_unknown_Throwable() throws TestRejection, TestThrowable {
ModelTests.clearModel();
final Throwable throwable = new TestThrowable("Unexpected Throwable");
final Command command = givenThrowingHandler(throwable);
final CommandEnvelope envelope = CommandEnvelope.of(command);
commandBus.post(command, observer);
// Check that the logging was called.
verify(log).errorHandlingUnknown(eq(throwable), eq(envelope.getMessage()), eq(envelope.getId()));
// Check that the status and message.
assertHasErrorStatusWithMessage(envelope, throwable.getMessage());
}
use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class CommandStoreShould method set_expired_scheduled_command_status_to_error_if_time_to_post_them_passed.
@Test
public void set_expired_scheduled_command_status_to_error_if_time_to_post_them_passed() {
final List<Command> commands = newArrayList(createProject(), addTask(), startProject());
final Duration delay = fromMinutes(5);
// time to post passed
final Timestamp schedulingTime = TimeTests.Past.minutesAgo(10);
storeAsScheduled(commands, delay, schedulingTime);
commandBus.rescheduleCommands();
for (Command cmd : commands) {
final CommandEnvelope envelope = CommandEnvelope.of(cmd);
final Message msg = envelope.getMessage();
final CommandId id = envelope.getId();
// Check the expired status error was set.
final ProcessingStatus status = getProcessingStatus(envelope);
// Check that the logging was called.
verify(log).errorExpiredCommand(msg, id);
final Error expected = CommandExpiredException.commandExpired(cmd);
assertEquals(expected, status.getError());
}
}
use of io.spine.core.CommandEnvelope in project core-java by SpineEventEngine.
the class CommandEnvelopeShould method obtain_actor_context.
@Test
public void obtain_actor_context() {
final Command command = outerObject();
final CommandEnvelope envelope = toEnvelope(command);
assertEquals(command.getContext().getActorContext(), envelope.getActorContext());
}
Aggregations