use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandStoreShould method set_command_status_to_OK_when_handler_returns.
@Test
public void set_command_status_to_OK_when_handler_returns() {
commandBus.register(createProjectHandler);
final Command command = requestFactory.command().create(createProjectMessage());
commandBus.post(command, observer);
final TenantId tenantId = command.getContext().getActorContext().getTenantId();
final CommandId commandId = command.getId();
final ProcessingStatus status = getStatus(commandId, tenantId);
assertEquals(CommandStatus.OK, status.getCode());
}
use of io.spine.core.Command 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.Command in project core-java by SpineEventEngine.
the class CommandValidatorViolationCheckShould method validate_command_and_return_violations_if_message_is_NOT_valid.
@Test
public void validate_command_and_return_violations_if_message_is_NOT_valid() {
final Any invalidMessagePacked = AnyPacker.pack(CmdCreateProject.getDefaultInstance());
final Command commandWithEmptyMessage = Command.newBuilder().setId(generateId()).setMessage(invalidMessagePacked).setContext(withRandomActor()).build();
final List<ConstraintViolation> violations = inspect(CommandEnvelope.of(commandWithEmptyMessage));
assertEquals(3, violations.size());
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class ExecutorCommandSchedulerShould method schedule_command_if_delay_is_set.
@Test
public void schedule_command_if_delay_is_set() {
final Command cmdPrimary = commandFactory.createBasedOnContext(createProjectMessage(), context);
final ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
scheduler.schedule(cmdPrimary);
verify(scheduler, never()).post(any(Command.class));
verify(scheduler, timeout(DELAY_MS + WAIT_FOR_PROPAGATION_MS)).post(commandCaptor.capture());
final Command actualCmd = commandCaptor.getValue();
final Command expectedCmd = CommandScheduler.setSchedulingTime(cmdPrimary, getSchedulingTime(actualCmd));
assertEquals(expectedCmd, actualCmd);
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class MultiTenantCommandBusShould method verify_tenant_id_attribute_if_multitenant.
/*
* Command validation tests.
***************************/
@Test
public void verify_tenant_id_attribute_if_multitenant() {
commandBus.register(createProjectHandler);
final Command cmd = newCommandWithoutTenantId();
commandBus.post(cmd, observer);
checkCommandError(observer.firstResponse(), TENANT_UNKNOWN, InvalidCommandException.class, cmd);
}
Aggregations