use of io.spine.base.CommandContext in project core-java by SpineEventEngine.
the class ProcessManagerShould method create_router.
@Test
public void create_router() {
final StringValue commandMessage = Wrapper.forString("create_router");
final CommandContext commandContext = requestFactory.createCommandContext();
processManager.setCommandBus(mock(CommandBus.class));
final CommandRouter router = processManager.newRouterFor(commandMessage, commandContext);
assertNotNull(router);
assertEquals(commandMessage, getMessage(router.getSource()));
assertEquals(commandContext, router.getSource().getContext());
}
use of io.spine.base.CommandContext in project core-java by SpineEventEngine.
the class CommandFactoryShould method create_command_context.
@Test
public void create_command_context() {
final TenantId tenantId = newTenantUuid();
final UserId userId = newUserUuid();
final ZoneOffset zoneOffset = ZoneOffsets.ofHours(-3);
final int targetVersion = 100500;
final CommandContext commandContext = CommandFactory.createContext(tenantId, userId, zoneOffset, targetVersion);
final ActorContext actorContext = commandContext.getActorContext();
assertEquals(tenantId, actorContext.getTenantId());
assertEquals(userId, actorContext.getActor());
assertEquals(zoneOffset, actorContext.getZoneOffset());
assertEquals(targetVersion, commandContext.getTargetVersion());
}
use of io.spine.base.CommandContext in project core-java by SpineEventEngine.
the class CommandFactory method create.
/**
* Creates new {@code Command} with the passed message and target entity version.
*
* <p>The command contains a {@code CommandContext} instance with the current time.
*
* <p>The message passed is validated according to the constraints set in its Protobuf
* definition. In case the message isn't valid, an {@linkplain ConstraintViolationThrowable
* exception} is thrown.
*
* @param message the command message
* @param targetVersion the ID of the entity for applying commands if {@code null}
* the commands can be applied to any entity
* @return new command instance
* @throws ConstraintViolationThrowable if the passed message does not satisfy the constraints
* set for it in its Protobuf definition
*/
public Command create(Message message, int targetVersion) throws ConstraintViolationThrowable {
checkNotNull(message);
checkNotNull(targetVersion);
checkValid(message);
final CommandContext context = createContext(targetVersion);
final Command result = createCommand(message, context);
return result;
}
use of io.spine.base.CommandContext in project core-java by SpineEventEngine.
the class CommandFactory method createBasedOnContext.
/**
* Creates new {@code Command} with the passed message, using the existing context.
*
* <p>The produced command is created with a {@code CommandContext} instance, copied from
* the given one, but with the current time set as a context timestamp.
*
* @param message the command message
* @param context the command context to use as a base for the new command
* @return new command instance
* @throws ConstraintViolationThrowable if the passed message does not satisfy the constraints
* set for it in its Protobuf definition
*/
@Internal
public Command createBasedOnContext(Message message, CommandContext context) throws ConstraintViolationThrowable {
checkNotNull(message);
checkNotNull(context);
checkValid(message);
final CommandContext newContext = contextBasedOn(context);
final Command result = createCommand(message, newContext);
return result;
}
use of io.spine.base.CommandContext in project core-java by SpineEventEngine.
the class CommandFactory method createContext.
/**
* Creates a new command context with the current time.
*
* @param tenantId the ID of the tenant or {@code null} for single-tenant applications
* @param userId the actor id
* @param zoneOffset the offset of the timezone in which the user works
* @param targetVersion the the ID of the entity for applying commands
* @return new {@code CommandContext}
* @see CommandFactory#create(Message)
*/
@VisibleForTesting
static CommandContext createContext(@Nullable TenantId tenantId, UserId userId, ZoneOffset zoneOffset, int targetVersion) {
checkNotNull(userId);
checkNotNull(zoneOffset);
checkNotNull(targetVersion);
final CommandContext.Builder builder = newContextBuilder(tenantId, userId, zoneOffset);
final CommandContext result = builder.setTargetVersion(targetVersion).build();
return result;
}
Aggregations