Interface WhenState
- All Known Subinterfaces:
ContinuedGivenState
- All Known Implementing Classes:
SagaTestFixture
- Since:
- 2.1.1
- Author:
- Allard Buijze
-
Method Summary
Modifier and TypeMethodDescriptionwhenAggregate(String aggregateIdentifier) Use this method to indicate that an aggregate with given identifier should publish certain events, while recording the outcome.whenPublishingA(Object event) Use this method to indicate an event is published, while recording the outcome.whenPublishingA(Object event, Map<String, String> metadata) Use this method to indicate an event is published with given additionalmetadata, while recording the outcome.whenTimeAdvancesTo(Instant newDateTime) Mimic an elapsed time with no relevant activity for the Saga.whenTimeElapses(Duration elapsedTime) Mimic an elapsed time with no relevant activity for the Saga.
-
Method Details
-
whenAggregate
Use this method to indicate that an aggregate with given identifier should publish certain events, while recording the outcome. In contrast to thegivenandandThenmethods, 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
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
Use this method to indicate an event is published with given additionalmetadata, 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 publishmetadata- The metadata to attach to the event- Returns:
- an object allowing you to verify the test results
-
whenTimeElapses
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
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
-