Event interceptors have no impact on AggregateTestFixture

Hi,

I have already used command dispatch and handler interceptors on AggregateTestFixture and they work perfectly fine. Recently, however, I had a use case where I wanted to add an event dispatch interceptor but this didn’t seem to do anything. I had a look at the implementation of AggregateTestFixture and found this:

public Registration registerDispatchInterceptor(MessageDispatchInterceptor<? super EventMessage<?>> dispatchInterceptor) {
    return () -> {
        return true;
    };
}

Is there a reason why this is not implemented or is this an oversight?

Regards,
Jens

Hi Jens,

it’s probably a bit of both. The fixture’s intent is to test the behavior of the aggregate, not so much of the interceptors.
However, I can imagine one could say the dispatch interceptor is part of the command handling component.
If you’d like to have this included, feel free to submit an issue (or better, a PR :slight_smile: ).

Cheers,
Allard

Hi Allard,

I use MessageDispatchInterceptors for command validation. Since they don’t work in tests, my tests fail. What do you suggest I do in this case?

Thanks

Hi Altug,

If you check the AggregateTestFixture API, you can see there is a registerCommandDispatchInterceptor() method on it.
Thus, in your Aggregate test cases, you can configure your MessageDispatchInterceptor by utilizing that method.

Hope this helps!

Cheers,
Steven