use of io.spine.core.CommandId in project core-java by SpineEventEngine.
the class CommandStore method getStatus.
/**
* Obtains the processing status for the passed command.
*/
public ProcessingStatus getStatus(Command command) {
final TenantId tenantId = Commands.getTenantId(command);
final TenantAwareFunction<CommandId, ProcessingStatus> func = new TenantAwareFunction<CommandId, ProcessingStatus>(tenantId) {
@Nullable
@Override
public ProcessingStatus apply(@Nullable CommandId commandId) {
checkNotNull(commandId);
return getStatus(commandId);
}
};
return func.execute(command.getId());
}
use of io.spine.core.CommandId in project core-java by SpineEventEngine.
the class CommandTestUtil method checkRecord.
static void checkRecord(CommandRecord record, Command cmd, CommandStatus statusExpected) {
final CommandContext context = cmd.getContext();
final CommandId commandId = cmd.getId();
final CmdCreateProject message = unpack(cmd.getMessage());
assertEquals(cmd.getMessage(), record.getCommand().getMessage());
assertTrue(record.getTimestamp().getSeconds() > 0);
assertEquals(message.getClass().getSimpleName(), record.getCommandType());
assertEquals(commandId, record.getCommandId());
assertEquals(statusExpected, record.getStatus().getCode());
assertEquals(context, record.getCommand().getContext());
switch(statusExpected) {
case RECEIVED:
case OK:
case SCHEDULED:
assertTrue(isDefault(record.getStatus().getError()));
assertTrue(isDefault(record.getStatus().getRejection()));
break;
case ERROR:
assertTrue(isNotDefault(record.getStatus().getError()));
break;
case REJECTED:
assertTrue(isNotDefault(record.getStatus().getRejection()));
break;
case UNDEFINED:
case UNRECOGNIZED:
break;
}
}
use of io.spine.core.CommandId in project core-java by SpineEventEngine.
the class StorageShould method store_command_with_error.
// We get right after we store.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void store_command_with_error() {
final Command command = Given.ACommand.createProject();
final CommandId commandId = command.getId();
final Error error = newError();
repository.store(command, error);
final CommandRecord record = read(commandId).get();
checkRecord(record, command, ERROR);
assertEquals(error, record.getStatus().getError());
}
use of io.spine.core.CommandId in project core-java by SpineEventEngine.
the class AbstractCommandBusTestSuite method checkResult.
protected void checkResult(Command cmd) {
assertNull(observer.getError());
assertTrue(observer.isCompleted());
final CommandId commandId = unpack(observer.firstResponse().getMessageId());
assertEquals(cmd.getId(), commandId);
}
use of io.spine.core.CommandId in project core-java by SpineEventEngine.
the class CommandStoreShould method set_command_status_to_rejection_when_handler_throws_rejection.
@Test
public void set_command_status_to_rejection_when_handler_throws_rejection() {
ModelTests.clearModel();
final TestRejection rejection = new TestRejection();
final Command command = givenThrowingHandler(rejection);
final CommandId commandId = command.getId();
final Message commandMessage = getMessage(command);
commandBus.post(command, observer);
// Check that the logging was called.
verify(log).rejectedWith(eq(rejection), eq(commandMessage), eq(commandId));
// Check that the status has the correct code,
// and the rejection matches the thrown rejection.
final TenantId tenantId = command.getContext().getActorContext().getTenantId();
final ProcessingStatus status = getStatus(commandId, tenantId);
assertEquals(CommandStatus.REJECTED, status.getCode());
assertEquals(toRejection(rejection, command).getMessage(), status.getRejection().getMessage());
}
Aggregations