use of io.spine.server.route.given.switchman.Log 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));
}
Aggregations