Search in sources :

Example 11 with CommandContext

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

the class GivenCommandContextShould method create_with_random_actor.

@Test
public void create_with_random_actor() {
    final CommandContext first = GivenCommandContext.withRandomActor();
    final CommandContext second = GivenCommandContext.withRandomActor();
    checkValid(first);
    checkValid(second);
    final ActorContext firstActorContext = first.getActorContext();
    final ActorContext secondActorContext = second.getActorContext();
    assertNotEquals(firstActorContext.getActor(), secondActorContext.getActor());
}
Also used : CommandContext(io.spine.core.CommandContext) ActorContext(io.spine.core.ActorContext) Test(org.junit.Test)

Example 12 with CommandContext

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

the class GivenCommandContextShould method create_with_scheduled_delay.

@Test
public void create_with_scheduled_delay() {
    final Duration delay = Durations2.fromHours(42);
    final Schedule expectedSchedule = Schedule.newBuilder().setDelay(delay).build();
    final CommandContext context = GivenCommandContext.withScheduledDelayOf(delay);
    checkValid(context);
    final Schedule actualSchedule = context.getSchedule();
    assertEquals(expectedSchedule, actualSchedule);
}
Also used : CommandContext(io.spine.core.CommandContext) Schedule(io.spine.core.CommandContext.Schedule) Duration(com.google.protobuf.Duration) Test(org.junit.Test)

Example 13 with CommandContext

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

the class EventStoreShould method fail_to_store_events_of_different_tenants_in_a_single_operation.

@Test(expected = IllegalArgumentException.class)
public void fail_to_store_events_of_different_tenants_in_a_single_operation() {
    final TenantId firstTenantId = TenantId.newBuilder().setValue("abc").build();
    final TenantId secondTenantId = TenantId.newBuilder().setValue("xyz").build();
    final ActorContext firstTenantActor = ActorContext.newBuilder().setTenantId(firstTenantId).build();
    final ActorContext secondTenantActor = ActorContext.newBuilder().setTenantId(secondTenantId).build();
    final CommandContext firstTenantCommand = CommandContext.newBuilder().setActorContext(firstTenantActor).build();
    final CommandContext secondTenantCommand = CommandContext.newBuilder().setActorContext(secondTenantActor).build();
    final EventContext firstTenantContext = EventContext.newBuilder().setCommandContext(firstTenantCommand).build();
    final EventContext secondTenantContext = EventContext.newBuilder().setCommandContext(secondTenantCommand).build();
    final Event firstTenantEvent = Event.newBuilder().setContext(firstTenantContext).build();
    final Event secondTenantEvent = Event.newBuilder().setContext(secondTenantContext).build();
    final Collection<Event> event = ImmutableSet.of(firstTenantEvent, secondTenantEvent);
    eventStore.appendAll(event);
}
Also used : EventContext(io.spine.core.EventContext) TenantId(io.spine.core.TenantId) CommandContext(io.spine.core.CommandContext) Event(io.spine.core.Event) ActorContext(io.spine.core.ActorContext) Test(org.junit.Test)

Example 14 with CommandContext

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

the class ProcessManagerShould method create_iterating_router.

@Test
public void create_iterating_router() {
    final StringValue commandMessage = toMessage("create_iterating_router");
    final CommandContext commandContext = requestFactory.createCommandContext();
    processManager.injectCommandBus(mock(CommandBus.class));
    final IteratingCommandRouter router = processManager.newIteratingRouterFor(commandMessage, commandContext);
    assertNotNull(router);
    assertEquals(commandMessage, getMessage(router.getSource()));
    assertEquals(commandContext, router.getSource().getContext());
}
Also used : CommandContext(io.spine.core.CommandContext) CommandBus(io.spine.server.commandbus.CommandBus) StringValue(com.google.protobuf.StringValue) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 15 with CommandContext

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

the class RejectionReactorMethodShould method invoke_reactor_method.

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

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