Class CommandHandlingTestFixture.Given<C extends Command>
- Type Parameters:
C
- the command type
- Enclosing class:
CommandHandlingTestFixture<I,
C extends Command, R>
CommandHandler
under test.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Fluent API helper class for fine granular specification of a single given event. -
Method Summary
Modifier and TypeMethodDescriptionApplies further events in order to the configuredStateRebuildingHandlerDefinition
s to update the instance state.Applies a further event using theCommandHandlingTestFixture.Given.GivenEvent
consumer for more fine-grained event specification of the event and its meta-data to update the instance state.andGivenCommand
(CommandHandlingTestFixture<I, AnotherCommand, ?> fixture, AnotherCommand command) Uses any previously configured stubbings to execute the givenCommand
without meta-data using theCommandHandlerDefinition
encapsulated within the given fixture to capture any new events published, which in turn will be applied tothis
.andGivenCommand
(CommandHandlingTestFixture<I, AnotherCommand, ?> fixture, AnotherCommand command, Map<String, ?> metaData) Uses any previously configured stubbings to execute the givenCommand
with meta-data using theCommandHandlerDefinition
encapsulated 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}CommandHandler
using the previously initialized instance state.Executes the CommandHandlingTestFixture.Builder.using(Class, CommandHandler) configured}CommandHandler
using the previously initialized instance state.
-
Method Details
-
andGivenCommand
public <AnotherCommand extends Command> CommandHandlingTestFixture<I,C, andGivenCommandR>.Given<C> (CommandHandlingTestFixture<I, AnotherCommand, throws AssertionError?> fixture, AnotherCommand command) Uses any previously configured stubbings to execute the givenCommand
without meta-data using theCommandHandlerDefinition
encapsulated within the given fixture to capture any new events published, which in turn will be applied tothis
. This is mostly used forCommandHandler
s 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
CommandHandler
is 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
this
for further fluent API calls - Throws:
AssertionError
- in case the given command did not execute successfully
-
andGivenCommand
public <AnotherCommand extends Command> CommandHandlingTestFixture<I,C, andGivenCommandR>.Given<C> (CommandHandlingTestFixture<I, AnotherCommand, throws AssertionError?> fixture, AnotherCommand command, Map<String, ?> metaData) Uses any previously configured stubbings to execute the givenCommand
with meta-data using theCommandHandlerDefinition
encapsulated within the given fixture to capture any new events published, which in turn will be applied tothis
. This is mostly used forCommandHandler
s 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
CommandHandler
is 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
this
for 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
this
for further fluent API calls - See Also:
-
usingCommandSubject
- Returns:
- a
this
for 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
this
for 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
this
for further fluent API calls
-
andGiven
Applies further events in order to the configuredStateRebuildingHandlerDefinition
s to update the instance state.- Parameters:
events
- the events to be applied- Returns:
- a
this
for further fluent API calls
-
andGiven
public CommandHandlingTestFixture<I,C, andGivenR>.Given<C> (Consumer<CommandHandlingTestFixture.Given.GivenEvent<I>> event) Applies a further event using theCommandHandlingTestFixture.Given.GivenEvent
consumer 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
this
for further fluent API calls
-
when
Executes the CommandHandlingTestFixture.Builder.using(Class, CommandHandler) configured}CommandHandler
using 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
StateRebuildingHandlerDefinition
s, if and only if theCommandHandler
terminates non exceptionally. This mimics theCommandRouter
behaviour, as events will only be published to the event store for successful executions.Be aware, however, that instance mutability cannot be enforced. Hence,CommandHandler
s publishing events, which result in mutated instance state, cannot be rolled back. -
when
Executes the CommandHandlingTestFixture.Builder.using(Class, CommandHandler) configured}CommandHandler
using 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
StateRebuildingHandlerDefinition
s, if and only if theCommandHandler
terminates non exceptionally. This mimics theCommandRouter
behaviour, as events will only be published to the event store for successful executions.Be aware, however, that instance mutability cannot be enforced. Hence,CommandHandler
s publishing events, which result in mutated instance state, cannot be rolled back.- Parameters:
command
- theCommand
to executemetaData
- additional command meta-data supplied to theCommandHandler
- Returns:
- an
CommandHandlingTestFixture<I,
instance for further fluent API callsC extends Command, R>.Expect
-