use of io.spine.core.CommandContext in project core-java by SpineEventEngine.
the class StandPostShould method use_delivery_from_builder.
@SuppressWarnings("MagicNumber")
@Test
public void use_delivery_from_builder() {
final StandUpdateDelivery delivery = spy(new StandUpdateDelivery() {
@Override
protected boolean shouldPostponeDelivery(EntityStateEnvelope deliverable, Stand consumer) {
return false;
}
});
final Stand.Builder builder = Stand.newBuilder().setDelivery(delivery);
final Stand stand = builder.build();
Assert.assertNotNull(stand);
final Object id = Identifier.newUuid();
final StringValue state = StringValue.getDefaultInstance();
final VersionableEntity entity = mock(AbstractVersionableEntity.class);
when(entity.getState()).thenReturn(state);
when(entity.getId()).thenReturn(id);
when(entity.getVersion()).thenReturn(newVersion(17, Time.getCurrentTime()));
final CommandContext context = requestFactory.createCommandContext();
stand.post(context.getActorContext().getTenantId(), entity);
final EntityStateEnvelope envelope = EntityStateEnvelope.of(entity, context.getActorContext().getTenantId());
verify(delivery).deliverNow(eq(envelope), eq(Consumers.idOf(stand)));
}
use of io.spine.core.CommandContext in project core-java by SpineEventEngine.
the class CommandScheduler method setSchedule.
/**
* Updates {@linkplain CommandContext.Schedule command schedule}.
*
* @param command a command to update
* @param delay a {@linkplain CommandContext.Schedule#getDelay() delay} to set
* @param schedulingTime the time when the command was scheduled by the {@code CommandScheduler}
* @return an updated command
*/
static Command setSchedule(Command command, Duration delay, Timestamp schedulingTime) {
checkNotNull(command);
checkNotNull(delay);
checkNotNull(schedulingTime);
checkValid(schedulingTime);
final CommandContext context = command.getContext();
final CommandContext.Schedule scheduleUpdated = context.getSchedule().toBuilder().setDelay(delay).build();
final CommandContext contextUpdated = context.toBuilder().setSchedule(scheduleUpdated).build();
final Command.SystemProperties sysProps = command.getSystemProperties().toBuilder().setSchedulingTime(schedulingTime).build();
final Command result = command.toBuilder().setContext(contextUpdated).setSystemProperties(sysProps).build();
return result;
}
use of io.spine.core.CommandContext in project core-java by SpineEventEngine.
the class CommandFactory method create.
/**
* Creates a new {@link Command} with the given message.
*
* @param message the command message
* @return new command instance
* @throws ValidationException if the passed message does not satisfy the constraints
* set for it in its Protobuf definition
*/
public Command create(Message message) throws ValidationException {
checkNotNull(message);
checkValid(message);
final CommandContext context = createContext();
final Command result = createCommand(message, context);
return result;
}
use of io.spine.core.CommandContext 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());
}
use of io.spine.core.CommandContext in project core-java by SpineEventEngine.
the class CommandTest method adjustTimestamp.
/**
* Adjusts a timestamp in the context of the passed command.
*
* @return new command instance with the modified timestamp
*/
private static Command adjustTimestamp(Command command, Timestamp timestamp) {
final CommandContext context = command.getContext();
final ActorContext.Builder withTime = context.getActorContext().toBuilder().setTimestamp(timestamp);
final Command.Builder commandBuilder = command.toBuilder().setContext(context.toBuilder().setActorContext(withTime));
return commandBuilder.build();
}
Aggregations