Search in sources :

Example 1 with Command

use of io.spine.base.Command in project core-java by SpineEventEngine.

the class FailureSubscriber method dispatch.

@Override
public void dispatch(final FailureEnvelope envelope) {
    final Command originCommand = envelope.getOuterObject().getContext().getCommand();
    final CommandOperation op = new CommandOperation(originCommand) {

        @Override
        public void run() {
            handle(envelope.getMessage(), envelope.getCommandMessage(), envelope.getCommandContext());
        }
    };
    op.execute();
}
Also used : Command(io.spine.base.Command) CommandOperation(io.spine.server.tenant.CommandOperation)

Example 2 with Command

use of io.spine.base.Command in project core-java by SpineEventEngine.

the class TimeTests method adjustTimestamp.

/**
     * Adjusts a timestamp in the context of the passed command.
     *
     * @return new command instance with the modified timestamp
     */
public static Command adjustTimestamp(Command command, Timestamp timestamp) {
    final CommandContext context = command.getContext();
    final ActorContext.Builder withTime = context.getActorContext().toBuilder().setTimestamp(timestamp);
    final Command.Builder commandBuilder = command.toBuilder().setContext(context.toBuilder().setActorContext(withTime));
    return commandBuilder.build();
}
Also used : CommandContext(io.spine.base.CommandContext) Command(io.spine.base.Command) ActorContext(io.spine.base.ActorContext)

Example 3 with Command

use of io.spine.base.Command in project core-java by SpineEventEngine.

the class CommandTestShould method createAndAssertCommand.

/**
     * Creates a new command and checks its content.
     *
     * <p>If the method completes, we assume that the passed command test
     * has correctly working {@link ActorRequestFactory}.
     */
private static void createAndAssertCommand(CommandTest<StringValue> commandTest) {
    final StringValue commandMessage = newUuidValue();
    final Command command = commandTest.createCommand(commandMessage);
    checkNotDefault(command);
    assertEquals(commandMessage, Commands.getMessage(command));
    checkNotDefault(command.getContext());
}
Also used : Command(io.spine.base.Command) StringValue(com.google.protobuf.StringValue)

Example 4 with Command

use of io.spine.base.Command in project core-java by SpineEventEngine.

the class CommandTestShould method create_different_command.

@Test
public void create_different_command() {
    final Message anotherCommandMsg = Time.getCurrentTime();
    final Command anotherCommand = commandTest.createDifferentCommand(anotherCommandMsg);
    assertEquals(anotherCommandMsg, Commands.getMessage(anotherCommand));
}
Also used : Message(com.google.protobuf.Message) Command(io.spine.base.Command) Test(org.junit.Test)

Example 5 with Command

use of io.spine.base.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.base.Command) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Aggregations

Command (io.spine.base.Command)24 Test (org.junit.Test)14 StringValue (com.google.protobuf.StringValue)6 Message (com.google.protobuf.Message)4 ConstraintViolation (io.spine.validate.ConstraintViolation)4 Timestamp (com.google.protobuf.Timestamp)3 TestActorRequestFactory (io.spine.test.TestActorRequestFactory)3 TenantId (io.spine.users.TenantId)3 Event (io.spine.base.Event)2 Response (io.spine.base.Response)2 CommandOperation (io.spine.server.tenant.CommandOperation)2 EqualsTester (com.google.common.testing.EqualsTester)1 Any (com.google.protobuf.Any)1 StreamObserver (io.grpc.stub.StreamObserver)1 ActorContext (io.spine.base.ActorContext)1 CommandContext (io.spine.base.CommandContext)1 CommandId (io.spine.base.CommandId)1 Commands.getMessage (io.spine.base.Commands.getMessage)1 Failure (io.spine.base.Failure)1 StringChange (io.spine.change.StringChange)1