aggregateSpecTests
fun <S : Any> aggregateSpecTests(model: AggregateModel<S>, id: String = "aggregate-1", caller: Caller? = null, tenantId: String = caller?.tenantId ?: DEFAULT_TENANT, start: Instant = DEFAULT_START, block: AggregateSpec<S>.() -> Unit): Stream<DynamicNode>
The specification aggregateSpec runs, as a tree of tests for a JUnit @TestFactory: each AggregateSpec.whenCommand, AggregateSpec.advanceTime and AggregateSpec.expectNothingDue is a test of its own, and each AggregateSpec.fork a container of the tests it runs, named by the fork. A failing check fails its own test only: the specification goes on, so the other steps and forks still run and report on their own.
@TestFactory
fun order() = aggregateSpecTests(orderModel) {
whenCommand(PlaceOrder(...)) {
expectEventTypes(OrderPlaced::class)
fork("paid") { whenCommand(PayOrder(...)) { expectEventTypes(OrderPaid::class) } }
fork("cancelled") { whenCommand(CancelOrder(...)) { expectEventTypes(OrderCancelled::class) } }
}
}Content copied to clipboard
The specification runs as the tree is built, as 9.x's did; the tests report what each step found. An exception outside a step (a AggregateSpec.given that cannot commit, say) ends its fork, or the specification, and is reported as a failing test Error.