Interface AxonTestPhase
This interface defines four primary phases of a test:
AxonTestPhase.Setup- Initial configuration of the test fixtureAxonTestPhase.Given- Defining the initial state of the system before testing by events and commandsAxonTestPhase.When- Executing commands to testAxonTestPhase.Then- Validating the results of the test
The test fixture manages UnitOfWork instances during test execution,
automatically committing as appropriate. During the Given phase, each operation (like AxonTestPhase.Given.event(java.lang.Object)},
AxonTestPhase.Given.command(java.lang.Object) or even batched like AxonTestPhase.Given.events(org.axonframework.messaging.eventhandling.EventMessage...) and AxonTestPhase.Given.commands(org.axonframework.messaging.commandhandling.CommandMessage...))
is executed in its own separate UnitOfWork that is committed immediately after execution. In the When phase, a single Unit of Work is started
and committed after the command is executed. The Then phase only validates the results.
The test phases operates on components defined in Configuration that you pass to the fixture during its construction.
Typical usage example:
var fixture = AxonTestFixture.with(configurer);
fixture.given()
.event(new AccountCreatedEvent("account-1"))
.when()
.command(new WithdrawMoneyCommand("account-1", 100.00))
.then()
.success()
.events(new MoneyWithdrawnEvent("account-1", 100.00));
Example with chaining multiple test scenarios using and():
var fixture = AxonTestFixture.with(configurer);
fixture.given()
.event(new AccountCreatedEvent("account-1", 500.00))
.when()
.command(new WithdrawMoneyCommand("account-1", 100.00))
.then()
.events(new MoneyWithdrawnEvent("account-1", 100.00))
.success()
.and()
.when()
.command(new WithdrawMoneyCommand("account-1", 500.00))
.then()
.exception(InsufficientBalanceException.class)
.noEvents();
- Since:
- 5.0.0
- Author:
- Allard Buijze, Mateusz Nowak, Mitchell Herrijgers, Steven van Beelen
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceInterface describing the operations available in the Given phase of the test fixture execution.static interfaceInterface describing the initial setup phase of a test fixture.static interfaceInterface describing the operations available in the Then phase of the test fixture execution.static interfaceInterface describing the operations available in the When phase of the test fixture execution.