Skip to main content
Version: 5.0.0 (Unmaintained)

ExecutionContext and Mode

The ExecutionContext SPI interface provides runtime services for an active descriptor execution. Mode determines how an action executes.

import org.paramixel.spi.action.ExecutionContext;
import org.paramixel.spi.action.Mode;

ExecutionContext​

public interface ExecutionContext {
Configuration configuration();
Listener listener();
Descriptor descriptor();
<T> Optional<T> instance(Class<T> type);
void setStatus(Status status);
}
MethodDescription
configuration()The run configuration
listener()The listener for callbacks
descriptor()The descriptor currently being executed
instance(Class<T> type)The current fixture instance from a parent Instance action, or empty
setStatus(Status)Sets the descriptor status; must be RUNNING or terminal

Status transitions​

setStatus() validates transitions:

  • PENDING → RUNNING is valid
  • RUNNING → terminal (PASSED, FAILED, SKIPPED, ABORTED) is valid
  • PENDING as a target status throws IllegalArgumentException
  • Transitions from a terminal status throw IllegalStateException

Setting status with detail​

To set a terminal status with a message or throwable, use Status factory methods:

context.setStatus(Status.failed("connection refused"));
context.setStatus(Status.failed("timeout", new TimeoutException()));

Using instance​

Within an Instance action, instance() returns the fixture object created by the instance factory. Outside an Instance scope, returns Optional.empty().

@Override
public void execute(ExecutionContext context) {
Optional<MyService> service = context.instance(MyService.class);
service.ifPresent(s -> s.performWork());
}

Mode​

public enum Mode {
RUN,
SKIP,
ABORT;
}
ValueBehavior
RUNExecute the action's logic normally
SKIPProduce a skipped outcome without running the action body
ABORTProduce an aborted outcome without running the action body

Modes are per-execution, not properties of reusable Action definitions.

MethodDescription
toStatus()Returns the terminal status for this mode
fromStatus(Status)Returns the mode to propagate based on a terminal status

Mode-to-Status mapping​

ModetoStatus()
RUNPASSED
SKIPSKIPPED
ABORTABORTED

Status-to-Mode propagation​

Terminal statusfromStatus()
ABORTEDABORT
Any other terminalSKIP

Built-in actions check the mode before executing user callbacks. Custom actions should do the same:

@Override
public void execute(ExecutionContext context) {
var mode = context.descriptor().metadata().mode();
if (mode != Mode.RUN) {
context.setStatus(mode.toStatus());
return;
}
// ... execute action logic ...
context.setStatus(Status.PASSED);
}

See Custom Actions for the full custom action contract and Action for the action interface.