org.axonframework.test.saga
Interface FixtureConfiguration

All Known Implementing Classes:
AnnotatedSagaTestFixture

public interface FixtureConfiguration

Interface describing action to perform on a Saga Test Fixture during the configuration phase.

Since:
1.1
Author:
Allard Buijze

Method Summary
 org.joda.time.DateTime currentTime()
          Returns the time as "known" by the fixture.
 GivenAggregateEventPublisher givenAggregate(Object 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.
 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 registerFieldFilter(FieldFilter fieldFilter)
          Registers the given fieldFilter, which is used to define which Fields are used when comparing objects.
 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.
 void registerResource(Object resource)
          Registers the given resource.
 void setCallbackBehavior(CallbackBehavior callbackBehavior)
          Sets the instance that defines the behavior of the Command Bus when a command is dispatched with a callback.
 

Method Detail

registerResource

void registerResource(Object resource)
Registers the given 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.

Parameters:
resource - the resource to register.

registerCommandGateway

<T> T registerCommandGateway(Class<T> gatewayInterface)
Creates a Command Gateway for the given 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.expectDispatchedCommandsEqualTo(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.

Type Parameters:
T - The gateway type
Parameters:
gatewayInterface - The interface describing the gateway
Returns:
the gateway implementation being registered as a resource.

registerCommandGateway

<T> T registerCommandGateway(Class<T> gatewayInterface,
                             T stubImplementation)
Creates a Command Gateway for the given 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.expectDispatchedCommandsEqualTo(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.

Type Parameters:
T - The gateway type
Parameters:
gatewayInterface - The interface describing the gateway
stubImplementation - The stub or mock implementation defining behavior of the gateway
Returns:
the gateway implementation being registered as a resource.

registerFieldFilter

FixtureConfiguration registerFieldFilter(FieldFilter fieldFilter)
Registers the given fieldFilter, which is used to define which Fields are used when comparing objects. The ResultValidator.expectEvents(Object...) and ResultValidator.expectReturnValue(Object), 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.

Parameters:
fieldFilter - The FieldFilter that defines which fields to include in the comparison
Returns:
the current FixtureConfiguration, for fluent interfacing

registerIgnoredField

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.

Parameters:
declaringClass - The class declaring the field
fieldName - The name of the field
Returns:
the current FixtureConfiguration, for fluent interfacing
Throws:
FixtureExecutionException - when no such field is declared

setCallbackBehavior

void setCallbackBehavior(CallbackBehavior callbackBehavior)
Sets the instance that defines the behavior of the Command Bus when a command is dispatched with a callback.

Parameters:
callbackBehavior - The instance deciding to how the callback should be invoked.

givenAggregate

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

Can be chained to build natural sentences:
andThenAggregate(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 applicationEvent 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

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
Since:
2.1.1

currentTime

org.joda.time.DateTime currentTime()
Returns the time as "known" by the fixture. This is the time at which the fixture was created, plus the amount of time the fixture was told to simulate a "wait".

This time can be used to predict calculations that the saga may have made based on timestamps from the events it received.

Returns:
the simulated "current time" of the fixture.


Copyright © 2010-2016. All Rights Reserved.