Interface WorkflowTestDriver
- All Known Implementing Classes:
DefaultWorkflowTestDriver
This type exposes the low-level primitives that power WorkflowTestFixture. Use it directly when a test
needs more control than the staged fixture API provides, for example when selecting a specific workflow execution,
advancing time explicitly, or driving individual workflow steps in a precise order.
The term driver is used here in the modern testing sense: this class is a small facade that drives the system under test and keeps test code thin by wrapping workflow-specific interactions behind a focused API. It is not a classical integration-testing driver in the driver/stub sense where a temporary caller is built because the real upstream component does not exist yet.
Create an instance in one of two modes:
stepper(WorkflowModule, boolean, UnaryOperator)starts the workflow engine in stepping mode. In this mode workflow-defined step actions are paused until the test explicitly executes them throughexecuteStep(String),executeStep(String, PayloadProcessor), orexecuteStepFailing(String, StepFailedException). Stepping mode also enables virtual time control throughtimePasses(Duration).live(WorkflowModule, UnaryOperator)orlive(WorkflowModule, boolean, UnaryOperator)starts the workflow engine in live mode. In this mode the workflow runs normally, and the driver is limited to observation and event publication. Methods that depend on manual step execution or virtual time control reject live mode with anIllegalStateException.
The driver is stateful. Selection methods such as executionExists(), executionMatches(Predicate),
historyExists(), and historyMatches(Predicate) update the shared WorkflowEngineTestingState
with the current execution and workflow history. Later operations that inspect the workflow state, especially step
execution assertions, operate against that selected state.
Most observation methods are eventually consistent and use Awaitility under the hood. They
wait until the expected execution or history entry appears and then surface the last assertion failure when the wait
times out. This makes the driver suitable for workflows that advance asynchronously in response to published events
or scheduled timeouts.
A typical stepping-mode test flow is:
- Create the driver with one of the
stepper(...)factory methods - Trigger the workflow with
publishEvent(Object) - Select the active execution with
executionExists()orexecutionMatches(Predicate) - Drive waiting steps with
executeStep(String),executeStep(String, PayloadProcessor), orexecuteStepFailing(String, StepFailedException) - Advance scheduled work with
timePasses(Duration)when the workflow waits on time - Assert the resulting execution or recorded history with
executionSatisfies(Consumer),historySatisfies(Consumer),noExecution(), ornoHistory()
Tests that create the driver directly should call shutdown() when finished so all workflow infrastructure
is stopped cleanly.
- Since:
- 5.4.0
- Author:
- Simon Zambrovski
-
Method Summary
Modifier and TypeMethodDescriptionReturns the assertion failure handler.voidawaitEventually(String description, org.awaitility.core.ThrowingRunnable assertion) Waits until the given condition is met, using the defined assertion failure handler.voidexecuteStep(String stepName) Waits until the given step is executed calling original action defined in the workflow definition.voidexecuteStep(String stepName, PayloadProcessor payloadProcessor) Waits until the given step is executed calling the given payload processor.voidexecuteStepFailing(String stepName, StepFailedException exception) Waits until the given step is executed throwing the given exception.Waits until an active workflow execution exists.executionMatches(Predicate<WorkflowExecution> predicate) Waits until an active workflow execution matching the predicate exists.voidexecutionSatisfies(Consumer<WorkflowExecution> executionConsumer) Waits until an active workflow execution exists and applies the given consumer.Waits until a workflow history exists.historyMatches(Predicate<WorkflowHistory> predicate) Waits until a workflow history matching the predicate exists.voidhistorySatisfies(Consumer<WorkflowHistory> historyConsumer) Waits until a workflow history exists and applies the given consumer.static <C extends WorkflowContext>
WorkflowTestDriverlive(WorkflowModule<C> workflowModule, boolean throwFixtureException, UnaryOperator<WorkflowConfigurer> customize) Creates a new test driver in live mode.static <C extends WorkflowContext>
WorkflowTestDriverlive(WorkflowModule<C> workflowModule, UnaryOperator<WorkflowConfigurer> customize) Creates a new test driver in live mode.voidWaits until no active workflow executions exist.voidAsserts that no workflow histories exist.voidpublishEvent(Object event) Publishes an event.voidshutdown()Shuts down the tester.Constructs a list of step names.static <C extends WorkflowContext>
WorkflowTestDriverstepper(WorkflowModule<C> workflowModule, boolean throwFixtureException, UnaryOperator<WorkflowConfigurer> customize) Constructs a new test driver in stepping mode.booleanIndicates whether this driver runs in stepping mode.Returns the shared testing state.voidtimePasses(Duration duration) Advances time by the given duration.Returns services for testing workflow runtime.
-
Method Details
-
stepper
static <C extends WorkflowContext> WorkflowTestDriver stepper(WorkflowModule<C> workflowModule, boolean throwFixtureException, UnaryOperator<WorkflowConfigurer> customize) Constructs a new test driver in stepping mode.- Type Parameters:
C- type of the workflow context- Parameters:
workflowModule- workflow modulethrowFixtureException- whether to fail assertions. If set totrue, the failures are delivered asWorkflowTestFixtureExceptions, else asAssertionErrorcustomize- customizer of the workflow configuration- Returns:
- workflow test driver
-
live
static <C extends WorkflowContext> WorkflowTestDriver live(WorkflowModule<C> workflowModule, UnaryOperator<WorkflowConfigurer> customize) Creates a new test driver in live mode.- Type Parameters:
C- type of the workflow context- Parameters:
workflowModule- workflow modulecustomize- customizer of the workflow configuration- Returns:
- workflow test driver
-
live
static <C extends WorkflowContext> WorkflowTestDriver live(WorkflowModule<C> workflowModule, boolean throwFixtureException, UnaryOperator<WorkflowConfigurer> customize) Creates a new test driver in live mode.- Type Parameters:
C- type of the workflow context- Parameters:
workflowModule- workflow modulethrowFixtureException- whether to fail assertions withWorkflowTestFixtureExceptionscustomize- customizer of the workflow configuration- Returns:
- workflow test driver
-
stepNames
Constructs a list of step names.- Parameters:
stepName- mandatory first step namestepNames- optional additional step names- Returns:
- list of steps
-
workflowTestServices
WorkflowTestServices workflowTestServices()Returns services for testing workflow runtime.- Returns:
- services for testing workflow runtime
-
testingState
WorkflowEngineTestingState testingState()Returns the shared testing state.- Returns:
- shared testing state
-
assertionFailureHandler
AssertionFailureHandler assertionFailureHandler()Returns the assertion failure handler.- Returns:
- assertion failure handler
-
steppingMode
boolean steppingMode()Indicates whether this driver runs in stepping mode.- Returns:
trueif this driver runs in stepping mode, otherwisefalse
-
executionExists
WorkflowExecution executionExists()Waits until an active workflow execution exists.- Returns:
- the selected execution
-
executionMatches
Waits until an active workflow execution matching the predicate exists.- Parameters:
predicate- predicate used to select matching executions- Returns:
- the selected execution
-
executionSatisfies
Waits until an active workflow execution exists and applies the given consumer.- Parameters:
executionConsumer- consumer applied to the selected execution
-
noExecution
void noExecution()Waits until no active workflow executions exist. -
historyMatches
Waits until a workflow history matching the predicate exists.- Parameters:
predicate- predicate used to select matching histories- Returns:
- the selected history
-
historyExists
WorkflowHistory historyExists()Waits until a workflow history exists.- Returns:
- the selected history
-
historySatisfies
Waits until a workflow history exists and applies the given consumer.- Parameters:
historyConsumer- consumer applied to the selected history
-
noHistory
void noHistory()Asserts that no workflow histories exist. -
publishEvent
Publishes an event.- Parameters:
event- event message or event payload
-
timePasses
Advances time by the given duration.- Parameters:
duration- duration to advance time by
-
executeStep
Waits until the given step is executed calling original action defined in the workflow definition.This works only in stepping mode.
- Parameters:
stepName- step name
-
executeStep
Waits until the given step is executed calling the given payload processor.This works only in stepping mode.
- Parameters:
stepName- step namepayloadProcessor- payload processor to use instead of the workflow-defined action
-
executeStepFailing
Waits until the given step is executed throwing the given exception.This works only in stepping mode.
- Parameters:
stepName- name of the step to executeexception- exception to throw
-
shutdown
void shutdown()Shuts down the tester. -
awaitEventually
Waits until the given condition is met, using the defined assertion failure handler.- Parameters:
description- description of the assertionassertion- assertion to execute
-