use of io.spine.core.Command in project core-java by SpineEventEngine.
the class IdempotencyGuardShould method not_throw_if_another_command_was_handled.
@Test
public void not_throw_if_another_command_was_handled() {
final TenantId tenantId = newTenantId();
final ProjectId projectId = newProjectId();
final Command createCommand = command(createProject(projectId), tenantId);
final Command startCommand = command(startProject(projectId), tenantId);
final CommandBus commandBus = boundedContext.getCommandBus();
final StreamObserver<Ack> noOpObserver = noOpObserver();
commandBus.post(createCommand, noOpObserver);
final IgTestAggregate aggregate = repository.loadAggregate(tenantId, projectId);
final IdempotencyGuard guard = new IdempotencyGuard(aggregate);
guard.check(of(startCommand));
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class IdempotencyGuardShould method not_throw_when_the_command_was_handled_but_the_snapshot_was_made.
@Test
public void not_throw_when_the_command_was_handled_but_the_snapshot_was_made() {
repository.setSnapshotTrigger(1);
final TenantId tenantId = newTenantId();
final ProjectId projectId = newProjectId();
final Command createCommand = command(createProject(projectId), tenantId);
final CommandBus commandBus = boundedContext.getCommandBus();
final StreamObserver<Ack> noOpObserver = noOpObserver();
commandBus.post(createCommand, noOpObserver);
final IgTestAggregate aggregate = repository.loadAggregate(tenantId, projectId);
final IdempotencyGuard guard = new IdempotencyGuard(aggregate);
guard.check(of(createCommand));
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class AggregateMessageDeliveryTestEnv method createProject.
public static Command createProject() {
final ProjectId projectId = projectId();
final Command command = createCommand(AggCreateProject.newBuilder().setName("A project" + projectId).setProjectId(projectId).build());
return command;
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class RejectionHandlerMethod method doInvoke.
/**
* Invokes the wrapped handler method to handle {@code rejectionMessage},
* {@code commandMessage} with the passed {@code context} of the {@code Command}.
*
* <p>Unlike the {@linkplain #invoke(Object, Message, Message) overloaded alternative method},
* this one may return some value.
*
* @param target the target object on which call the method
* @param rejectionMsg the rejection message to handle
* @param context the context of the rejection
* @return the result of the invocation
*/
@SuppressWarnings("OverlyLongMethod")
Object doInvoke(Object target, Message rejectionMsg, RejectionContext context) {
checkNotNull(target);
checkNotNull(rejectionMsg);
checkNotNull(context);
final Command command = context.getCommand();
final CommandContext commandContext = command.getContext();
try {
final Object output;
final Method method = getMethod();
Message commandMessage;
switch(kind) {
case REJECTION_MESSAGE_AWARE:
output = method.invoke(target, rejectionMsg);
break;
case REJECTION_CONTEXT_AWARE:
output = method.invoke(target, rejectionMsg, context);
break;
case COMMAND_CONTEXT_AWARE:
output = method.invoke(target, rejectionMsg, commandContext);
break;
case COMMAND_MESSAGE_AWARE:
commandMessage = Commands.getMessage(command);
output = method.invoke(target, rejectionMsg, commandMessage);
break;
case COMMAND_AWARE:
commandMessage = Commands.getMessage(command);
output = method.invoke(target, rejectionMsg, commandMessage, commandContext);
break;
default:
throw unsupported("Unsupported method kind encountered %s", kind.name());
}
return output;
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
throw whyFailed(target, rejectionMsg, context, e);
}
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class AggregateTestEnv method cannotModifyDeletedEntity.
public static RejectionEnvelope cannotModifyDeletedEntity(Class<? extends Message> commandMessageCls) {
final CannotModifyDeletedEntity rejectionMsg = CannotModifyDeletedEntity.newBuilder().build();
final Command command = io.spine.server.commandbus.Given.ACommand.withMessage(Sample.messageOfType(commandMessageCls));
final Rejection rejection = Rejections.createRejection(rejectionMsg, command);
return RejectionEnvelope.of(rejection);
}
Aggregations