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();
}
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());
}
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);
}
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;
}
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());
}
Aggregations