public interface FixtureConfiguration
Modifier and Type | Method and Description |
---|---|
Instant |
currentTime()
Returns the time as "known" by the fixture.
|
CommandBus |
getCommandBus()
Returns the command bus used by this fixture.
|
EventBus |
getEventBus()
Returns the event bus used by this fixture.
|
GivenAggregateEventPublisher |
givenAggregate(String aggregateIdentifier)
Use this method to indicate that an aggregate with given identifier published certain events.
|
ContinuedGivenState |
givenAPublished(Object event)
Indicates that the given
applicationEvent has been published in the past. |
ContinuedGivenState |
givenCurrentTime(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.
|
WhenState |
givenNoPriorActivity()
Indicates that no relevant activity has occurred in the past.
|
<T> T |
registerCommandGateway(Class<T> gatewayInterface)
Creates a Command Gateway for the given
gatewayInterface and registers that as a resource. |
<T> T |
registerCommandGateway(Class<T> gatewayInterface,
T stubImplementation)
Creates a Command Gateway for the given
gatewayInterface and registers that as a resource. |
FixtureConfiguration |
registerDeadlineDispatchInterceptor(MessageDispatchInterceptor<? super DeadlineMessage<?>> deadlineDispatchInterceptor)
Registers a deadline dispatch interceptor which will always be invoked before a deadline is dispatched
(scheduled) on the
DeadlineManager to perform a task specified in the
interceptor. |
FixtureConfiguration |
registerDeadlineHandlerInterceptor(MessageHandlerInterceptor<? super DeadlineMessage<?>> deadlineHandlerInterceptor)
Registers a deadline handler interceptor which will always be invoked before a deadline is handled to perform a
task specified in the interceptor.
|
default FixtureConfiguration |
registerEventHandlerInterceptor(MessageHandlerInterceptor<? super EventMessage<?>> eventHandlerInterceptor)
Registers a
MessageHandlerInterceptor for EventMessages . |
FixtureConfiguration |
registerFieldFilter(FieldFilter fieldFilter)
Registers the given
fieldFilter , which is used to define which Fields are used when comparing objects. |
FixtureConfiguration |
registerHandlerDefinition(HandlerDefinition handlerDefinition)
Registers a
HandlerDefinition within this fixture. |
FixtureConfiguration |
registerHandlerEnhancerDefinition(HandlerEnhancerDefinition handlerEnhancerDefinition)
Registers a
HandlerEnhancerDefinition within this fixture. |
FixtureConfiguration |
registerIgnoredField(Class<?> declaringClass,
String fieldName)
Indicates that a field with given
fieldName , which is declared in given declaringClass is ignored
when performing deep equality checks. |
FixtureConfiguration |
registerListenerInvocationErrorHandler(ListenerInvocationErrorHandler listenerInvocationErrorHandler)
Registers a
ListenerInvocationErrorHandler to be set for the Saga to deal with exceptions being thrown from within Saga Event Handlers. |
FixtureConfiguration |
registerParameterResolverFactory(ParameterResolverFactory parameterResolverFactory)
Registers a
ParameterResolverFactory within this fixture. |
void |
registerResource(Object resource)
Registers the given
resource . |
FixtureConfiguration |
registerResourceInjector(ResourceInjector resourceInjector)
Registers a
ResourceInjector within this fixture. |
FixtureConfiguration |
registerStartRecordingCallback(Runnable onStartRecordingCallback)
Registers a callback to be invoked when the fixture execution starts recording.
|
void |
setCallbackBehavior(CallbackBehavior callbackBehavior)
Sets the instance that defines the behavior of the Command Bus when a command is dispatched with a callback.
|
default FixtureConfiguration |
suppressExceptionInGivenPhase(boolean suppress)
Configure whether the fixture should suppress exceptions thrown during the given-phase.
|
FixtureConfiguration |
withTransienceCheckDisabled()
Disables the check that injected resources are stored in fields that are marked 'transient'.
|
FixtureConfiguration withTransienceCheckDisabled()
By default, Saga fixtures check for the transient modifier on fields that hold injected resources. These resources are generally not means to be serialized as part of the Saga.
When the transience check reports false positives, this method allows this check to be skipped.
void registerResource(Object resource)
resource
. When a Saga is created, all resources are injected on that instance before
any Events are passed onto it.
Note that a CommandBus, EventBus and EventScheduler are already registered as resources, and need not be
registered again.
Also note that you might need to reset the resources manually if you want to isolate behavior during the "when"
stage of the test.resource
- the resource to register.FixtureConfiguration registerParameterResolverFactory(ParameterResolverFactory parameterResolverFactory)
ParameterResolverFactory
within this fixture. The given parameterResolverFactory
will
be added to the other parameter resolver factories introduced through ClasspathParameterResolverFactory.forClass(Class)
and the SimpleResourceParameterResolverFactory
adding the registered resources
(with registerResource(Object)
. The type of the saga under test is used as input for the ClasspathParameterResolverFactory#forClass(Class)
operation.parameterResolverFactory
- the ParameterResolver
to register within this fixtureregisterResource(Object)
<T> T registerCommandGateway(Class<T> gatewayInterface)
gatewayInterface
and registers that as a resource. The gateway
will dispatch commands on the Command Bus contained in this Fixture, so that you can validate commands using
FixtureExecutionResult.expectDispatchedCommands(Object...)
and FixtureExecutionResult.expectDispatchedCommandsMatching(org.hamcrest.Matcher)
.
Note that you need to use setCallbackBehavior(org.axonframework.test.utils.CallbackBehavior)
to defined
the behavior of commands when expecting return values. Alternatively, you can use registerCommandGateway(Class, Object)
to define behavior using a stub implementation.T
- The gateway typegatewayInterface
- The interface describing the gateway<T> T registerCommandGateway(Class<T> gatewayInterface, T stubImplementation)
gatewayInterface
and registers that as a resource. The gateway
will dispatch commands on the Command Bus contained in this Fixture, so that you can validate commands using
FixtureExecutionResult.expectDispatchedCommands(Object...)
and FixtureExecutionResult.expectDispatchedCommandsMatching(org.hamcrest.Matcher)
.
The behavior of the created gateway is defined by the given stubImplementation
, if not null. Dispatched
Commands are still recorded for verification. Note that only commands executed in the "when" phase are recorded,
while the stub implementation may record activity during the "given" phase as well.T
- The gateway typegatewayInterface
- The interface describing the gatewaystubImplementation
- The stub or mock implementation defining behavior of the gatewayFixtureConfiguration registerFieldFilter(FieldFilter fieldFilter)
fieldFilter
, which is used to define which Fields are used when comparing objects.
The ResultValidator.expectEvents(Object...)
and ResultValidator.expectResultMessage(CommandResultMessage)
,
for example, use this filter.
When multiple filters are registered, a Field must be accepted by all registered filters in order to be
accepted.
By default, all Fields are included in the comparison.fieldFilter
- The FieldFilter that defines which fields to include in the comparisonFixtureConfiguration registerIgnoredField(Class<?> declaringClass, String fieldName)
fieldName
, which is declared in given declaringClass
is ignored
when performing deep equality checks.declaringClass
- The class declaring the fieldfieldName
- The name of the fieldFixtureExecutionException
- when no such field is declaredFixtureConfiguration registerHandlerDefinition(HandlerDefinition handlerDefinition)
HandlerDefinition
within this fixture. The given handlerDefinition
is added to the
handler definitions introduced through ClasspathHandlerDefinition.forClass(Class)
.
The type of the saga under test is used as input for the ClasspathHandlerDefinition#forClass(Class)
operation.handlerDefinition
- used to create concrete handlersFixtureConfiguration registerHandlerEnhancerDefinition(HandlerEnhancerDefinition handlerEnhancerDefinition)
HandlerEnhancerDefinition
within this fixture. This given handlerEnhancerDefinition
is added to the handler enhancer definitions introduced through ClasspathHandlerEnhancerDefinition.forClass(Class)
.
The type of the saga under test is used as input for the ClasspathHandlerEnhancerDefinition#forClass(Class)
operation.handlerEnhancerDefinition
- the HandlerEnhancerDefinition
to register within this fixtureFixtureConfiguration registerDeadlineDispatchInterceptor(MessageDispatchInterceptor<? super DeadlineMessage<?>> deadlineDispatchInterceptor)
DeadlineManager
to perform a task specified in the
interceptor.deadlineDispatchInterceptor
- the interceptor for dispatching (scheduling) deadlinesFixtureConfiguration registerDeadlineHandlerInterceptor(MessageHandlerInterceptor<? super DeadlineMessage<?>> deadlineHandlerInterceptor)
deadlineHandlerInterceptor
- the interceptor for handling deadlinesdefault FixtureConfiguration registerEventHandlerInterceptor(MessageHandlerInterceptor<? super EventMessage<?>> eventHandlerInterceptor)
MessageHandlerInterceptor
for EventMessages
.
Will always be invoked before an event is handled to perform a task specified in the interceptor. Interceptors are invoked in the order they have been registered in.
eventHandlerInterceptor
- the interceptor for handling EventMessages
FixtureConfiguration
, for fluent interfacing.FixtureConfiguration registerStartRecordingCallback(Runnable onStartRecordingCallback)
onStartRecordingCallback
- callback to invokeFixtureConfiguration registerListenerInvocationErrorHandler(ListenerInvocationErrorHandler listenerInvocationErrorHandler)
ListenerInvocationErrorHandler
to be set for the Saga to deal with exceptions being thrown from within Saga Event Handlers. Will be
given to the AnnotatedSagaManager
for the defined Saga type. Defaults to a LoggingErrorHandler
wrapped inside a RecordingListenerInvocationErrorHandler
.listenerInvocationErrorHandler
- to be set for the Saga to deal with exceptions being thrown from within Saga Event Handlersdefault FixtureConfiguration suppressExceptionInGivenPhase(boolean suppress)
suppress
is
true
, the fixture moves on to the when-phase regardless of any exceptions thrown during the given-phase.
Note that setting this to true
means the
registered
ListenerInvocationErrorHandler
is not invoked during exception in the given-phase. Defaults to
suppressing during given-phase exceptions.
suppress
- A boolean
describing whether the fixture should suppress failures during the
given-phase.FixtureConfiguration registerResourceInjector(ResourceInjector resourceInjector)
ResourceInjector
within this fixture. This approach can be used if a custom ResourceInjector
has been built for a project which the user wants to take into account when testing it's
sagas.
The provided resourceInjector
will be paired with the fixture's default ResourceInjector
to keep
support for the registerResource(Object)
and withTransienceCheckDisabled()
methods. Note that
first the default injector is called, and after that the given resourceInjector
. This approach
ensures the fixture's correct workings for default provided resources, like the EventBus
and CommandBus
}, whilst allowing the capability to append and/or override with the given resourceInjector
.
Care should be taken if the custom resourceInjector
overrides default resources like the EventBus
and CommandBus
, as the fixture uses specialized versions of the default sources to support all testing
functionality.
resourceInjector
- the ResourceInjector
to register within this fixturevoid setCallbackBehavior(CallbackBehavior callbackBehavior)
callbackBehavior
- The instance deciding to how the callback should be invoked.GivenAggregateEventPublisher givenAggregate(String aggregateIdentifier)
andThenAggregate(someIdentifier).published(someEvents)
aggregateIdentifier
- The identifier of the aggregate the events should appear to come fromContinuedGivenState givenCurrentTime(Instant currentTime)
currentTime
- The simulated "current time" at which the given state is initializedContinuedGivenState givenAPublished(Object event)
applicationEvent
has been published in the past. This event is sent to the
associated sagas.event
- The event to publishWhenState givenNoPriorActivity()
Instant currentTime()
EventBus getEventBus()
ResultValidator
operations.CommandBus getCommandBus()
Copyright © 2010–2024. All rights reserved.