Class SagaAssertions
SagaStore of a running Configuration.
A Saga keeps its state in a SagaStore rather than in messages, so a test that only observes published events
and dispatched commands cannot tell a Saga that ended from one that never started. These assertions close that gap.
They are the one thing AxonTestFixture cannot express on its own, and are meant to be handed to its
expect operation:
fixture.given()
.event(new OrderPlaced("order-1"))
.when()
.event(new OrderShipped("shipment-of-order-1"))
.then()
.commands(new ConfirmOrder("order-1"))
.expect(SagaAssertions.activeSagas(1))
.expect(SagaAssertions.associationWith(OrderSaga.class, "orderId", "order-1"));
The SagaStore is resolved from the Configuration as a component, so the configuration under test has
to register one. SagaTestFixture does that itself and offers the same assertions under their Axon
Framework 4 names.- Since:
- 5.4.0
- Author:
- Allard Buijze, Mateusz Nowak
-
Method Summary
Modifier and TypeMethodDescriptionstatic Consumer<Configuration> activeSagas(int expected) Asserts that theSagaStoreholdsexpectedSagas.static Consumer<Configuration> associationWith(Class<?> sagaType, String key, Object value) Asserts that a Saga of the givensagaTypeis associated with the givenkeyandvalue.static Consumer<Configuration> noAssociationWith(Class<?> sagaType, String key, Object value) Asserts that no Saga of the givensagaTypeis associated with the givenkeyandvalue.
-
Method Details
-
activeSagas
Asserts that theSagaStoreholdsexpectedSagas.Counts every Saga in the store, whatever its type, which is what Axon Framework 4 did and is why this assertion takes no Saga type while
associationWith(Class, String, Object)does. The count is only available from anInMemorySagaStore; against any other store this throws aFixtureExecutionException.- Parameters:
expected- the number of Sagas the store is expected to hold- Returns:
- an assertion to hand to
AxonTestPhase.Then.MessageAssertions.expect(Consumer)
-
associationWith
Asserts that a Saga of the givensagaTypeis associated with the givenkeyandvalue.The
valueis compared by itsstring representation, as Axon Framework 4 did, because that is the form anAssociationValueholds.- Parameters:
sagaType- the type of Saga to look forkey- the key of the associationvalue- the value of the association, compared by its string representation- Returns:
- an assertion to hand to
AxonTestPhase.Then.MessageAssertions.expect(Consumer)
-
noAssociationWith
public static Consumer<Configuration> noAssociationWith(Class<?> sagaType, String key, Object value) Asserts that no Saga of the givensagaTypeis associated with the givenkeyandvalue.The
valueis compared by itsstring representation, as Axon Framework 4 did, because that is the form anAssociationValueholds.- Parameters:
sagaType- the type of Saga to look forkey- the key of the associationvalue- the value of the association, compared by its string representation- Returns:
- an assertion to hand to
AxonTestPhase.Then.MessageAssertions.expect(Consumer)
-