Interface WhenState

All Known Subinterfaces:
ContinuedGivenState
All Known Implementing Classes:
SagaTestFixture

public interface WhenState
Interface providing an API to methods in the "when" state of the fixture execution. Unlike the methods in the "given" state, these methods record the behavior of the Sagas involved for validation.
Since:
2.1.1
Author:
Allard Buijze
  • Method Details

    • whenAggregate

      WhenAggregateEventPublisher whenAggregate(String aggregateIdentifier)
      Use this method to indicate that an aggregate with given identifier should publish certain events, while recording the outcome. In contrast to the given and andThen methods, this method starts recording activity on the event sink and command bus.

      Can be chained to build natural sentences: whenAggregate(someIdentifier).publishes(anEvent)

      Note that if you inject resources using FixtureConfiguration.registerResource(Object), you may need to reset them yourself if they are manipulated by the Saga in the "given" stage of the test.

      Parameters:
      aggregateIdentifier - The identifier of the aggregate the events should appear to come from
      Returns:
      an object that allows registration of the actual events to send
    • whenPublishingA

      FixtureExecutionResult whenPublishingA(Object event)
      Use this method to indicate an event is published, while recording the outcome.

      Note that if you inject resources using FixtureConfiguration.registerResource(Object), you may need to reset them yourself if they are manipulated by the Saga in the "given" stage of the test.

      Parameters:
      event - the event to publish
      Returns:
      an object allowing you to verify the test results
    • whenPublishingA

      FixtureExecutionResult whenPublishingA(Object event, Map<String,String> metadata)
      Use this method to indicate an event is published with given additional metadata, while recording the outcome.

      Note that if you inject resources using FixtureConfiguration.registerResource(Object), you may need to reset them yourself if they are manipulated by the Saga in the "given" stage of the test.

      Parameters:
      event - the event to publish
      metadata - The metadata to attach to the event
      Returns:
      an object allowing you to verify the test results
    • whenTimeElapses

      FixtureExecutionResult whenTimeElapses(Duration elapsedTime)
      Mimic an elapsed time with no relevant activity for the Saga. If any Events are scheduled to be published within this time frame, they are published. All activity by the Saga on the command bus and event sink (meaning that scheduled events are excluded) is recorded.

      Note that if you inject resources using FixtureConfiguration.registerResource(Object), you may need to reset them yourself if they are manipulated by the Saga in the "given" stage of the test.

      Parameters:
      elapsedTime - The amount of time to elapse
      Returns:
      an object allowing you to verify the test results
    • whenTimeAdvancesTo

      FixtureExecutionResult whenTimeAdvancesTo(Instant newDateTime)
      Mimic an elapsed time with no relevant activity for the Saga. If any Events are scheduled to be published within this time frame, they are published. All activity by the Saga on the command bus and event sink (meaning that scheduled events are excluded) is recorded.

      Note that if you inject resources using FixtureConfiguration.registerResource(Object), you may need to reset them yourself if they are manipulated by the Saga in the "given" stage of the test.

      Parameters:
      newDateTime - The time to advance the clock to
      Returns:
      an object allowing you to verify the test results