scenario on how to test Saga that calls autowired services


I am curious to know how to deal with testing Saga calling some autowired Spring services : actually, my aggregate root is a post, once the post is created I send a PostCreatedEvent, to my Saga. The handler of this event in the Saga calls BlackListingService, that returns a boolean if the result is positive a BlacklistPostCommand is dispatched, otherwise I schedule an ArchivePostCommand using the scheduler and dispatch an AcceptPostCommand.

So while testing, all the autowired services are null .


you’re not abusing Sagas (as far as I can tell). It’s normal for a Saga to request information from other locations.
In the test fixture, you can register resources. These resources can then be used as parameters to @…Handler methods or as dependencies in Sagas.
I recommend using Stubs or Mocks as these resources for testing.



Great!!! many thanks