Search in sources :

Example 16 with CommandContext

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

the class RejectionSubscriberMethodShould method invoke_subscriber_method.

@Test
public void invoke_subscriber_method() throws InvocationTargetException {
    final ValidThreeParams subscriberObject = new ValidThreeParams();
    final RejectionSubscriberMethod method = new RejectionSubscriberMethod(subscriberObject.getMethod());
    final InvalidProjectName rejectionMessage = Given.RejectionMessage.invalidProjectName();
    final RejectionContext.Builder builder = RejectionContext.newBuilder();
    final CommandContext commandContext = CommandContext.newBuilder().setTargetVersion(1020).build();
    final RjUpdateProjectName commandMessage = RjUpdateProjectName.getDefaultInstance();
    builder.setCommand(Command.newBuilder().setMessage(pack(commandMessage)).setContext(commandContext));
    final RejectionContext rejectionContext = builder.build();
    method.invoke(subscriberObject, rejectionMessage, rejectionContext);
    assertEquals(rejectionMessage, subscriberObject.getLastRejectionMessage());
    assertEquals(commandMessage, subscriberObject.getLastCommandMessage());
    assertEquals(commandContext, subscriberObject.getLastCommandContext());
}
Also used : CommandContext(io.spine.core.CommandContext) ValidThreeParams(io.spine.server.rejection.given.RejectionSubscriberMethodTestEnv.ValidThreeParams) InvalidProjectName(io.spine.test.reflect.ReflectRejections.InvalidProjectName) RejectionContext(io.spine.core.RejectionContext) RjUpdateProjectName(io.spine.test.rejection.command.RjUpdateProjectName) Test(org.junit.Test)

Example 17 with CommandContext

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

the class EventsTestEnv method commandContext.

public static CommandContext commandContext(TenantId id) {
    final ActorContext actorContext = ActorContext.newBuilder().setTenantId(id).build();
    final CommandContext result = CommandContext.newBuilder().setActorContext(actorContext).build();
    return result;
}
Also used : CommandContext(io.spine.core.CommandContext) ActorContext(io.spine.core.ActorContext)

Example 18 with CommandContext

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

the class AbstractCommandRouter method produceCommand.

private Command produceCommand(Message commandMessage) {
    final CommandContext sourceContext = source.getContext();
    final CommandFactory commandFactory = commandFactory(sourceContext);
    final Command result = commandFactory.createBasedOnContext(commandMessage, sourceContext);
    return result;
}
Also used : CommandContext(io.spine.core.CommandContext) Command(io.spine.core.Command) CommandFactory(io.spine.client.CommandFactory)

Example 19 with CommandContext

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

the class CommandHistory method contains.

public boolean contains(Command command) {
    final Message message = Commands.getMessage(command);
    if (messages.contains(message)) {
        final int messageIndex = messages.indexOf(message);
        final CommandContext actualContext = command.getContext();
        final CommandContext storedContext = contexts.get(messageIndex);
        return actualContext.equals(storedContext);
    }
    return false;
}
Also used : Message(com.google.protobuf.Message) CommandContext(io.spine.core.CommandContext)

Example 20 with CommandContext

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

the class TestActorRequestFactory method withTimestamp.

private static Command withTimestamp(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.core.CommandContext) Command(io.spine.core.Command) ActorContext(io.spine.core.ActorContext)

Aggregations

CommandContext (io.spine.core.CommandContext)25 Test (org.junit.Test)11 ActorContext (io.spine.core.ActorContext)8 Command (io.spine.core.Command)8 StringValue (com.google.protobuf.StringValue)4 Message (com.google.protobuf.Message)3 TenantId (io.spine.core.TenantId)3 CommandBus (io.spine.server.commandbus.CommandBus)3 Event (io.spine.core.Event)2 EventContext (io.spine.core.EventContext)2 RejectionContext (io.spine.core.RejectionContext)2 UserId (io.spine.core.UserId)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 InvalidProjectName (io.spine.test.reflect.ReflectRejections.InvalidProjectName)2 RjUpdateProjectName (io.spine.test.rejection.command.RjUpdateProjectName)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Duration (com.google.protobuf.Duration)1 Timestamp (com.google.protobuf.Timestamp)1 Internal (io.spine.annotation.Internal)1 CommandFactory (io.spine.client.CommandFactory)1