Class CommandHandlingTestFixture.Given<C extends Command>
- Type Parameters:
C- the command type
- Enclosing class:
CommandHandlingTestFixture<C extends Command>
CommandHandler under test.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFluent API helper class for fine granular specification of a single given event. -
Method Summary
Modifier and TypeMethodDescriptionApplies further events in order to the configuredStateRebuildingHandlerDefinitions to update the instance state.Applies a further event using theCommandHandlingTestFixture.Given.GivenEventconsumer for more fine-grained event specification of the event and its meta-data to update the instance state.<AnotherCommand extends Command>
CommandHandlingTestFixture<C>.Given<C> andGivenCommand(CommandHandlingTestFixture<AnotherCommand> fixture, AnotherCommand command) Uses any previously configured stubbings to execute the givenCommandwithout meta-data using theCommandHandlerDefinitionencapsulated within the given fixture to capture any new events published, which in turn will be applied tothis.<AnotherCommand extends Command>
CommandHandlingTestFixture<C>.Given<C> andGivenCommand(CommandHandlingTestFixture<AnotherCommand> fixture, AnotherCommand command, Map<String, ?> metaData) Uses any previously configured stubbings to execute the givenCommandwith meta-data using theCommandHandlerDefinitionencapsulated within the given fixture to capture any new events published, which in turn will be applied tothis.andGivenTime(Instant time) Configures a (new) time-stamp to be used, if further events shall be applied with thatEvent.time().andGivenTimeDelta(Duration duration) Shifts the previously configured time-stamp by given duration, if further events shall be applied with thatEvent.time().usingSubject(String subject) Specifies theEvent.subject()to be used for subsequent calls toandGiven(Object...).Executes the CommandHandlingTestFixture.Builder.using(Class, CommandHandler) configured}CommandHandlerusing the previously initialized instance state.Executes the CommandHandlingTestFixture.Builder.using(Class, CommandHandler) configured}CommandHandlerusing the previously initialized instance state.
-
Method Details
-
andGivenCommand
public <AnotherCommand extends Command> CommandHandlingTestFixture<C>.Given<C> andGivenCommand(CommandHandlingTestFixture<AnotherCommand> fixture, AnotherCommand command) throws AssertionError Uses any previously configured stubbings to execute the givenCommandwithout meta-data using theCommandHandlerDefinitionencapsulated within the given fixture to capture any new events published, which in turn will be applied tothis. This is mostly used forCommandHandlers publishing a lot or more complex events, in favor of stubbing the events directly.Be aware that stubbed events can be specified more precisely than captured ones, since the encapsulated
CommandHandleris responsible for event publication using theCommandEventPublisher. Hence,CommandHandlingTestFixture.Given.GivenEvent.time(Instant)andCommandHandlingTestFixture.Given.GivenEvent.id(String)cannot be specified using this approach.- Type Parameters:
AnotherCommand- generic command type to execute- Parameters:
fixture- the fixture holding the command to executecommand- the command to execute for event capturing- Returns:
- a
thisfor further fluent API calls - Throws:
AssertionError- in case the given command did not execute successfully
-
andGivenCommand
public <AnotherCommand extends Command> CommandHandlingTestFixture<C>.Given<C> andGivenCommand(CommandHandlingTestFixture<AnotherCommand> fixture, AnotherCommand command, Map<String, ?> metaData) throws AssertionErrorUses any previously configured stubbings to execute the givenCommandwith meta-data using theCommandHandlerDefinitionencapsulated within the given fixture to capture any new events published, which in turn will be applied tothis. This is mostly used forCommandHandlers publishing a lot or more complex events, in favor of stubbing the events directly.Be aware that stubbed events can be specified more precisely than captured ones, since the encapsulated
CommandHandleris responsible for event publication using theCommandEventPublisher. Hence,CommandHandlingTestFixture.Given.GivenEvent.time(Instant)andCommandHandlingTestFixture.Given.GivenEvent.id(String)cannot be specified using this approach.- Type Parameters:
AnotherCommand- generic command type to execute- Parameters:
fixture- the fixture holding the command to executecommand- the command to execute for event capturingmetaData- the command meta-data- Returns:
- a
thisfor further fluent API calls - Throws:
AssertionError- in case the given command did not execute successfully
-
usingSubject
Specifies theEvent.subject()to be used for subsequent calls toandGiven(Object...).This is a convenience method to be used in favor of specifying event subjects using
CommandHandlingTestFixture.Given.GivenEvent.subject(String), which, if used, however, takes precedence over the subject defined using this method. Notice, that the event subject specified by this method does not affect calls toandGivenCommand(CommandHandlingTestFixture, Command).- Parameters:
subject- the event subject to be applied to any subsequent given events- Returns:
- a
thisfor further fluent API calls - See Also:
-
usingCommandSubject
- Returns:
- a
thisfor further fluent API calls - See Also:
-
andGivenTime
Configures a (new) time-stamp to be used, if further events shall be applied with thatEvent.time().- Parameters:
time- the new time-stamp to be used- Returns:
- a
thisfor further fluent API calls
-
andGivenTimeDelta
Shifts the previously configured time-stamp by given duration, if further events shall be applied with thatEvent.time().- Parameters:
duration- the time-stamp delta to be applied- Returns:
- a
thisfor further fluent API calls
-
andGiven
Applies further events in order to the configuredStateRebuildingHandlerDefinitions to update the instance state.- Parameters:
events- the events to be applied- Returns:
- a
thisfor further fluent API calls
-
andGiven
public CommandHandlingTestFixture<C>.Given<C> andGiven(Consumer<CommandHandlingTestFixture.Given.GivenEvent> event) Applies a further event using theCommandHandlingTestFixture.Given.GivenEventconsumer for more fine-grained event specification of the event and its meta-data to update the instance state.- Parameters:
event- event specification consumer, at leastCommandHandlingTestFixture.Given.GivenEvent.payload(Object)must be called- Returns:
- a
thisfor further fluent API calls
-
when
Executes the CommandHandlingTestFixture.Builder.using(Class, CommandHandler) configured}CommandHandlerusing the previously initialized instance state. All events published as part of the execution as well as any exceptions thrown will be captured in-memory for further assertion.Events will get applied to the current instance state using the configured
StateRebuildingHandlerDefinitions, if and only if theCommandHandlerterminates non exceptionally. This mimics theCommandRouterbehaviour, as events will only be published to the event store for successful executions.Be aware, however, that instance mutability cannot be enforced. Hence,CommandHandlers publishing events, which result in mutated instance state, cannot be rolled back.- Parameters:
command- theCommandto execute- Returns:
- an
CommandHandlingTestFixture<C extends Command>.Expectinstance for further fluent API calls
-
when
Executes the CommandHandlingTestFixture.Builder.using(Class, CommandHandler) configured}CommandHandlerusing the previously initialized instance state. All events published as part of the execution as well as any exceptions thrown will be captured in-memory for further assertion.Events will get applied to the current instance state using the configured
StateRebuildingHandlerDefinitions, if and only if theCommandHandlerterminates non exceptionally. This mimics theCommandRouterbehaviour, as events will only be published to the event store for successful executions.Be aware, however, that instance mutability cannot be enforced. Hence,CommandHandlers publishing events, which result in mutated instance state, cannot be rolled back.- Parameters:
command- theCommandto executemetaData- additional command meta-data supplied to theCommandHandler- Returns:
- an
CommandHandlingTestFixture<C extends Command>.Expectinstance for further fluent API calls
-