Search in sources :

Example 6 with ActorContext

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

the class GivenCommandContext method withActorAndTime.

/**
 * Creates a new {@link CommandContext} instance based upon given actor and creation date.
 *
 * @return a new {@code CommandContext} instance
 */
public static CommandContext withActorAndTime(UserId actor, Timestamp when) {
    final TenantId tenantId = GivenTenantId.newUuid();
    final ActorContext.Builder actorContext = ActorContext.newBuilder().setActor(actor).setTimestamp(when).setZoneOffset(UTC).setTenantId(tenantId);
    final CommandContext.Builder builder = CommandContext.newBuilder().setActorContext(actorContext);
    return builder.build();
}
Also used : TenantId(io.spine.core.TenantId) CommandContext(io.spine.core.CommandContext) ActorContext(io.spine.core.ActorContext)

Example 7 with ActorContext

use of io.spine.core.ActorContext 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 8 with ActorContext

use of io.spine.core.ActorContext 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 9 with ActorContext

use of io.spine.core.ActorContext 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 10 with ActorContext

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

the class GivenCommandContextShould method create_with_actor_and_time.

@Test
public void create_with_actor_and_time() {
    final UserId actorId = newUuid();
    final Timestamp when = add(getCurrentTime(), fromMinutes(42));
    final CommandContext context = GivenCommandContext.withActorAndTime(actorId, when);
    checkValid(context);
    final ActorContext actualActorContext = context.getActorContext();
    assertEquals(actorId, actualActorContext.getActor());
    assertEquals(when, actualActorContext.getTimestamp());
}
Also used : CommandContext(io.spine.core.CommandContext) UserId(io.spine.core.UserId) Timestamp(com.google.protobuf.Timestamp) ActorContext(io.spine.core.ActorContext) Test(org.junit.Test)

Aggregations

ActorContext (io.spine.core.ActorContext)10 CommandContext (io.spine.core.CommandContext)6 Test (org.junit.Test)5 TenantId (io.spine.core.TenantId)3 UserId (io.spine.core.UserId)2 Timestamp (com.google.protobuf.Timestamp)1 ActorRequestFactory (io.spine.client.ActorRequestFactory)1 Event (io.spine.core.Event)1 EventContext (io.spine.core.EventContext)1 RejectionEnvelope (io.spine.core.RejectionEnvelope)1 GivenTenantId (io.spine.core.given.GivenTenantId)1 GivenUserId (io.spine.core.given.GivenUserId)1 ZoneOffset (io.spine.time.ZoneOffset)1