Class AggregateTestFixture<T>
- Type Parameters:
T- The type of Aggregate tested in this Fixture
- All Implemented Interfaces:
FixtureConfiguration<T>,TestExecutor<T>
FixtureConfiguration.- Since:
- 0.6
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionAggregateTestFixture(Class<T> aggregateType) Initializes a new given-when-then style test fixture for the givenaggregateType. -
Method Summary
Modifier and TypeMethodDescriptionConfigures the givendomainEventsas the "given" events.Configures the givendomainEventsas the "given" events.andGivenCommands(Object... commands) Configures the givencommandsas the command that will provide the "given" events.andGivenCommands(List<?> commands) Configures the givencommandsas the command that will provide the "given" events.andGivenCurrentTime(Instant currentTime) Use this method to indicate a specific moment as the initial current time "known" by the fixture at the start of the given state.Returns the time as "known" by the fixture.Returns the command bus used by this fixture.Returns the event bus used by this fixture.Returns the event store used by this fixture.Returns the repository used by this fixture.Configures the givendomainEventsas the "given" events.Configures the givendomainEventsas the "given" events.givenCommands(Object... commands) Configures the givencommandsas to execute against the aggregate under test to initiate the given-phase.givenCommands(List<?> commands) Configures the givencommandsas to execute against the aggregate under test to initiate the given-phase.givenCurrentTime(Instant currentTime) Use this method to indicate a specific moment as the initial current time "known" by the fixture at the start of the given state.Indicates that no relevant activities like commands or events have occurred in the past.givenState(Supplier<T> aggregate) Sets the aggregate instance as supplied by givenaggregateStateas the initial state for a test case.protected voidhandleDeadline(ScopeDescriptor aggregateDescriptor, DeadlineMessage<?> deadlineMessage) Handles the givendeadlineMessagein the aggregate described by the givenaggregateDescriptor.registerAggregateFactory(AggregateFactory<T> aggregateFactory) Registers the givenaggregateFactorywith the fixture.registerAnnotatedCommandHandler(Object annotatedCommandHandler) Registers anannotatedCommandHandlerwith this fixture.registerCommandDispatchInterceptor(MessageDispatchInterceptor<? super CommandMessage<?>> commandDispatchInterceptor) Register aMessageDispatchInterceptorforCommandMessages which will be invoked before any command is dispatched on theCommandBusto perform a task specified in the interceptor.registerCommandHandler(Class<?> payloadType, MessageHandler<CommandMessage<?>> commandHandler) Registers acommandHandlerto handle commands of the givencommandTypewith the command bus used by this fixture.registerCommandHandler(String commandName, MessageHandler<CommandMessage<?>> commandHandler) Registers acommandHandlerto handle commands of the givencommandTypewith the command bus used by this fixture.registerCommandHandlerInterceptor(MessageHandlerInterceptor<? super CommandMessage<?>> commandHandlerInterceptor) Register aMessageHandlerInterceptorforCommandMessages which will be invoked before or after the command has been dispatched on theCommandBusto perform a task specified in the interceptor.registerCommandTargetResolver(CommandTargetResolver commandTargetResolver) Registers theCommandTargetResolverwithin this fixture.registerDeadlineDispatchInterceptor(MessageDispatchInterceptor<? super DeadlineMessage<?>> deadlineDispatchInterceptor) Registers a deadline dispatch interceptor which will always be invoked before a deadline is dispatched (scheduled) on theDeadlineManagerto perform a task specified in the interceptor.registerDeadlineHandlerInterceptor(MessageHandlerInterceptor<? super DeadlineMessage<?>> deadlineHandlerInterceptor) Registers a deadline handler interceptor which will always be invoked before a deadline is handled to perform a task specified in the interceptor.registerFieldFilter(FieldFilter fieldFilter) Registers the givenfieldFilter, which is used to define which Fields are used when comparing objects.registerHandlerDefinition(HandlerDefinition handlerDefinition) Registers aHandlerDefinitionwithin this fixture.registerHandlerEnhancerDefinition(HandlerEnhancerDefinition handlerEnhancerDefinition) Registers aHandlerEnhancerDefinitionwithin this fixture.registerIgnoredField(Class<?> declaringClass, String fieldName) Indicates that a field with givenfieldName, which is declared in givendeclaringClassis ignored when performing deep equality checks.registerInjectableResource(Object resource) Registers a resource that is eligible for injection in handler method (e.g. methods annotated with@CommandHandler,@EventSourcingHandlerandEventHandler.registerParameterResolverFactory(ParameterResolverFactory parameterResolverFactory) Registers aParameterResolverFactorywithin this fixture.registerRepository(Repository<T> repository) Registers an arbitraryrepositorywith the fixture.registerRepositoryProvider(RepositoryProvider repositoryProvider) Registers repository provider with the fixture.voidsetReportIllegalStateChange(boolean reportIllegalStateChange) Sets whether or not the fixture should detect and report state changes that occur outside of Event Handler methods.Configures the fixture for state stored aggregates.Dispatches the given command to the appropriate command handler and records all activity in the fixture for result validation.Dispatches the given command and meta-data to the appropriate command handler and records all activity in the fixture for result validation.whenConstructing(Callable<T> aggregateFactory) Invokes the givenaggregateFactoryexpecting an aggregate instance of typeTto be returned.whenInvoking(String aggregateId, Consumer<T> aggregateSupplier) Invokes the givenaggregateConsumerafter loading an aggregate of typeTbased on the givenaggregateIdentifier.whenThenTimeAdvancesTo(Instant newPointInTime) Deprecated.whenThenTimeElapses(Duration elapsedTime) Deprecated.whenTimeAdvancesTo(Instant newPointInTime) Simulates the time advancing in the current given state using anInstantas the unit of time.whenTimeElapses(Duration elapsedTime) Simulates the time elapsing in the current given state using aDurationas the unit of time.final FixtureConfiguration<T> withSubtypes(Class<? extends T>... subtypes) Registers subtypes of this aggregate to support aggregate polymorphism.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.test.aggregate.FixtureConfiguration
registerInjectableResourcesMethods inherited from interface org.axonframework.test.aggregate.TestExecutor
andThenTimeAdvancesTo, andThenTimeElapses
-
Constructor Details
-
AggregateTestFixture
Initializes a new given-when-then style test fixture for the givenaggregateType.- Parameters:
aggregateType- the aggregate to initialize the test fixture for
-
-
Method Details
-
withSubtypes
Description copied from interface:FixtureConfigurationRegisters subtypes of this aggregate to support aggregate polymorphism. Command Handlers defined on this subtype will be considered part of this aggregate's handlers.- Specified by:
withSubtypesin interfaceFixtureConfiguration<T>- Parameters:
subtypes- subtypes in this polymorphic hierarchy- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
useStateStorage
Description copied from interface:FixtureConfigurationConfigures the fixture for state stored aggregates. This will register an in-memorywith this fixture. Should be used before callinginvalid reference
org.axonframework.commandhandling.model.RepositoryFixtureConfiguration.givenState(Supplier)orFixtureConfiguration.givenCommands(List)(Supplier)}.- Specified by:
useStateStoragein interfaceFixtureConfiguration<T>- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerRepository
Description copied from interface:FixtureConfigurationRegisters an arbitraryrepositorywith the fixture. The repository must be wired with the Event Store of this test fixture. Should not be used in combination withFixtureConfiguration.registerAggregateFactory(org.axonframework.eventsourcing.AggregateFactory), as that will overwrite any repository previously registered.- Specified by:
registerRepositoryin interfaceFixtureConfiguration<T>- Parameters:
repository- The repository to use in the test case- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerRepositoryProvider
Description copied from interface:FixtureConfigurationRegisters repository provider with the fixture. If an aggregate being tested spawns new aggregates, this provider should be registered. Otherwise, it is not going to be invoked.- Specified by:
registerRepositoryProviderin interfaceFixtureConfiguration<T>- Parameters:
repositoryProvider- provides repositories for specified aggregate types- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerAggregateFactory
Description copied from interface:FixtureConfigurationRegisters the givenaggregateFactorywith the fixture. The repository used by the fixture will use the given factory to create new aggregate instances. Defaults to an Aggregate Factory that uses the no-arg constructor to create new instances. Should not be used in combination withFixtureConfiguration.registerRepository(Repository), as that will overwrite any aggregate factory previously registered.- Specified by:
registerAggregateFactoryin interfaceFixtureConfiguration<T>- Parameters:
aggregateFactory- The Aggregate Factory to create empty aggregates with- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerAnnotatedCommandHandler
Description copied from interface:FixtureConfigurationRegisters anannotatedCommandHandlerwith this fixture. This will register this command handler with the command bus used in this fixture.- Specified by:
registerAnnotatedCommandHandlerin interfaceFixtureConfiguration<T>- Parameters:
annotatedCommandHandler- The command handler to register for this test- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerCommandHandler
public FixtureConfiguration<T> registerCommandHandler(Class<?> payloadType, MessageHandler<CommandMessage<?>> commandHandler) Description copied from interface:FixtureConfigurationRegisters acommandHandlerto handle commands of the givencommandTypewith the command bus used by this fixture.- Specified by:
registerCommandHandlerin interfaceFixtureConfiguration<T>- Parameters:
payloadType- The type of command to register the handler forcommandHandler- The handler to register- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerCommandHandler
public FixtureConfiguration<T> registerCommandHandler(String commandName, MessageHandler<CommandMessage<?>> commandHandler) Description copied from interface:FixtureConfigurationRegisters acommandHandlerto handle commands of the givencommandTypewith the command bus used by this fixture.- Specified by:
registerCommandHandlerin interfaceFixtureConfiguration<T>- Parameters:
commandName- The name of the command to register the handler forcommandHandler- The handler to register- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerInjectableResource
Description copied from interface:FixtureConfigurationRegisters a resource that is eligible for injection in handler method (e.g. methods annotated with@CommandHandler,@EventSourcingHandlerandEventHandler. These resource must be registered before registering any command handler.- Specified by:
registerInjectableResourcein interfaceFixtureConfiguration<T>- Parameters:
resource- the resource eligible for injection- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerParameterResolverFactory
public FixtureConfiguration<T> registerParameterResolverFactory(ParameterResolverFactory parameterResolverFactory) Description copied from interface:FixtureConfigurationRegisters aParameterResolverFactorywithin this fixture. The givenparameterResolverFactorywill be added to the other parameter resolver factories introduced throughClasspathParameterResolverFactory.forClass(Class)and theSimpleResourceParameterResolverFactoryadding the registered resources (withFixtureConfiguration.registerInjectableResource(Object). The genericTis used as input for theClasspathParameterResolverFactory#forClass(Class)operation.- Specified by:
registerParameterResolverFactoryin interfaceFixtureConfiguration<T>- Parameters:
parameterResolverFactory- theParameterResolverto register within this fixture- Returns:
- the current FixtureConfiguration, for fluent interfacing
- See Also:
-
registerCommandDispatchInterceptor
public FixtureConfiguration<T> registerCommandDispatchInterceptor(MessageDispatchInterceptor<? super CommandMessage<?>> commandDispatchInterceptor) Description copied from interface:FixtureConfigurationRegister aMessageDispatchInterceptorforCommandMessages which will be invoked before any command is dispatched on theCommandBusto perform a task specified in the interceptor. For example by addingMetaDataor throwing an exception based on the command.- Specified by:
registerCommandDispatchInterceptorin interfaceFixtureConfiguration<T>- Parameters:
commandDispatchInterceptor- theMessageDispatchInterceptorforCommandMessages to be added to this fixture'sCommandBus- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerCommandHandlerInterceptor
public FixtureConfiguration<T> registerCommandHandlerInterceptor(MessageHandlerInterceptor<? super CommandMessage<?>> commandHandlerInterceptor) Description copied from interface:FixtureConfigurationRegister aMessageHandlerInterceptorforCommandMessages which will be invoked before or after the command has been dispatched on theCommandBusto perform a task specified in the interceptor. It could for example block the command for security reasons or add auditing to the command bus- Specified by:
registerCommandHandlerInterceptorin interfaceFixtureConfiguration<T>- Parameters:
commandHandlerInterceptor- theMessageHandlerInterceptorforCommandMessages to be added to this fixture'sCommandBus- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerDeadlineDispatchInterceptor
public FixtureConfiguration<T> registerDeadlineDispatchInterceptor(MessageDispatchInterceptor<? super DeadlineMessage<?>> deadlineDispatchInterceptor) Description copied from interface:FixtureConfigurationRegisters a deadline dispatch interceptor which will always be invoked before a deadline is dispatched (scheduled) on theDeadlineManagerto perform a task specified in the interceptor.- Specified by:
registerDeadlineDispatchInterceptorin interfaceFixtureConfiguration<T>- Parameters:
deadlineDispatchInterceptor- the interceptor for dispatching (scheduling) deadlines- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerDeadlineHandlerInterceptor
public FixtureConfiguration<T> registerDeadlineHandlerInterceptor(MessageHandlerInterceptor<? super DeadlineMessage<?>> deadlineHandlerInterceptor) Description copied from interface:FixtureConfigurationRegisters a deadline handler interceptor which will always be invoked before a deadline is handled to perform a task specified in the interceptor.- Specified by:
registerDeadlineHandlerInterceptorin interfaceFixtureConfiguration<T>- Parameters:
deadlineHandlerInterceptor- the interceptor for handling deadlines- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerFieldFilter
Description copied from interface:FixtureConfigurationRegisters the givenfieldFilter, which is used to define which Fields are used when comparing objects. TheResultValidator.expectEvents(Object...)andResultValidator.expectResultMessagePayload(Object), for example, use this filter. When multiple filters are registered, a Field must be accepted by all registered filters in order to be accepted. By default, all Fields are included in the comparison.- Specified by:
registerFieldFilterin interfaceFixtureConfiguration<T>- Parameters:
fieldFilter- The FieldFilter that defines which fields to include in the comparison- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerIgnoredField
Description copied from interface:FixtureConfigurationIndicates that a field with givenfieldName, which is declared in givendeclaringClassis ignored when performing deep equality checks.- Specified by:
registerIgnoredFieldin interfaceFixtureConfiguration<T>- Parameters:
declaringClass- The class declaring the fieldfieldName- The name of the field- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerHandlerDefinition
Description copied from interface:FixtureConfigurationRegisters aHandlerDefinitionwithin this fixture. The givenhandlerDefinitionis added to the handler definitions introduced throughClasspathHandlerDefinition.forClass(Class). The genericTis used as input for theClasspathHandlerDefinition#forClass(Class)operation.- Specified by:
registerHandlerDefinitionin interfaceFixtureConfiguration<T>- Parameters:
handlerDefinition- used to create concrete handlers- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerHandlerEnhancerDefinition
public FixtureConfiguration<T> registerHandlerEnhancerDefinition(HandlerEnhancerDefinition handlerEnhancerDefinition) Description copied from interface:FixtureConfigurationRegisters aHandlerEnhancerDefinitionwithin this fixture. This givenhandlerEnhancerDefinitionis added to the handler enhancer definitions introduced throughClasspathHandlerEnhancerDefinition.forClass(Class). The genericTis used as input for theClasspathHandlerEnhancerDefinition#forClass(Class)operation.- Specified by:
registerHandlerEnhancerDefinitionin interfaceFixtureConfiguration<T>- Parameters:
handlerEnhancerDefinition- theHandlerEnhancerDefinitionto register within this fixture- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
registerCommandTargetResolver
public FixtureConfiguration<T> registerCommandTargetResolver(CommandTargetResolver commandTargetResolver) Description copied from interface:FixtureConfigurationRegisters theCommandTargetResolverwithin this fixture. ThecommandTargetResolverwill replace the default implementation (defined by theAggregateAnnotationCommandHandlerwithin this fixture.- Specified by:
registerCommandTargetResolverin interfaceFixtureConfiguration<T>- Parameters:
commandTargetResolver- theCommandTargetResolverused to resolve an Aggregate for a given command- Returns:
- the current FixtureConfiguration, for fluent interfacing
-
given
Description copied from interface:FixtureConfigurationConfigures the givendomainEventsas the "given" events. These are the events returned by the event store when an aggregate is loaded. If an item in the givendomainEventsimplementsMessage, the payload andMetaDatafrom thatMessageare copied into a newly createdDomainEventMessage. Otherwise, aDomainEventMessagewith the item as payload and emptyMetaDatais created.Note that transitioning to the returned
TestExecutorwill clear any previously defined "given" state to ensure the fixture can run a clean test environment.- Specified by:
givenin interfaceFixtureConfiguration<T>- Parameters:
domainEvents- The domain events the event store should return.- Returns:
- A
TestExecutorinstance that can execute the test with this configuration.
-
andGiven
Description copied from interface:TestExecutorConfigures the givendomainEventsas the "given" events. These are the events returned by the event store when an aggregate is loaded. If an item in the givendomainEventsimplementsMessage, the payload and meta-data from that message are copied into a newly created Domain Event Message. Otherwise, a Domain Event Message with the item as payload and empty meta-data is created.- Specified by:
andGivenin interfaceTestExecutor<T>- Parameters:
domainEvents- the domain events the event store should return- Returns:
- a TestExecutor instance that can execute the test with this configuration
-
givenNoPriorActivity
Description copied from interface:FixtureConfigurationIndicates that no relevant activities like commands or events have occurred in the past. This also means that no previous state is present in the repository.- Specified by:
givenNoPriorActivityin interfaceFixtureConfiguration<T>- Returns:
- A
TestExecutorinstance that can execute the test with this configuration.
-
givenState
Description copied from interface:FixtureConfigurationSets the aggregate instance as supplied by givenaggregateStateas the initial state for a test case.Usage of this method is highly discouraged for event sourced aggregates. In that case, use
FixtureConfiguration.given(Object...)to specify historic events.Note that transitioning to the returned
TestExecutorwill clear any previously defined "given" state to ensure the fixture can run a clean test environment.- Specified by:
givenStatein interfaceFixtureConfiguration<T>- Parameters:
aggregate- ASupplierproviding the state to use as starting point for this fixture.- Returns:
- A
TestExecutorinstance that can execute the test with this configuration.
-
given
Description copied from interface:FixtureConfigurationConfigures the givendomainEventsas the "given" events. These are the events returned by the event store when an aggregate is loaded. If an item in the list implementsMessage, the payload andMetaDatafrom thatMessageare copied into a newly createdDomainEventMessage. Otherwise, aDomainEventMessagewith the item as payload and emptyMetaDatais created.Note that transitioning to the returned
TestExecutorwill clear any previously defined "given" state to ensure the fixture can run a clean test environment.- Specified by:
givenin interfaceFixtureConfiguration<T>- Parameters:
domainEvents- The domain events the event store should return.- Returns:
- A
TestExecutorinstance that can execute the test with this configuration.
-
andGiven
Description copied from interface:TestExecutorConfigures the givendomainEventsas the "given" events. These are the events returned by the event store when an aggregate is loaded. If an item in the list implementsMessage, the payload and meta-data from that message are copied into a newly created Domain Event Message. Otherwise, a Domain Event Message with the item as payload and empty meta-data is created.- Specified by:
andGivenin interfaceTestExecutor<T>- Parameters:
domainEvents- the domain events the event store should return- Returns:
- a TestExecutor instance that can execute the test with this configuration
-
givenCommands
Description copied from interface:FixtureConfigurationConfigures the givencommandsas to execute against the aggregate under test to initiate the given-phase. The commands are executed, and the resulting stored events are captured.Note that transitioning to the returned
TestExecutorwill clear any previously defined "given" state to ensure the fixture can run a clean test environment.- Specified by:
givenCommandsin interfaceFixtureConfiguration<T>- Parameters:
commands- The commands to execute against the aggregate under test to initiate the given-phase.- Returns:
- A
TestExecutorinstance that can execute the test with this configuration.
-
andGivenCommands
Description copied from interface:TestExecutorConfigures the givencommandsas the command that will provide the "given" events. The commands are executed, and the resulting stored events are captured.- Specified by:
andGivenCommandsin interfaceTestExecutor<T>- Parameters:
commands- the domain events the event store should return- Returns:
- a TestExecutor instance that can execute the test with this configuration
-
givenCommands
Description copied from interface:FixtureConfigurationConfigures the givencommandsas to execute against the aggregate under test to initiate the given-phase. The commands are executed, and the resulting stored events are captured.Note that transitioning to the returned
TestExecutorwill clear any previously defined "given" state to ensure the fixture can run a clean test environment.- Specified by:
givenCommandsin interfaceFixtureConfiguration<T>- Parameters:
commands- The commands to execute against the aggregate under test to initiate the given-phase.- Returns:
- A
TestExecutorinstance that can execute the test with this configuration.
-
andGivenCommands
Description copied from interface:TestExecutorConfigures the givencommandsas the command that will provide the "given" events. The commands are executed, and the resulting stored events are captured.- Specified by:
andGivenCommandsin interfaceTestExecutor<T>- Parameters:
commands- the domain events the event store should return- Returns:
- a TestExecutor instance that can execute the test with this configuration
-
givenCurrentTime
Description copied from interface:FixtureConfigurationUse this method to indicate a specific moment as the initial current time "known" by the fixture at the start of the given state.Note that transitioning to the returned
TestExecutorwill clear any previously defined "given" state to ensure the fixture can run a clean test environment.- Specified by:
givenCurrentTimein interfaceFixtureConfiguration<T>- Parameters:
currentTime- AnInstantdefining the simulated "current time" at which the given state is initialized.- Returns:
- A
TestExecutorinstance that can execute the test with this configuration.
-
andGivenCurrentTime
Description copied from interface:TestExecutorUse this method to indicate a specific moment as the initial current time "known" by the fixture at the start of the given state.- Specified by:
andGivenCurrentTimein interfaceTestExecutor<T>- Parameters:
currentTime- The simulated "current time" at which the given state is initialized- Returns:
- a TestExecutor instance that can execute the test with this configuration
-
currentTime
Description copied from interface:TestExecutorReturns the time as "known" by the fixture. This is the time at which the fixture was created, plus the amount of time the fixture was told to simulate a "wait".- Specified by:
currentTimein interfaceTestExecutor<T>- Returns:
- the simulated "current time" of the fixture.
-
whenTimeElapses
Description copied from interface:TestExecutorSimulates the time elapsing in the current given state using aDurationas the unit of time. This can be useful when the time between given events is of importance, for example when leveraging theDeadlineManagerto schedule deadlines in the context of a given Aggregate.Note: As this method is added to the interface as a replacement for the deprecated
TestExecutor.whenThenTimeAdvancesTo(Instant)method, and in case there are other implementations by 3rd party libraries, this method is changed to a default method that rely on the deprecated method so that there is no breaking changes in the API in case an external implementation of this interface. Nevertheless, the recommended approach is to override this implementation.- Specified by:
whenTimeElapsesin interfaceTestExecutor<T>- Parameters:
elapsedTime- aDurationspecifying the amount of time that will elapse- Returns:
- a
ResultValidatorthat can be used to validate the resulting actions of the command execution
-
whenThenTimeElapses
Deprecated.Description copied from interface:TestExecutorSimulates the time elapsing in the current given state using aDurationas the unit of time. This can be useful when the time between given events is of importance, for example when leveraging theDeadlineManagerto schedule deadlines in the context of a given Aggregate.- Specified by:
whenThenTimeElapsesin interfaceTestExecutor<T>- Parameters:
elapsedTime- aDurationspecifying the amount of time that will elapse- Returns:
- a
ResultValidatorthat can be used to validate the resulting actions of the command execution
-
whenTimeAdvancesTo
Description copied from interface:TestExecutorSimulates the time advancing in the current given state using anInstantas the unit of time. This can be useful when the time between given events is of importance, for example when leveraging theDeadlineManagerto schedule deadlines in the context of a given Aggregate.Note: As this method is added to the interface as a replacement for the deprecated
TestExecutor.whenThenTimeAdvancesTo(Instant)method, and in case there are other implementations by 3rd party libraries, this method is changed to a default method that rely on the deprecated method so that there is no breaking changes in the API in case an external implementation of this interface. Nevertheless, the recommended approach is to override this implementation.- Specified by:
whenTimeAdvancesToin interfaceTestExecutor<T>- Parameters:
newPointInTime- anInstantspecifying the amount of time to advance the clock to- Returns:
- a
ResultValidatorthat can be used to validate the resulting actions of the command execution
-
whenThenTimeAdvancesTo
Deprecated.Description copied from interface:TestExecutorSimulates the time advancing in the current given state using anInstantas the unit of time. This can be useful when the time between given events is of importance, for example when leveraging theDeadlineManagerto schedule deadlines in the context of a given Aggregate.- Specified by:
whenThenTimeAdvancesToin interfaceTestExecutor<T>- Parameters:
newPointInTime- anInstantspecifying the amount of time to advance the clock to- Returns:
- a
ResultValidatorthat can be used to validate the resulting actions of the command execution
-
when
Description copied from interface:TestExecutorDispatches the given command to the appropriate command handler and records all activity in the fixture for result validation. If the givencommandis aCommandMessageinstance, it will be dispatched as-is. Any other object will cause the givencommandto be wrapped in aCommandMessageas its payload.- Specified by:
whenin interfaceTestExecutor<T>- Parameters:
command- The command to execute- Returns:
- a ResultValidator that can be used to validate the resulting actions of the command execution
-
when
Description copied from interface:TestExecutorDispatches the given command and meta-data to the appropriate command handler and records all activity in the fixture for result validation. If the givencommandis aCommandMessageinstance, it will be dispatched as-is, with given additionalmetaData. Any other object will cause the givencommandto be wrapped in aCommandMessageas its payload.- Specified by:
whenin interfaceTestExecutor<T>- Parameters:
command- The command to executemetaData- The meta-data to attach to the- Returns:
- a ResultValidator that can be used to validate the resulting actions of the command execution
-
whenConstructing
Description copied from interface:TestExecutorInvokes the givenaggregateFactoryexpecting an aggregate instance of typeTto be returned.All activity is recorded in the fixture for result validation. The
aggregateFactorytypically refers to one of the aggregate's constructors.You should use this when-phase operation whenever you do not use the
CommandHandlerannotation on the aggregate's methods, nor haveregistered an external command handlerinvoking theRepository.- Specified by:
whenConstructingin interfaceTestExecutor<T>- Parameters:
aggregateFactory- A callable operation expecting an aggregate instance of typeTto be returned. This typically is an aggregate constructor invocation.- Returns:
- a
ResultValidatorthat can be used to validate the resulting actions of executing the givenaggregateFactory.
-
whenInvoking
Description copied from interface:TestExecutorInvokes the givenaggregateConsumerafter loading an aggregate of typeTbased on the givenaggregateIdentifier.All activity is recorded in the fixture for result validation.
You should use this when-phase operation whenever you do not use the
CommandHandlerannotation on the aggregate's methods, nor haveregistered an external command handlerinvoking theRepository.- Specified by:
whenInvokingin interfaceTestExecutor<T>- Parameters:
aggregateId- The identifier of the aggregate toRepository.load(String).aggregateSupplier- A lambda providing an aggregate instance of typeTbased on the givenaggregateIdentifier.- Returns:
- a
ResultValidatorthat can be used to validate the resulting actions of executing the givenaggregateConsumer.
-
handleDeadline
protected void handleDeadline(ScopeDescriptor aggregateDescriptor, DeadlineMessage<?> deadlineMessage) throws Exception Handles the givendeadlineMessagein the aggregate described by the givenaggregateDescriptor. Deadline message is handled in the scope of aUnitOfWork. If handling the deadline results in an exception, the exception will be wrapped in aFixtureExecutionException.- Parameters:
aggregateDescriptor- AScopeDescriptordescribing the aggregate under testdeadlineMessage- TheDeadlineMessageto be handled- Throws:
Exception
-
setReportIllegalStateChange
public void setReportIllegalStateChange(boolean reportIllegalStateChange) Description copied from interface:FixtureConfigurationSets whether or not the fixture should detect and report state changes that occur outside of Event Handler methods.- Specified by:
setReportIllegalStateChangein interfaceFixtureConfiguration<T>- Parameters:
reportIllegalStateChange- whether or not to detect and report state changes outside of Event Handler methods.
-
getCommandBus
Description copied from interface:FixtureConfigurationReturns the command bus used by this fixture. The command bus is provided for wiring purposes only, for example to support composite commands (a single command that causes the execution of one or more others).- Specified by:
getCommandBusin interfaceFixtureConfiguration<T>- Returns:
- the command bus used by this fixture
-
getEventBus
Description copied from interface:FixtureConfigurationReturns the event bus used by this fixture. The event bus is provided for wiring purposes only, for example to allow command handlers to publish events other than Domain Events. Events published on the returned event bus are recorded an evaluated in theResultValidatoroperations.- Specified by:
getEventBusin interfaceFixtureConfiguration<T>- Returns:
- the event bus used by this fixture
-
getEventStore
Description copied from interface:FixtureConfigurationReturns the event store used by this fixture. This event store is provided for wiring purposes only.- Specified by:
getEventStorein interfaceFixtureConfiguration<T>- Returns:
- the event store used by this fixture
-
getRepository
Description copied from interface:FixtureConfigurationReturns the repository used by this fixture. This repository is provided for wiring purposes only. The repository is configured to use the fixture's event store to load events.- Specified by:
getRepositoryin interfaceFixtureConfiguration<T>- Returns:
- the repository used by this fixture
-