Search in sources :

Example 1 with ActorContext

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

the class RejectionEnvelopeShould method obtain_actor_context.

@Test
public void obtain_actor_context() {
    final RejectionEnvelope rejection = toEnvelope(outerObject());
    final ActorContext actorContext = rejection.getActorContext();
    /* Since we're using `TestActorRequestFactory` initialized with the class of this test suite
           the actor ID should be the suite class name.
         */
    assertEquals(getClass().getName(), actorContext.getActor().getValue());
}
Also used : RejectionEnvelope(io.spine.core.RejectionEnvelope) ActorContext(io.spine.core.ActorContext) Test(org.junit.Test)

Example 2 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 3 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 4 with ActorContext

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

the class AbstractCommandRouter method commandFactory.

/**
 * Creates a {@code CommandFactory} using the {@linkplain io.spine.core.UserId actor},
 * {@linkplain io.spine.core.TenantId tenant ID} and {@linkplain io.spine.time.ZoneOffset
 * zone offset} from the given command context.
 */
private static CommandFactory commandFactory(CommandContext sourceContext) {
    final ActorContext actorContext = sourceContext.getActorContext();
    final ActorRequestFactory factory = ActorRequestFactory.newBuilder().setActor(actorContext.getActor()).setTenantId(actorContext.getTenantId()).setZoneOffset(actorContext.getZoneOffset()).build();
    return factory.command();
}
Also used : ActorRequestFactory(io.spine.client.ActorRequestFactory) ActorContext(io.spine.core.ActorContext)

Example 5 with ActorContext

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

the class ActorRequestFactoryShould method verifyContext.

void verifyContext(ActorContext actualContext) {
    final ActorContext expectedContext = actorContext();
    assertEquals(expectedContext.getTenantId(), actualContext.getTenantId());
    assertEquals(expectedContext.getActor(), actualContext.getActor());
    assertEquals(expectedContext.getLanguage(), actualContext.getLanguage());
    assertEquals(expectedContext.getZoneOffset(), actualContext.getZoneOffset());
    // It's impossible to get the same creation time for the `expected` value,
    // so checking that the `actual` value is not later than `expected`.
    assertTrue(actualContext.getTimestamp().equals(expectedContext.getTimestamp()) || isLaterThan(expectedContext.getTimestamp(), actualContext.getTimestamp()));
}
Also used : ActorContext(io.spine.core.ActorContext)

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