SagaVerifier

Utility object for creating and configuring stateless saga verifiers for testing.

SagaVerifier provides a fluent API for testing stateless sagas using the Given/When/Expect pattern. It simplifies saga testing by offering pre-configured components and convenient factory methods that handle the complex setup of command gateways, service providers, and message factories.

Key features:

  • Pre-configured command gateway for isolated testing

  • Automatic metadata extraction from saga class annotations

  • Support for dependency injection via ServiceProvider

  • Fluent DSL for defining test scenarios with domain events

  • Type-safe testing with generics and reified types

Example usage:

SagaVerifier.sagaVerifier<OrderSaga>()
.whenEvent(mockOrderCreatedEvent)
.expectNoCommand()
.verify()

Author

ahoo wang

Functions

Link copied to clipboard

Creates a default command gateway configured for stateless saga testing.

Link copied to clipboard
inline fun <T : Any> sagaVerifier(serviceProvider: ServiceProvider = SimpleServiceProvider(), commandGateway: CommandGateway = defaultCommandGateway()): WhenStage<T>

Creates a when stage for testing a stateless saga using reified generics.

fun <T : Any> Class<T>.sagaVerifier(serviceProvider: ServiceProvider = SimpleServiceProvider(), commandGateway: CommandGateway = defaultCommandGateway(), commandMessageFactory: CommandMessageFactory = SimpleCommandMessageFactory( validator = TestValidator, commandBuilderRewriterRegistry = SimpleCommandBuilderRewriterRegistry(), )): WhenStage<T>

Creates a when stage for testing a stateless saga of this class type.