Interface ResultValidator<T>

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

public interface ResultValidator<T>
Interface describing the operations available on the "validate result" (a.k.a. "then") stage of the test execution. The underlying fixture expects a test to have been executed successfully using a TestExecutor.

There are several things to validate:

  • the published events,
  • the stored events, and
  • the command handler's execution result, which is one of
    • a regular return value,
    • a void return value, or
    • an exception.
Since:
0.6
Author:
Allard Buijze
  • Method Details

    • expectEvents

      ResultValidator<T> expectEvents(Object... expectedEvents)
      Expect the given set of events to have been published.

      All events are compared for equality using a shallow equals comparison on all the fields of the events. This means that all assigned values on the events' fields should have a proper equals implementation.

      Note that the event identifier is ignored in the comparison.

      Parameters:
      expectedEvents - The expected events, in the exact order they are expected to be dispatched and stored.
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectEvents

      ResultValidator<T> expectEvents(EventMessage<?>... expectedEvents)
      Expect the given set of events to have been published.

      All events are compared for equality using a shallow equals comparison on all the fields of the events. This means that all assigned values on the events' fields should have a proper equals implementation.
      Additionally the metadata will be compared too.

      Note that the event identifier is ignored in the comparison.

      Parameters:
      expectedEvents - The expected events, in the exact order they are expected to be dispatched and stored.
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoEvents

      default ResultValidator<T> expectNoEvents()
      Expect no events to have been published from the command.
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectEventsMatching

      ResultValidator<T> expectEventsMatching(org.hamcrest.Matcher<? extends List<? super EventMessage<?>>> matcher)
      Expect the published events to match the given matcher.

      Note: if no events were published, the matcher receives an empty List.

      Parameters:
      matcher - The matcher to match with the actually published events
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectResultMessagePayload

      ResultValidator<T> expectResultMessagePayload(Object expectedPayload)
      Expect the command handler to return the given expectedPayload after execution. The actual and expected values are compared using their equals methods.
      Parameters:
      expectedPayload - The expected result message payload of the command execution
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectResultMessagePayloadMatching

      ResultValidator<T> expectResultMessagePayloadMatching(org.hamcrest.Matcher<?> matcher)
      Expect the command handler to return a payload that matches the given matcher after execution.
      Parameters:
      matcher - The matcher to verify the actual return value against
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectResultMessage

      ResultValidator<T> expectResultMessage(CommandResultMessage<?> expectedResultMessage)
      Expect the command handler to return the given expectedResultMessage after execution. The actual and expected values are compared using their equals methods.

      Comparison is done on message payload and meta data.

      Parameters:
      expectedResultMessage - The expected result message of the command execution
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectResultMessageMatching

      ResultValidator<T> expectResultMessageMatching(org.hamcrest.Matcher<? super CommandResultMessage<?>> matcher)
      Expect the command handler to return a value that matches the given matcher after execution.
      Parameters:
      matcher - The matcher to verify the actual result message against
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectExceptionMessage

      ResultValidator<T> expectExceptionMessage(org.hamcrest.Matcher<?> matcher)
      Expect an exception message to occur during command handler execution that matches with the given matcher.
      Parameters:
      matcher - The matcher to validate the actual exception message
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectExceptionMessage

      ResultValidator<T> expectExceptionMessage(String exceptionMessage)
      Expect the given exceptionMessage to occur during command handler execution. The actual exception message should be exactly the same as exceptionMessage.
      Parameters:
      exceptionMessage - The exception message expected from the command handler execution
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectException

      ResultValidator<T> expectException(Class<? extends Throwable> expectedException)
      Expect the given expectedException to occur during command handler execution. The actual exception should be exactly of that type, subclasses are not accepted.
      Parameters:
      expectedException - The type of exception expected from the command handler execution
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectException

      ResultValidator<T> expectException(org.hamcrest.Matcher<?> matcher)
      Expect an exception to occur during command handler execution that matches with the given matcher.
      Parameters:
      matcher - The matcher to validate the actual exception
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectExceptionDetails

      ResultValidator<T> expectExceptionDetails(Object exceptionDetails)
      Expect the given exceptionDetails to occur during command handler execution. The actual exception details should be exactly the same as exceptionDetails.
      Parameters:
      exceptionDetails - The exception details expected from the command handler execution
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectExceptionDetails

      ResultValidator<T> expectExceptionDetails(Class<?> exceptionDetails)
      Expect the given exceptionDetails type to occur during command handler execution. The actual exception details should be exactly of that type, subclasses are not accepted.
      Parameters:
      exceptionDetails - The type of exception details expected from the command handler execution
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectExceptionDetails

      ResultValidator<T> expectExceptionDetails(org.hamcrest.Matcher<?> matcher)
      Expect exception details to occur during command handler execution that matches with the given matcher.
      Parameters:
      matcher - The matcher to validate the actual exception details
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectSuccessfulHandlerExecution

      ResultValidator<T> expectSuccessfulHandlerExecution()
      Expect a successful execution of the given command handler, regardless of the actual return value.
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectState

      ResultValidator<T> expectState(Consumer<T> aggregateStateValidator)
      Provides access the the state of the Aggregate as it was stored in the repository, allowing for validation of the state of the aggregate, as it was left in the repository.

      Note that validating state on Event Sourced Aggregate is highly discouraged. Event Sourced aggregates should measure behavior exclusively by measuring emitted events.

      Parameters:
      aggregateStateValidator - a consumer that is provided with the aggregate instance, allowing it to make assertions based on the aggregate's state.
      Returns:
      the current ResultValidator, for fluent interfacing
      Throws:
      IllegalStateException - when an error in Command execution caused the Unit of Work to be rolled back.
    • expectScheduledDeadlineMatching

      ResultValidator<T> expectScheduledDeadlineMatching(Duration duration, org.hamcrest.Matcher<? super DeadlineMessage<?>> matcher)
      Asserts that a deadline scheduled after given duration matches the given matcher.
      Parameters:
      duration - the delay expected before the deadline is met
      matcher - the matcher that must match with the deadline scheduled at the given time
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectScheduledDeadline

      ResultValidator<T> expectScheduledDeadline(Duration duration, Object deadline)
      Asserts that a deadline equal to the given deadline has been scheduled after the given duration.

      Note that the source attribute of the deadline is ignored when comparing deadlines. Deadlines are compared using an "equals" check on all fields in the deadlines.

      Parameters:
      duration - the time to wait before the deadline should be met
      deadline - the expected deadline
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectScheduledDeadlineOfType

      ResultValidator<T> expectScheduledDeadlineOfType(Duration duration, Class<?> deadlineType)
      Asserts that a deadline of the given deadlineType has been scheduled after the given duration.
      Parameters:
      duration - the time to wait before the deadline is met
      deadlineType - the type of the expected deadline
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectScheduledDeadlineWithName

      ResultValidator<T> expectScheduledDeadlineWithName(Duration duration, String deadlineName)
      Asserts that a deadline with the given deadlineName has been scheduled after the given duration.
      Parameters:
      duration - the time to wait before the deadline is met
      deadlineName - the name of the expected deadline
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectScheduledDeadlineMatching

      ResultValidator<T> expectScheduledDeadlineMatching(Instant scheduledTime, org.hamcrest.Matcher<? super DeadlineMessage<?>> matcher)
      Asserts that a deadline matching the given matcher has been scheduled at the given scheduledTime.

      If the scheduledTime is calculated based on the "current time", use the TestExecutor.currentTime() to get the time to use as "current time".

      Parameters:
      scheduledTime - the time at which the deadline should be met
      matcher - the matcher defining the deadline expected
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectScheduledDeadline

      ResultValidator<T> expectScheduledDeadline(Instant scheduledTime, Object deadline)
      Asserts that a deadline equal to the given deadline has been scheduled at the given scheduledTime.

      If the scheduledTime is calculated based on the "current time", use the TestExecutor.currentTime() to get the time to use as "current time".

      Note that the source attribute of the deadline is ignored when comparing deadlines. Deadlines are compared using an "equals" check on all fields in the deadlines.

      Parameters:
      scheduledTime - the time at which the deadline is scheduled
      deadline - the expected deadline
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectScheduledDeadlineOfType

      ResultValidator<T> expectScheduledDeadlineOfType(Instant scheduledTime, Class<?> deadlineType)
      Asserts that a deadline of the given deadlineType has been scheduled at the given scheduledTime.
      Parameters:
      scheduledTime - the time at which the deadline is scheduled
      deadlineType - the type of the expected deadline
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectScheduledDeadlineWithName

      ResultValidator<T> expectScheduledDeadlineWithName(Instant scheduledTime, String deadlineName)
      Asserts that a deadline with the given deadlineName has been scheduled at the given scheduledTime.
      Parameters:
      scheduledTime - the time at which the deadline is scheduled
      deadlineName - the name of the expected deadline
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadlines

      ResultValidator<T> expectNoScheduledDeadlines()
      Asserts that no deadlines are scheduled. This means that either no deadlines were scheduled at all, all schedules have been cancelled or all scheduled deadlines have been met already.
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadlineMatching

      ResultValidator<T> expectNoScheduledDeadlineMatching(org.hamcrest.Matcher<? super DeadlineMessage<?>> matcher)
      Asserts that no deadline matching the given matcher is scheduled. Can be used to validate if a deadline has never been set or has been canceled.
      Parameters:
      matcher - the matcher defining the deadline which should not be scheduled
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadlineMatching

      ResultValidator<T> expectNoScheduledDeadlineMatching(Duration durationToScheduledTime, org.hamcrest.Matcher<? super DeadlineMessage<?>> matcher)
      Asserts that no deadline matching the given matcher should be scheduled after the given durationToScheduledTime. Can be used to validate if a deadline has never been set or has been canceled at an exact moment in time.
      Parameters:
      durationToScheduledTime - the time to wait until the trigger point of the deadline which should not be scheduled
      matcher - the matcher defining the deadline which should not be scheduled
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadline

      ResultValidator<T> expectNoScheduledDeadline(Duration durationToScheduledTime, Object deadline)
      Asserts that no deadline equal to the given deadline has been scheduled after the given durationToScheduledTime. Can be used to validate if a deadline has never been set or has been canceled at an exact moment in time.

      Note that the source attribute of the deadline is ignored when comparing deadlines. Deadlines are compared using an "equals" check on all fields in the deadlines.

      Parameters:
      durationToScheduledTime - the time to wait until the trigger point of the deadline which should not be scheduled
      deadline - the deadline which should not be scheduled
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadlineOfType

      ResultValidator<T> expectNoScheduledDeadlineOfType(Duration durationToScheduledTime, Class<?> deadlineType)
      Asserts that no deadline of the given deadlineType has been scheduled after the given durationToScheduledTime. Can be used to validate if a deadline has never been set or has been canceled at an exact moment in time.
      Parameters:
      durationToScheduledTime - the time to wait until the trigger point of the deadline which should not be scheduled
      deadlineType - the type of the deadline which should not be scheduled
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadlineWithName

      ResultValidator<T> expectNoScheduledDeadlineWithName(Duration durationToScheduledTime, String deadlineName)
      Asserts that no deadline with the given deadlineName has been scheduled after the given durationToScheduledTime. Can be used to validate if a deadline has never been set or has been canceled at an exact moment in time.
      Parameters:
      durationToScheduledTime - the time to wait until the trigger point of the deadline which should not be scheduled
      deadlineName - the name of the deadline which should not be scheduled
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadlineMatching

      ResultValidator<T> expectNoScheduledDeadlineMatching(Instant scheduledTime, org.hamcrest.Matcher<? super DeadlineMessage<?>> matcher)
      Asserts that no deadline matching the given matcher has been scheduled at the given scheduledTime. Can be used to validate if a deadline has never been set or has been canceled at an exact moment in time.

      If the scheduledTime is calculated based on the "current time", use the TestExecutor.currentTime() to get the time to use as "current time".

      Parameters:
      scheduledTime - the time at which no deadline matching the given matcher should be scheduled
      matcher - the matcher defining the deadline which should not be scheduled
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadline

      ResultValidator<T> expectNoScheduledDeadline(Instant scheduledTime, Object deadline)
      Asserts that no deadline equal to the given deadline has been scheduled at the given scheduledTime. Can be used to validate if a deadline has never been set or has been canceled at an exact moment in time.

      If the scheduledTime is calculated based on the "current time", use the TestExecutor.currentTime() to get the time to use as "current time".

      Note that the source attribute of the deadline is ignored when comparing deadlines. Deadlines are compared using an "equals" check on all fields in the deadlines.

      Parameters:
      scheduledTime - the time at which no deadline equal to the given deadline should be scheduled
      deadline - the deadline which should not be scheduled
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadlineOfType

      ResultValidator<T> expectNoScheduledDeadlineOfType(Instant scheduledTime, Class<?> deadlineType)
      Asserts that no deadline with the given deadlineType has been scheduled at the given scheduledTime. Can be used to validate if a deadline has never been set or has been canceled at an exact moment in time.
      Parameters:
      scheduledTime - the time at which no deadline of deadlineType should be scheduled
      deadlineType - the type of the deadline which should not be scheduled
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadlineWithName

      ResultValidator<T> expectNoScheduledDeadlineWithName(Instant scheduledTime, String deadlineName)
      Asserts that no deadline with the given deadlineName has been scheduled at the given scheduledTime. Can be used to validate if a deadline has never been set or has been canceled at an exact moment in time.
      Parameters:
      scheduledTime - the time at which no deadline of deadlineName should be scheduled
      deadlineName - the name of the deadline which should not be scheduled
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadlineMatching

      ResultValidator<T> expectNoScheduledDeadlineMatching(Instant from, Instant to, org.hamcrest.Matcher<? super DeadlineMessage<?>> matcher)
      Asserts that no deadline matching the given matcher has been scheduled between the to and from times, where to and from are inclusive. Can be used to validate if a deadline has never been set or has been canceled within a given timeframe.
      Parameters:
      from - the time from which no deadline equal to the given deadline should be scheduled (inclusive)
      to - the time until which no deadline equal to the given deadline should be scheduled (inclusive)
      matcher - the matcher defining the deadline which should not be scheduled
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadline

      ResultValidator<T> expectNoScheduledDeadline(Instant from, Instant to, Object deadline)
      Asserts that no deadline equal to the given deadline has been scheduled between the to and from times, where to and from are inclusive. Can be used to validate if a deadline has never been set or has been canceled within a given timeframe.
      Parameters:
      from - the time from which no deadline equal to the given deadline should be scheduled (inclusive)
      to - the time until which no deadline equal to the given deadline should be scheduled (inclusive)
      deadline - the deadline which should not be scheduled
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadlineOfType

      ResultValidator<T> expectNoScheduledDeadlineOfType(Instant from, Instant to, Class<?> deadlineType)
      Asserts that no deadline with the given deadlineType has been scheduled between the to and from times, where to and from are inclusive. Can be used to validate if a deadline has never been set or has been canceled within a given timeframe.
      Parameters:
      from - the time from which no deadline equal to the given deadline should be scheduled (inclusive)
      to - the time until which no deadline equal to the given deadline should be scheduled (inclusive)
      deadlineType - the type of the deadline which should not be scheduled
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNoScheduledDeadlineWithName

      ResultValidator<T> expectNoScheduledDeadlineWithName(Instant from, Instant to, String deadlineName)
      Asserts that no deadline with the given deadlineName has been scheduled between the to and from times, where to and from are inclusive. Can be used to validate if a deadline has never been set or has been canceled within a given timeframe.
      Parameters:
      from - the time from which no deadline equal to the given deadline should be scheduled (inclusive)
      to - the time until which no deadline equal to the given deadline should be scheduled (inclusive)
      deadlineName - the name of the deadline which should not be scheduled
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectDeadlinesMetMatching

      @Deprecated ResultValidator<T> expectDeadlinesMetMatching(org.hamcrest.Matcher<? extends List<? super DeadlineMessage<?>>> matcher)
      Asserts that deadlines matching the given matcher have been met (which have passed in time) on this aggregate.
      Parameters:
      matcher - The matcher that defines the expected list of deadlines
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectTriggeredDeadlinesMatching

      ResultValidator<T> expectTriggeredDeadlinesMatching(org.hamcrest.Matcher<? extends List<? super DeadlineMessage<?>>> matcher)
      Asserts that deadlines matching the given matcher have been triggered for this aggregate.
      Parameters:
      matcher - the matcher that defines the expected list of deadlines
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectDeadlinesMet

      @Deprecated ResultValidator<T> expectDeadlinesMet(Object... expected)
      Deprecated.
      Asserts that given expected deadlines have been met (which have passed in time). Deadlines are compared comparing their type and fields using "equals".
      Parameters:
      expected - The sequence of deadlines expected to be met
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectTriggeredDeadlines

      ResultValidator<T> expectTriggeredDeadlines(Object... expected)
      Asserts that given expected deadlines have been triggered. Deadlines are compared by their type and fields using "equals".
      Parameters:
      expected - the sequence of deadlines expected to have been triggered
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectTriggeredDeadlinesWithName

      ResultValidator<T> expectTriggeredDeadlinesWithName(String... expectedDeadlineNames)
      Asserts that the given expectedDeadlineNames have been triggered. Matches that the given names are complete, in the same order and match the triggered deadlines by validating with DeadlineMessage.getDeadlineName().
      Parameters:
      expectedDeadlineNames - the sequence of deadline names expected to have been triggered
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectTriggeredDeadlinesOfType

      ResultValidator<T> expectTriggeredDeadlinesOfType(Class<?>... expectedDeadlineTypes)
      Asserts that the given expectedDeadlineTypes have been triggered. Matches that the given types are complete, in the same order and match the triggered deadlines by validating with Message.getPayloadType().
      Parameters:
      expectedDeadlineTypes - the sequence of deadline types expected to have been triggered
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectMarkedDeleted

      ResultValidator<T> expectMarkedDeleted()
      Asserts that the Aggregate has been marked for deletion.
      Returns:
      the current ResultValidator, for fluent interfacing
    • expectNotMarkedDeleted

      ResultValidator<T> expectNotMarkedDeleted()
      Asserts that the Aggregate has NOT been marked for deletion.
      Returns:
      the current ResultValidator, for fluent interfacing