Interface TestExecutor<T>
- Type Parameters:
T- The type of Aggregate under test
- All Known Implementing Classes:
AggregateTestFixture
when(Object), which dispatches a command on this fixture's Command Bus.- Since:
- 0.6
- Author:
- Allard Buijze
-
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.default ResultValidatorandThenTimeAdvancesTo(Instant newPointInTime) Deprecated.default ResultValidatorandThenTimeElapses(Duration elapsedTime) Deprecated.in favor ofwhenTimeElapses(Duration).Returns the time as "known" by the fixture.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 aggregateIdentifier, Consumer<T> aggregateConsumer) Invokes the givenaggregateConsumerafter loading an aggregate of typeTbased on the givenaggregateIdentifier.whenThenTimeAdvancesTo(Instant newPointInTime) Deprecated.since 4.6.whenThenTimeElapses(Duration elapsedTime) Deprecated.since 4.6.default ResultValidator<T> whenTimeAdvancesTo(Instant newPointInTime) Simulates the time advancing in the current given state using anInstantas the unit of time.default ResultValidator<T> whenTimeElapses(Duration elapsedTime) Simulates the time elapsing in the current given state using aDurationas the unit of time.
-
Method Details
-
when
Dispatches 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.- Parameters:
command- The command to execute- Returns:
- a ResultValidator that can be used to validate the resulting actions of the command execution
-
when
Dispatches 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.- 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
-
andGiven
Configures 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.- Parameters:
domainEvents- the domain events the event store should return- Returns:
- a TestExecutor instance that can execute the test with this configuration
-
andGiven
Configures 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.- Parameters:
domainEvents- the domain events the event store should return- Returns:
- a TestExecutor instance that can execute the test with this configuration
-
andGivenCommands
Configures the givencommandsas the command that will provide the "given" events. The commands are executed, and the resulting stored events are captured.- Parameters:
commands- the domain events the event store should return- Returns:
- a TestExecutor instance that can execute the test with this configuration
-
andGivenCommands
Configures the givencommandsas the command that will provide the "given" events. The commands are executed, and the resulting stored events are captured.- Parameters:
commands- the domain events the event store should return- Returns:
- a TestExecutor instance that can execute the test with this configuration
-
andGivenCurrentTime
Use this method to indicate a specific moment as the initial current time "known" by the fixture at the start of the given state.- 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
Instant currentTime()Returns 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".- Returns:
- the simulated "current time" of the fixture.
-
andThenTimeElapses
Deprecated.in favor ofwhenTimeElapses(Duration). This function incorrectly suggests you can proceed with other operations after calling it, which is made impossible due to theResultValidatorreturn typeSimulates 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.- 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.since 4.6. UsewhenTimeAdvancesTo(Instant)methodSimulates 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.- 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
-
whenTimeElapses
Simulates 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
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.- 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
-
andThenTimeAdvancesTo
Deprecated.in favor ofwhenTimeAdvancesTo(Instant). This function incorrectly suggests you can proceed with other operations after calling it, which is made impossible due to theResultValidatorreturn typeSimulates 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.- 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.since 4.6. UsewhenTimeAdvancesTo(Instant)methodSimulates 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.- 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
-
whenTimeAdvancesTo
Simulates 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
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.- 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
-
whenConstructing
Invokes 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.- 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
Invokes 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.- Parameters:
aggregateIdentifier- The identifier of the aggregate toRepository.load(String).aggregateConsumer- 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.
-
whenTimeAdvancesTo(Instant).