Interface TestExecutor<T>

Type Parameters:
T - The type of Aggregate under test
All Known Implementing Classes:
AggregateTestFixture

public interface TestExecutor<T>
Interface describing the operations available on a test fixture in the execution stage. In this stage, there is only on operation: when(Object), which dispatches a command on this fixture's Command Bus.
Since:
0.6
Author:
Allard Buijze
  • Method Details

    • when

      ResultValidator<T> when(Object command)
      Dispatches the given command to the appropriate command handler and records all activity in the fixture for result validation. If the given command is a CommandMessage instance, it will be dispatched as-is. Any other object will cause the given command to be wrapped in a CommandMessage as 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

      ResultValidator<T> when(Object command, Map<String,?> metaData)
      Dispatches the given command and meta-data to the appropriate command handler and records all activity in the fixture for result validation. If the given command is a CommandMessage instance, it will be dispatched as-is, with given additional metaData. Any other object will cause the given command to be wrapped in a CommandMessage as its payload.
      Parameters:
      command - The command to execute
      metaData - The meta-data to attach to the
      Returns:
      a ResultValidator that can be used to validate the resulting actions of the command execution
    • andGiven

      TestExecutor<T> andGiven(Object... domainEvents)
      Configures the given domainEvents as the "given" events. These are the events returned by the event store when an aggregate is loaded.

      If an item in the given domainEvents implements Message, 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

      TestExecutor<T> andGiven(List<?> domainEvents)
      Configures the given domainEvents as the "given" events. These are the events returned by the event store when an aggregate is loaded.

      If an item in the list implements Message, 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

      TestExecutor<T> andGivenCommands(Object... commands)
      Configures the given commands as 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

      TestExecutor<T> andGivenCommands(List<?> commands)
      Configures the given commands as 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

      TestExecutor<T> 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.
      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 default ResultValidator andThenTimeElapses(Duration elapsedTime)
      Deprecated.
      in favor of whenTimeElapses(Duration). This function incorrectly suggests you can proceed with other operations after calling it, which is made impossible due to the ResultValidator return type
      Simulates the time elapsing in the current given state using a Duration as the unit of time. This can be useful when the time between given events is of importance, for example when leveraging the DeadlineManager to schedule deadlines in the context of a given Aggregate.
      Parameters:
      elapsedTime - a Duration specifying the amount of time that will elapse
      Returns:
      a ResultValidator that can be used to validate the resulting actions of the command execution
    • whenThenTimeElapses

      @Deprecated ResultValidator<T> whenThenTimeElapses(Duration elapsedTime)
      Deprecated.
      since 4.6. Use whenTimeAdvancesTo(Instant) method
      Simulates the time elapsing in the current given state using a Duration as the unit of time. This can be useful when the time between given events is of importance, for example when leveraging the DeadlineManager to schedule deadlines in the context of a given Aggregate.
      Parameters:
      elapsedTime - a Duration specifying the amount of time that will elapse
      Returns:
      a ResultValidator that can be used to validate the resulting actions of the command execution
    • whenTimeElapses

      default ResultValidator<T> whenTimeElapses(Duration elapsedTime)
      Simulates the time elapsing in the current given state using a Duration as the unit of time. This can be useful when the time between given events is of importance, for example when leveraging the DeadlineManager to 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 - a Duration specifying the amount of time that will elapse
      Returns:
      a ResultValidator that can be used to validate the resulting actions of the command execution
    • andThenTimeAdvancesTo

      @Deprecated default ResultValidator andThenTimeAdvancesTo(Instant newPointInTime)
      Deprecated.
      in favor of whenTimeAdvancesTo(Instant). This function incorrectly suggests you can proceed with other operations after calling it, which is made impossible due to the ResultValidator return type
      Simulates the time advancing in the current given state using an Instant as the unit of time. This can be useful when the time between given events is of importance, for example when leveraging the DeadlineManager to schedule deadlines in the context of a given Aggregate.
      Parameters:
      newPointInTime - an Instant specifying the amount of time to advance the clock to
      Returns:
      a ResultValidator that can be used to validate the resulting actions of the command execution
    • whenThenTimeAdvancesTo

      @Deprecated ResultValidator<T> whenThenTimeAdvancesTo(Instant newPointInTime)
      Deprecated.
      since 4.6. Use whenTimeAdvancesTo(Instant) method
      Simulates the time advancing in the current given state using an Instant as the unit of time. This can be useful when the time between given events is of importance, for example when leveraging the DeadlineManager to schedule deadlines in the context of a given Aggregate.
      Parameters:
      newPointInTime - an Instant specifying the amount of time to advance the clock to
      Returns:
      a ResultValidator that can be used to validate the resulting actions of the command execution
    • whenTimeAdvancesTo

      default ResultValidator<T> whenTimeAdvancesTo(Instant newPointInTime)
      Simulates the time advancing in the current given state using an Instant as the unit of time. This can be useful when the time between given events is of importance, for example when leveraging the DeadlineManager to 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 - an Instant specifying the amount of time to advance the clock to
      Returns:
      a ResultValidator that can be used to validate the resulting actions of the command execution
    • whenConstructing

      ResultValidator<T> whenConstructing(Callable<T> aggregateFactory)
      Invokes the given aggregateFactory expecting an aggregate instance of type T to be returned.

      All activity is recorded in the fixture for result validation. The aggregateFactory typically refers to one of the aggregate's constructors.

      You should use this when-phase operation whenever you do not use the CommandHandler annotation on the aggregate's methods, nor have registered an external command handler invoking the Repository.

      Parameters:
      aggregateFactory - A callable operation expecting an aggregate instance of type T to be returned. This typically is an aggregate constructor invocation.
      Returns:
      a ResultValidator that can be used to validate the resulting actions of executing the given aggregateFactory.
    • whenInvoking

      ResultValidator<T> whenInvoking(String aggregateIdentifier, Consumer<T> aggregateConsumer)
      Invokes the given aggregateConsumer after loading an aggregate of type T based on the given aggregateIdentifier.

      All activity is recorded in the fixture for result validation.

      You should use this when-phase operation whenever you do not use the CommandHandler annotation on the aggregate's methods, nor have registered an external command handler invoking the Repository.

      Parameters:
      aggregateIdentifier - The identifier of the aggregate to Repository.load(String).
      aggregateConsumer - A lambda providing an aggregate instance of type T based on the given aggregateIdentifier.
      Returns:
      a ResultValidator that can be used to validate the resulting actions of executing the given aggregateConsumer.