|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.axonframework.test.saga.AnnotatedSagaTestFixture
public class AnnotatedSagaTestFixture
Fixture for testing Annotated Sagas based on events and time passing. This fixture allows resources to be configured for the sagas to use.
Constructor Summary | |
---|---|
AnnotatedSagaTestFixture(Class<? extends AbstractAnnotatedSaga> sagaType)
Creates an instance of the AnnotatedSagaTestFixture to test sagas of the given sagaType . |
Method Summary | ||
---|---|---|
GivenAggregateEventPublisher |
andThenAggregate(Object aggregateIdentifier)
Use this method to indicate that an aggregate with given identifier published certain events. |
|
ContinuedGivenState |
andThenAPublished(Object event)
Indicates that the given event has been published in the past. |
|
ContinuedGivenState |
andThenTimeAdvancesTo(org.joda.time.DateTime newDateTime)
Simulate time shifts in the current given state. |
|
ContinuedGivenState |
andThenTimeElapses(org.joda.time.Duration elapsedTime)
Simulate time shifts in the current given state. |
|
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. |
|
|
registerCommandGateway(Class<T> gatewayInterface)
Creates a Command Gateway for the given gatewayInterface and registers that as a resource. |
|
|
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. |
|
WhenAggregateEventPublisher |
whenAggregate(Object aggregateIdentifier)
Use this method to indicate that an aggregate with given identifier should publish certain events, while recording the outcome. |
|
FixtureExecutionResult |
whenPublishingA(Object event)
Use this method to indicate an application is published, while recording the outcome. |
|
FixtureExecutionResult |
whenTimeAdvancesTo(org.joda.time.DateTime newDateTime)
Mimic an elapsed time with no relevant activity for the Saga. |
|
FixtureExecutionResult |
whenTimeElapses(org.joda.time.Duration elapsedTime)
Mimic an elapsed time with no relevant activity for the Saga. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AnnotatedSagaTestFixture(Class<? extends AbstractAnnotatedSaga> sagaType)
sagaType
.
sagaType
- The type of saga under testMethod Detail |
---|
public FixtureExecutionResult whenTimeElapses(org.joda.time.Duration elapsedTime)
WhenState
FixtureConfiguration.registerResource(Object)
, you may need to
reset them yourself if they are manipulated by the Saga in the "given" stage of the test.
whenTimeElapses
in interface WhenState
elapsedTime
- The amount of time to elapse
public FixtureExecutionResult whenTimeAdvancesTo(org.joda.time.DateTime newDateTime)
WhenState
FixtureConfiguration.registerResource(Object)
, you may need to
reset them yourself if they are manipulated by the Saga in the "given" stage of the test.
whenTimeAdvancesTo
in interface WhenState
newDateTime
- The time to advance the clock to
public void registerResource(Object resource)
FixtureConfiguration
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.
registerResource
in interface FixtureConfiguration
resource
- the resource to register.public void setCallbackBehavior(CallbackBehavior callbackBehavior)
FixtureConfiguration
setCallbackBehavior
in interface FixtureConfiguration
callbackBehavior
- The instance deciding to how the callback should be invoked.public GivenAggregateEventPublisher givenAggregate(Object aggregateIdentifier)
FixtureConfiguration
andThenAggregate(someIdentifier).published(someEvents)
givenAggregate
in interface FixtureConfiguration
aggregateIdentifier
- The identifier of the aggregate the events should appear to come from
public ContinuedGivenState givenAPublished(Object event)
FixtureConfiguration
applicationEvent
has been published in the past. This event is sent to the
associated sagas.
givenAPublished
in interface FixtureConfiguration
event
- The event to publish
public WhenState givenNoPriorActivity()
FixtureConfiguration
givenNoPriorActivity
in interface FixtureConfiguration
public GivenAggregateEventPublisher andThenAggregate(Object aggregateIdentifier)
ContinuedGivenState
andThenAggregate(someIdentifier).published(someEvents)
andThenAggregate
in interface ContinuedGivenState
aggregateIdentifier
- The identifier of the aggregate the events should appear to come from
public ContinuedGivenState andThenTimeElapses(org.joda.time.Duration elapsedTime)
ContinuedGivenState
andThenTimeElapses
in interface ContinuedGivenState
elapsedTime
- The amount of time that will elapse
public ContinuedGivenState andThenTimeAdvancesTo(org.joda.time.DateTime newDateTime)
ContinuedGivenState
andThenTimeAdvancesTo
in interface ContinuedGivenState
newDateTime
- The time to advance the clock to
public ContinuedGivenState andThenAPublished(Object event)
ContinuedGivenState
event
has been published in the past. This event is sent to the associated
sagas.
andThenAPublished
in interface ContinuedGivenState
event
- The event to publish
public WhenAggregateEventPublisher whenAggregate(Object aggregateIdentifier)
WhenState
FixtureConfiguration.givenAggregate(Object)
given} and
ContinuedGivenState.andThenAggregate(Object)
andThen} methods, this method
will start recording activity on the EventBus and CommandBus.
Can be chained to build natural sentences:whenAggregate(someIdentifier).publishes(anEvent)
Note that if you inject resources using FixtureConfiguration.registerResource(Object)
, you may need to
reset them yourself if they are manipulated by the Saga in the "given" stage of the test.
whenAggregate
in interface WhenState
aggregateIdentifier
- The identifier of the aggregate the events should appear to come from
public FixtureExecutionResult whenPublishingA(Object event)
WhenState
FixtureConfiguration.registerResource(Object)
, you may need to
reset them yourself if they are manipulated by the Saga in the "given" stage of the test.
whenPublishingA
in interface WhenState
event
- the event to publish
public org.joda.time.DateTime currentTime()
FixtureConfiguration
currentTime
in interface FixtureConfiguration
public <T> T registerCommandGateway(Class<T> gatewayInterface)
FixtureConfiguration
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 FixtureConfiguration.setCallbackBehavior(org.axonframework.test.utils.CallbackBehavior)
to defined
the behavior of commands when expecting return values. Alternatively, you can use FixtureConfiguration.registerCommandGateway(Class, Object)
to define behavior using a stub implementation.
registerCommandGateway
in interface FixtureConfiguration
T
- The gateway typegatewayInterface
- The interface describing the gateway
public <T> T registerCommandGateway(Class<T> gatewayInterface, T stubImplementation)
FixtureConfiguration
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.
registerCommandGateway
in interface FixtureConfiguration
T
- The gateway typegatewayInterface
- The interface describing the gatewaystubImplementation
- The stub or mock implementation defining behavior of the gateway
public FixtureConfiguration registerFieldFilter(FieldFilter fieldFilter)
FixtureConfiguration
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.
registerFieldFilter
in interface FixtureConfiguration
fieldFilter
- The FieldFilter that defines which fields to include in the comparison
public FixtureConfiguration registerIgnoredField(Class<?> declaringClass, String fieldName)
FixtureConfiguration
fieldName
, which is declared in given declaringClass
is ignored when performing deep equality checks.
registerIgnoredField
in interface FixtureConfiguration
declaringClass
- The class declaring the fieldfieldName
- The name of the field
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |