Interface WorkflowTestFixture<ACTION extends GivenWhen<ACTION,ASSERT>,ASSERT extends Then<ASSERT,ACTION>>

Type Parameters:
ACTION - type of the action phase used for given() and when()
ASSERT - type of the assertion phase used for then()
All Known Implementing Classes:
DefaultWorkflowTestFixture

public interface WorkflowTestFixture<ACTION extends GivenWhen<ACTION,ASSERT>,ASSERT extends Then<ASSERT,ACTION>>
Staged fixture for BDD-style workflow runtime tests.

This fixture wraps a WorkflowTestDriver in a small phase-oriented API so tests can read as given / when / then scenarios while still exercising the real workflow runtime. The fixture starts the workflow module in stepping mode, publishes real events, records normal workflow history, and keeps the selected execution or history entry shared across all phases.

The phase model is intentionally small:

  • given() returns the action phase for arranging workflow state before the behavior under test
  • when() returns the same action phase, but named for the stimulus or transition being tested
  • then() returns the assertion phase for verifying workflow state, steps, history, or payload

All phases are bound to the same underlying workflow runtime. Switching between them does not reset the fixture or start a new workflow test driver; it only changes which fluent operations are exposed next.

Failures are intentionally surfaced differently per phase. Action-phase methods reached through given() and when() use WorkflowTestFixtureException for fixture-driving failures such as missing executions or steps that never reach the expected terminal state. Assertion-phase methods reached through then() fail with plain AssertionErrors, so they behave like conventional test assertions.

Since:
5.4.0
Author:
Simon Zambrovski
  • Method Details

    • workflowModule

      static <T extends WorkflowContext> WorkflowModule<T> workflowModule(Class<T> contextType, ComponentBuilder<WorkflowContextFactory<T>> workflowContextFactoryBuilder, ComponentBuilder<Object> workflowInstanceBuilder)
      Builds an autodetected WorkflowModule registered under WorkflowTestServices.DEFAULT_MODULE_NAME, ready to be passed into of(WorkflowModule) or of(WorkflowModule, UnaryOperator).
      Type Parameters:
      T - type of the workflow context
      Parameters:
      contextType - type of the workflow context
      workflowContextFactoryBuilder - builder of the WorkflowContextFactory for the workflow context
      workflowInstanceBuilder - builder of the workflow instance to autodetect handlers on
      Returns:
      workflow module ready for use in a WorkflowTestFixture
    • of

      static <T extends WorkflowContext> WorkflowTestFixture<GivenWhen.Phase,Then.Phase> of(WorkflowModule<T> workflowModule)
      Creates a fixture with the default action and assertion phases.
      Type Parameters:
      T - type of the workflow context
      Parameters:
      workflowModule - workflow module to test
      Returns:
      fixture backed by the supplied workflow module
    • of

      Creates a fixture with the default action and assertion phases and a custom configuration step.
      Type Parameters:
      T - type of the workflow context
      Parameters:
      workflowModule - workflow module to test
      customize - customizer of the workflow configuration
      Returns:
      fixture backed by the supplied workflow module and customization
    • of

      static <T extends WorkflowContext, ACTION extends GivenWhen<ACTION, ASSERT>, ASSERT extends Then<ASSERT, ACTION>> WorkflowTestFixture<ACTION,ASSERT> of(WorkflowModule<T> workflowModule, UnaryOperator<WorkflowConfigurer> customize, ACTION givenWhenPhase, ASSERT thenPhase)
      Creates a fixture with caller-supplied action and assertion phases.

      Use this overload to introduce domain-specific phase methods while keeping the same underlying fixture behavior.

      Type Parameters:
      T - type of the workflow context
      ACTION - type of the action phase
      ASSERT - type of the assertion phase
      Parameters:
      workflowModule - workflow module to test
      customize - customizer of the workflow configuration
      givenWhenPhase - phase instance used for given() and when()
      thenPhase - phase instance used for then()
      Returns:
      fixture backed by the supplied workflow module and custom phases
    • given

      ACTION given()
      Returns the action phase in its setup role.

      Use this entry point for the given part of a scenario, where the test prepares workflow state before the main behavior is triggered. The returned object is the shared action phase instance used by this fixture. Failures raised while driving the fixture from this phase are reported as WorkflowTestFixtureException.

      Returns:
      action phase for arranging workflow state
    • when

      ACTION when()
      Returns the action phase in its stimulus role.

      This method returns the same phase instance as given(). The different name exists so tests can read naturally when they move from setup to the behavior under test. Calling when() does not reset the fixture or change the selected workflow state. Failures raised while driving the fixture from this phase are reported as WorkflowTestFixtureException.

      Returns:
      action phase for triggering the behavior under test
    • then

      ASSERT then()
      Returns the assertion phase.

      The returned phase shares the same workflow runtime and testing state as given() and when(). Use it to assert executions, histories, steps, payload, and workflow state after one or more action-phase operations. Failures raised from this phase are reported as AssertionErrors.

      Returns:
      assertion phase for verifying workflow behavior