Best way to integration test the starting of a saga?

Hi,

For integration tests what would be the best way to test that a saga has been started?

Right now I am thinking:

  1. Clear the saga_entry and association_value_entry tables.
  2. Issue the event(s) required to kick-off the saga.
  3. Check there is a new entry in the saga_entry table and the saga_type matches what we expect.
  4. Check there is a new entry in the association_value_entry table with the associationKey with what is expected.

Is there a better way in doing this that anyone would recommend?

Also this way involves using the org.axonframework.modelling.saga.repository.jpa.AssociationValueEntry and org.axonframework.modelling.saga.repository.jpa.SagaEntry entities directly. Is this ok, or not recommended?

Do I need to do something with the TokenEntry table as well?

Regards,
vab2048

Hi @vab2048,

As far as integration tests go, I typically tend to only validate the inputs and the outputs, not the process in the middle. As the Saga definitely is a process in the middle, I would regard this as not important when doing the integration test to be honest.

However, if you do feel validating the fact a Saga is being used to resolve the internal process, you could indeed query the tables to validate if the saga is actually there. I’d personally use the SagaRepository for this, as it allows you to retrieve a saga based on an AssociationValue. The latter is an object reflecting the associations you would define on the @StartSaga annotated method or through the SagaLifecycle#associateWith(...) method.

Prior to starting off such an integration test I would indeed clear out any tables really, thus including the saga_entry and association_value_entry. Doing a clear on all tables, without knowing which are their (to not tap into the fact a Saga is being used), should suffice here to I think.

That’s my two cents on the situation.
Hope this helps you out further @vab2048!

Cheers,
Steven

Thanks Steven - this makes sense.

To add some more info about why I was doing this - the saga resides in its own bounded context.

And so as part of the test suite of the aggregate which publishes the @StartSaga event I just wanted to make sure the saga was kicked off (and if it is not kicked off the test should fail).

Regards,
vab2048

1 Like