whenCommand

fun whenCommand(command: Any, requestId: String = "request-", expectedVersion: Int? = null, scope: Scope? = null, headers: Map<String, String> = emptyMap(), operator: Operator? = null, caller: Caller? = null, expect: Expectations<S>.() -> Unit)

Sends command through the kernel and checks its outcome in expect. An exception the decide function throws fails the specification, unless expect checks it with Expectations.expectError.

caller sends it, the specification's by default (aggregateSpec, asCaller), as the gateway admits a caller's command: in its scope, by its operator, with its application as the request fact app_id. scope names another scope it acts in, as a caller crossing scopes does (its operator then acting elsewhere); headers adds request facts (a scheduled command's me.ahoo.wow.api.schedule.ScheduleContext.headers, say) and operator replaces the caller's. Without a caller, the command is an anonymous one in scope, none by default.

A command whose body names its aggregate (me.ahoo.wow.api.annotation.AggregateId) names the specification's, or none: one that names another fails the specification, as admission refuses it.