Interface FixtureConfiguration

All Known Implementing Classes:
SagaTestFixture

public interface FixtureConfiguration
Interface describing action to perform on a SagaTestFixture during the configuration phase.

Most of what an Axon Framework 4 fixture configured is now expressible on the MessagingConfigurer an application configures itself, which customize(UnaryOperator) hands to the caller. Only the settings that configurer cannot express are kept here. Three Axon Framework 4 methods have no counterpart at all:

  • registerResourceInjector(..): a Saga has no injected fields to configure, since collaborators reach it as handler parameters.
  • registerListenerInvocationErrorHandler(..): Axon Framework 5 has no such component, and building one would mean porting two more that a Saga manager has nothing to fill in. A Saga suppresses its own failures with an ExceptionHandler method, which is what the Axon Framework 4 default behaviour became.
  • registerCommandGateway(..): Axon Framework 5 removed the CommandGatewayFactory, so a custom gateway interface can no longer be built anywhere, test or production. A Saga sends commands through CommandDispatcher or CommandGateway as a handler parameter, and a test decides the answer by subscribing a handler through customize(UnaryOperator) or by setting a callback behaviour.
Configuration is applied while building the fixture, which happens when the first event is handled or a bus is requested. Merely selecting a given aggregate or declaring that there is no prior activity does not build it. Anything registered after the fixture is built is ignored, as it was in Axon Framework 4.
Since:
1.1
Author:
Allard Buijze
  • Method Details

    • withTransienceCheckDisabled

      @Deprecated(forRemoval=true) FixtureConfiguration withTransienceCheckDisabled()
      Deprecated, for removal: This API element is subject to removal in a future version.
      There is no transience check to disable. Delete the call.
      Does nothing, and is kept only so an Axon Framework 4 test suite still compiles.

      Axon Framework 4 refused a Saga holding an injected resource in a field that was not transient, because the Saga is serialized into the SagaStore and the resource would go with it. This method turned that check off.

      Axon Framework 5 has no such check, and rebuilding it would not help. It worked by comparing each field against the resource injector's list, and there is no injector; and its advice no longer applies, since transient is a Java serialization marker while a Saga is now serialized through a Converter. A Saga can still hold infrastructure in a field, but nothing puts it there on the Saga's behalf, and serializing it fails loudly.

      Returns:
      the current FixtureConfiguration, for fluent interfacing
    • customize

      Customizes the MessagingConfigurer the fixture builds the Saga on, for anything this interface does not expose.

      The Saga, its store and its event processor are registered before the given customization is applied, so it can add to them or replace what they registered.

      Parameters:
      customization - the customization to apply to the configurer
      Returns:
      the current FixtureConfiguration, for fluent interfacing
    • registerResource

      void registerResource(Object resource)
      Registers the given resource, making it available to Saga handler methods declaring a parameter of an assignable type.

      Registering two resources of the same type makes the last one win, as it did in Axon Framework 4. Unlike Axon Framework 4, the resource is not injected into the Saga's fields.

      Parameters:
      resource - the resource to make available to the Saga's handler methods
    • registerParameterResolverFactory

      FixtureConfiguration registerParameterResolverFactory(ParameterResolverFactory parameterResolverFactory)
      Registers the given parameterResolverFactory, used to resolve the parameters of the Saga's handler methods.
      Parameters:
      parameterResolverFactory - the factory resolving handler method parameters
      Returns:
      the current FixtureConfiguration, for fluent interfacing
    • registerHandlerDefinition

      FixtureConfiguration registerHandlerDefinition(HandlerDefinition handlerDefinition)
      Registers the given handlerDefinition, used to create the Saga's handlers.
      Parameters:
      handlerDefinition - the definition creating the Saga's handlers
      Returns:
      the current FixtureConfiguration, for fluent interfacing
    • registerHandlerEnhancerDefinition

      FixtureConfiguration registerHandlerEnhancerDefinition(HandlerEnhancerDefinition handlerEnhancerDefinition)
      Registers the given handlerEnhancerDefinition, used to enhance the Saga's handlers.
      Parameters:
      handlerEnhancerDefinition - the definition enhancing the Saga's handlers
      Returns:
      the current FixtureConfiguration, for fluent interfacing
    • registerDeadlineDispatchInterceptor

      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.
      Parameters:
      deadlineDispatchInterceptor - the interceptor for dispatching (scheduling) deadlines
      Returns:
      the current FixtureConfiguration, for fluent interfacing
    • registerDeadlineHandlerInterceptor

      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.
      Parameters:
      deadlineHandlerInterceptor - the interceptor for handling deadlines
      Returns:
      the current FixtureConfiguration, for fluent interfacing
    • registerEventHandlerInterceptor

      FixtureConfiguration registerEventHandlerInterceptor(MessageHandlerInterceptor<? super EventMessage> interceptor)
      Registers the given interceptor, invoked around the Saga's event handling.

      Interceptors are invoked in registration order, as they were in Axon Framework 4.

      Parameters:
      interceptor - the interceptor to invoke around the Saga's event handling
      Returns:
      the current FixtureConfiguration, for fluent interfacing
    • registerFieldFilter

      FixtureConfiguration registerFieldFilter(FieldFilter fieldFilter)
      Registers the given fieldFilter, defining which fields are compared when matching messages.
      Parameters:
      fieldFilter - the filter defining which fields to compare
      Returns:
      the current FixtureConfiguration, for fluent interfacing
    • registerIgnoredField

      FixtureConfiguration registerIgnoredField(Class<?> declaringClass, String fieldName)
      Indicates that a field with the given fieldName, declared in the given declaringClass, is ignored when comparing messages.
      Parameters:
      declaringClass - the class declaring the field
      fieldName - the name of the field to ignore
      Returns:
      the current FixtureConfiguration, for fluent interfacing
    • registerStartRecordingCallback

      FixtureConfiguration registerStartRecordingCallback(Runnable callback)
      Registers the given callback, invoked when the fixture starts recording what the Saga does, which is when the "when" phase begins.
      Parameters:
      callback - the callback to invoke when recording starts
      Returns:
      the current FixtureConfiguration, for fluent interfacing
    • setCallbackBehavior

      void setCallbackBehavior(CallbackBehavior callbackBehavior)
      Sets the behaviour answering commands that no subscribed handler takes.

      Defaults to a DefaultCallbackBehavior, which answers null, as Axon Framework 4 did. A command that does reach a handler subscribed through customize(UnaryOperator) is answered by that handler instead.

      Parameters:
      callbackBehavior - the behaviour deciding what such a command returns
    • suppressExceptionInGivenPhase

      FixtureConfiguration suppressExceptionInGivenPhase(boolean suppress)
      Sets whether a failure of a Saga handler during the "given" phase is suppressed rather than thrown.

      Defaults to false, meaning a failure during the "given" phase surfaces. Axon Framework 4's FixtureConfiguration documented the opposite default while its implementation did the same as this; the implementation is what is kept.

      Parameters:
      suppress - whether to suppress a failure during the "given" phase
      Returns:
      the current FixtureConfiguration, for fluent interfacing
    • getEventBus

      EventBus getEventBus()
      The EventBus the fixture publishes on.

      Axon Framework 5 splits an EventBus into a EventSink for publishing and a SubscribableEventSource for subscribing. A test only needs the publishing half, but the whole bus is returned so that fixture.getEventBus().subscribe(..) keeps working, as it did in Axon Framework 4.

      Axon Framework 5 obtains the bus from the application configuration. Calling this method therefore builds and starts the fixture; make all fixture registrations before requesting the bus.

      Returns:
      the event bus the fixture publishes on
    • getCommandBus

      CommandBus getCommandBus()
      The CommandBus the Saga dispatches on.

      Axon Framework 5 obtains the bus from the application configuration. Calling this method therefore builds and starts the fixture; make all fixture registrations before requesting the bus.

      Returns:
      the command bus the Saga dispatches on
    • givenAggregate

      GivenAggregateEventPublisher givenAggregate(String aggregateIdentifier)
      Use this method to indicate that an aggregate with given identifier published certain events.

      Can be chained to build natural sentences: givenAggregate(someIdentifier).published(someEvents)

      Parameters:
      aggregateIdentifier - The identifier of the aggregate the events should appear to come from
      Returns:
      an object that allows registration of the actual events to send
    • givenAPublished

      ContinuedGivenState givenAPublished(Object event)
      Indicates that the given event has been published in the past. This event is sent to the associated Sagas.
      Parameters:
      event - The event to publish
      Returns:
      an object that allows chaining of more given state
    • givenAPublished

      ContinuedGivenState givenAPublished(Object event, Map<String,String> metadata)
      Indicates that the given event with given metadata has been published in the past. This event is sent to the associated Sagas.
      Parameters:
      event - The event to publish
      metadata - The metadata to attach to the event
      Returns:
      an object that allows chaining of more given state
    • givenNoPriorActivity

      WhenState givenNoPriorActivity()
      Indicates that no relevant activity has occurred in the past.
      Returns:
      an object that allows the definition of the activity to measure Saga behavior
    • givenCurrentTime

      ContinuedGivenState givenCurrentTime(Instant currentTime)
      Sets the time the fixture starts from.
      Parameters:
      currentTime - The time to start the fixture at
      Returns:
      an object that allows chaining of more given state
    • currentTime

      Instant currentTime()
      The time as the fixture's scheduler sees it.
      Returns:
      the current time of the fixture's scheduler