CallbackBehaviorobject. This object is registered using
setCallbackBehavior()on the fixture and defines if and how the callback must be invoked when a command is dispatched.
CommandBusdirectly, you can also use command gateways. See below on how to specify their behavior.
fixture.registerResource(Object)method with the resource as parameter. The fixture will detect appropriate setter methods or fields (annotated with
@Inject) on the saga and invoke it with an available resource.
TipIt can be very useful to inject mock objects (e.g. Mockito or Easymock) into your Saga. It allows you to verify that the saga interacts correctly with your external resources.
registerCommandGateway(Class, Object). Both methods return an instance of the given class that represents the gateway to use. This instance is also registered as a resource, to make it eligible for resource injection.
registerCommandGateway(Class)is used to register a gateway, it dispatches Commands to the CommandBus managed by the fixture. The behavior of the gateway is mostly defined by the
CallbackBehaviordefined on the fixture. If no explicit
CallbackBehavioris provided, callbacks are not invoked, making it impossible to provide any return value for the gateway.
registerCommandGateway(Class, Object)is used to register a gateway, the second parameter is used to define the behavior of the gateway.
whenTimeElapses(). All events will have the timestamp of the moment the test fixture was created.
NoteThe fixture uses a
StubSchedulerfor time based activity, such as scheduling events and advancing time. Fixtures will set the timestamp of any events sent to the Saga instance to the time of this scheduler. This means time is 'stopped' as soon as the fixture starts, and may be advanced deterministically using the
StubEventSchedulerindependently of the test fixtures if you need to test scheduling of events. This
EventSchedulerimplementation allows you to verify which events are scheduled for which time and gives you options to manipulate the progress of time. You can either advance time with a specific
Duration, move the clock to a specific date and time or advance time to the next scheduled event. All these operations will return the events scheduled within the progressed interval.