Search in sources :

Example 71 with Command

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));
}
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)

Example 72 with Command

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());
}
Also used : Message(com.google.protobuf.Message) Command(io.spine.core.Command) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 73 with Command

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());
}
Also used : Command(io.spine.core.Command) StringValue(com.google.protobuf.StringValue) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 74 with Command

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());
}
Also used : Command(io.spine.core.Command) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 75 with Command

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);
}
Also used : Command(io.spine.core.Command) Test(org.junit.Test)

Aggregations

Command (io.spine.core.Command)137 Test (org.junit.Test)87 Event (io.spine.core.Event)19 TenantId (io.spine.core.TenantId)17 Ack (io.spine.core.Ack)15 Message (com.google.protobuf.Message)14 Rejection (io.spine.core.Rejection)13 CommandEnvelope (io.spine.core.CommandEnvelope)11 Timestamp (com.google.protobuf.Timestamp)9 Error (io.spine.base.Error)9 CommandContext (io.spine.core.CommandContext)9 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)8 CommandRecord (io.spine.server.commandbus.CommandRecord)8 ProjectId (io.spine.test.aggregate.ProjectId)8 CommandBus (io.spine.server.commandbus.CommandBus)7 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)7 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)7 Any (com.google.protobuf.Any)6 CommandId (io.spine.core.CommandId)6 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)6