aggregateVerifier

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.

This extension function on Class initializes the testing framework with aggregate metadata derived from the command class annotation. It sets up the necessary components for testing aggregate behavior including event store, state factory, and service provider.

Example:

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

Return

a GivenStage instance ready for chaining test expectations

Parameters

C

the type of the command aggregate class

S

the type of the state aggregate

aggregateId

the unique identifier for the aggregate instance, defaults to a generated global ID

tenantId

the tenant identifier for multi-tenant scenarios, defaults to DEFAULT_TENANT_ID

stateAggregateFactory

factory for creating state aggregate instances, defaults to ConstructorStateAggregateFactory

eventStore

the event store implementation for event sourcing, defaults to InMemoryEventStore for isolated testing

serviceProvider

container for dependency injection, defaults to SimpleServiceProvider

Throws

if aggregate metadata cannot be resolved from the class annotations


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.

This static method provides an alternative way to initialize aggregate testing when you need to specify both command and state aggregate types explicitly. It internally delegates to the extension function on the command aggregate type.

Example:

aggregateVerifier(Cart::class.java, CartState::class.java)
.given(CartItemAdded(...))
.whenCommand(RemoveCartItem(productIds = setOf("item1")))
.expectEventType(CartItemRemoved::class)
.expectState { items.assert().isEmpty() }
.verify()

Return

a GivenStage instance ready for chaining test expectations

Parameters

C

the type of the command aggregate

S

the type of the state aggregate

commandAggregateType

the Class representing the command aggregate type

stateAggregateType

the Class representing the state aggregate type (used for type safety)

aggregateId

the unique identifier for the aggregate instance, defaults to a generated global ID

tenantId

the tenant identifier for multi-tenant scenarios, defaults to DEFAULT_TENANT_ID

stateAggregateFactory

factory for creating state aggregate instances, defaults to ConstructorStateAggregateFactory

eventStore

the event store implementation for event sourcing, defaults to InMemoryEventStore for isolated testing

serviceProvider

container for dependency injection, defaults to SimpleServiceProvider

Throws

if aggregate metadata cannot be resolved from the command class