sagaVerifier
Creates a when stage for testing a stateless saga of this class type.
This extension method on Class
The method configures:
Saga processor metadata extraction
Service provider for dependency injection
Command gateway for sending commands triggered by the saga
Command message factory for creating command messages
Example:
CartSaga::class.java.sagaVerifier()
.whenEvent(
event = mockk<OrderCreated> { ... },
ownerId = "owner123"
)
.expectCommandType(RemoveCartItem::class)
.expectCommand<RemoveCartItem> { body.productIds.assert().hasSize(1) }
.verify()Return
a WhenStage instance for defining test scenarios with domain events
Parameters
the type of the saga class to be tested
the service provider for dependency injection, defaults to SimpleServiceProvider
the command gateway for sending commands, defaults to defaultCommandGateway()
the factory for creating command messages, defaults to SimpleCommandMessageFactory with TestValidator
Throws
if saga metadata cannot be resolved from class annotations
Creates a when stage for testing a stateless saga using reified generics.
This inline function provides a convenient way to create saga verifiers without explicitly specifying the Class type. It leverages Kotlin's reified generics to automatically infer the saga class type at compile time, enabling type-safe testing without reflection overhead.
This is the recommended method for creating saga verifiers in Kotlin code due to its type safety and conciseness compared to the Class-based extension method.
Example:
sagaVerifier<OrderSaga>()
.whenEvent(
event = mockk<OrderCreated> {
every { items } returns listOf(orderItem)
every { fromCart } returns true
},
state = mockk<OrderState>()
)
.expectNoCommand()
.verify()Return
a WhenStage instance for defining test scenarios with domain events
Parameters
the reified type of the saga class (inferred automatically)
the service provider for dependency injection, defaults to SimpleServiceProvider
the command gateway for sending commands, defaults to defaultCommandGateway()
Throws
if saga metadata cannot be resolved from class annotations