AggregateVerifier

Aggregate Verifier provides utilities for testing domain aggregates using the Given/When/Expect pattern.

This object facilitates setting up and executing tests for aggregate behavior by providing methods to create GivenStage instances. The Given/When/Expect pattern allows for declarative testing of command handling, event production, and state changes in domain aggregates.

Key features:

  • Fluent API for test setup and verification

  • Support for event sourcing and state-based aggregates

  • Integration with in-memory event stores for isolated testing

  • Dependency injection support via ServiceProvider

  • Multi-tenant aggregate testing capabilities

Example usage:

aggregateVerifier<Cart, CartState>()
.given(CartItemAdded(...))
.whenCommand(AddCartItem(...))
.expectEventType(CartItemAdded::class)
.expectState { items.assert().hasSize(1) }
.verify()

Author

ahoo wang

Functions

Link copied to clipboard
fun <C : Any, S : Any> Class<C>.aggregateVerifier(aggregateId: String = generateGlobalId(), tenantId: String = TenantId.DEFAULT_TENANT_ID, stateAggregateFactory: StateAggregateFactory = ConstructorStateAggregateFactory, eventStore: EventStore = InMemoryEventStore(), serviceProvider: ServiceProvider = SimpleServiceProvider()): GivenStage<S>

Creates a GivenStage for testing an aggregate using the command class as the aggregate type.

fun <C : Any, S : Any> aggregateVerifier(commandAggregateType: Class<C>, stateAggregateType: Class<S>, aggregateId: String = generateGlobalId(), tenantId: String = TenantId.DEFAULT_TENANT_ID, stateAggregateFactory: StateAggregateFactory = ConstructorStateAggregateFactory, eventStore: EventStore = InMemoryEventStore(), serviceProvider: ServiceProvider = SimpleServiceProvider()): GivenStage<S>

Creates a GivenStage for testing an aggregate with explicit command and state types.