-
Notifications
You must be signed in to change notification settings - Fork 178
Description
Hi,
I was wondering how I can write integration tests that verify a business process that is driven by application events (a saga essentially).
For example, the creation of a new account triggers an invitation. After the invitation is accepted the account is activated.
The corresponding events are AccountCreationInitiated, InvitationAccepted, and AccountActivated.
I want to be able to write a test, that:
- Creates a new account
- Gets hold of the invitation (ideally through the published event because the invitation process is handled by another module)
- Accepts the invitation
- Verifies that
AccountActivatedwas published
I am able to write steps 1, 3, and 4 but step 2 is tricky. The problem is, that step two is performed by an @ApplicationModuleListener . This event handler is never called inside my test (it works if I start my application normally). I think it is because it waits for the transaction to finish but this never happens inside my test I think. The test runs fine if I replace the @ApplicationModuleListener with @EventHandler.
I am also not sure how the @Async annotation inside @ApplicationModuleListener interferes with my tests and how to reliably test these event handlers. I already added delays and timeouts to my verify calls which did not change the behavior.
Lastly, I would like to know if it makes sense to publish events inside my test methods to see how my system behaves.
How should I go about writing my integration tests?