use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandRoutingRejectionShould method result_in_rejected_command.
/**
* Verifies that a command rejected during routing gets rejected status.
*
* <p>The test initially posts a command which should be processed correctly. This is done to
* ensure that basic processing works.
*
* <p>Then the test posts a command with the argument that should cause rejection in the
* routing function.
*/
@Test
public void result_in_rejected_command() {
// Post a successful command to make sure general case works.
final String switchmanName = Switchman.class.getName();
final Command command = requestFactory.createCommand(SetSwitch.newBuilder().setSwitchId(generateSwitchId()).setSwitchmanName(switchmanName).setPosition(SwitchPosition.RIGHT).build());
commandBus.post(command, observer);
assertEquals(CommandStatus.OK, commandStore.getStatus(command).getCode());
// Post a command with the argument which causes rejection in routing.
final Command commandToReject = requestFactory.createCommand(SetSwitch.newBuilder().setSwitchmanName(SwitchmanBureau.MISSING_SWITCHMAN_NAME).setSwitchId(generateSwitchId()).setPosition(SwitchPosition.LEFT).build());
commandBus.post(commandToReject, observer);
final ProcessingStatus status = commandStore.getStatus(commandToReject);
// Check that the command is rejected.
assertEquals(CommandStatus.REJECTED, status.getCode());
final Message rejectionMessage = AnyPacker.unpack(status.getRejection().getMessage());
assertTrue(rejectionMessage instanceof Rejections.SwitchmanUnavailable);
// Check that the event and the rejection were dispatched.
final Optional<Log> optional = logRepository.find(Log.ID);
assertTrue(optional.isPresent());
final LogState log = optional.get().getState();
assertTrue(log.containsCounters(switchmanName));
assertTrue(log.getMissingSwitchmanList().contains(SwitchmanBureau.MISSING_SWITCHMAN_NAME));
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandTestShould method create_different_command_with_timestamp.
@Test
public void create_different_command_with_timestamp() {
final Message anotherCommandMsg = Time.getCurrentTime();
final Timestamp timestamp = TimeTests.Past.minutesAgo(30);
final Command anotherCommand = commandTest.createDifferentCommand(anotherCommandMsg, timestamp);
assertEquals(anotherCommandMsg, Commands.getMessage(anotherCommand));
assertEquals(timestamp, anotherCommand.getContext().getActorContext().getTimestamp());
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandTestShould method create_command_with_custom_Timestamp.
@Test
public void create_command_with_custom_Timestamp() {
final StringValue commandMessage = newUuidValue();
final Timestamp timestamp = TimeTests.Past.minutesAgo(5);
final Command command = commandTest.createCommand(commandMessage, timestamp);
assertEquals(timestamp, command.getContext().getActorContext().getTimestamp());
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandTestShould method stores_command_after_creation.
// This test verifies that Optionals
@SuppressWarnings("OptionalGetWithoutIsPresent")
// are initialized.
@Test
public void stores_command_after_creation() {
final StringValue commandMessage = newUuidValue();
final Command command = commandTest.createCommand(commandMessage);
assertEquals(commandMessage, commandTest.commandMessage().get());
assertEquals(command.getContext(), commandTest.commandContext().get());
assertEquals(command, commandTest.command().get());
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandSchedulingShould method schedule_command_if_delay_is_set.
@Test
public void schedule_command_if_delay_is_set() {
commandBus.register(createProjectHandler);
final Command cmd = createProject(/*delay=*/
minutes(1));
commandBus.post(cmd, observer);
verify(scheduler).schedule(cmd);
}
Aggregations