Skip to content

Testing event choreography #95

@danstooamerican

Description

@danstooamerican

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:

  1. Creates a new account
  2. Gets hold of the invitation (ideally through the published event because the invitation process is handled by another module)
  3. Accepts the invitation
  4. Verifies that AccountActivated was 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions