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