Context and Mode
The Context SPI interface provides runtime services for an active descriptor execution. Mode determines how an action executes.
import org.paramixel.api.action.Context;
import org.paramixel.api.action.Mode;
Context
public interface Context {
Configuration configuration();
Listener listener();
Descriptor descriptor();
<T> Optional<T> instance(Class<T> type);
void setStatus(Status status);
}
| Method | Description |
|---|---|
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→RUNNINGis validRUNNING→ terminal (PASSED,FAILED,SKIPPED,ABORTED) is validPENDINGas a target status throwsIllegalArgumentException- 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(Context context) {
Optional<MyService> service = context.instance(MyService.class);
service.ifPresent(s -> s.performWork());
}
Mode
public enum Mode {
RUN,
SKIP,
ABORT;
}
| Value | Behavior |
|---|---|
RUN | Execute the action's logic normally |
SKIP | Produce a skipped outcome without running the action body |
ABORT | Produce an aborted outcome without running the action body |
Modes are per-execution, not properties of reusable Action definitions.
| Method | Description |
|---|---|
toStatus() | Returns the terminal status for this mode |
fromStatus(Status) | Returns the mode to propagate based on a terminal status |
Mode-to-Status mapping
| Mode | toStatus() |
|---|---|
RUN | PASSED |
SKIP | SKIPPED |
ABORT | ABORTED |
Status-to-Mode propagation
| Terminal status | fromStatus() |
|---|---|
ABORTED | ABORT |
| Any other terminal | SKIP |
Built-in actions check the mode before executing user callbacks. Custom actions should do the same:
@Override
public void execute(Context 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.