Search in sources :

Example 1 with Log

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));
}
Also used : Rejections(io.spine.server.route.given.switchman.rejection.Rejections) Message(com.google.protobuf.Message) Command(io.spine.core.Command) Log(io.spine.server.route.given.switchman.Log) LogState(io.spine.server.rout.given.switchman.LogState) ProcessingStatus(io.spine.server.commandbus.ProcessingStatus) Test(org.junit.Test)

Aggregations

Message (com.google.protobuf.Message)1 Command (io.spine.core.Command)1 ProcessingStatus (io.spine.server.commandbus.ProcessingStatus)1 LogState (io.spine.server.rout.given.switchman.LogState)1 Log (io.spine.server.route.given.switchman.Log)1 Rejections (io.spine.server.route.given.switchman.rejection.Rejections)1 Test (org.junit.Test)1