`AggregateTestFixture` improvement - Validate Exception Details
Feature Description
This is about testing aggregates through the AggregateTestFixture. When it comes to testing exceptions thrown by a @CommandHandler, we have utilities to test the exception or its message, but not its details.
Current Behaviour
We have the following possibilities (taken from the doc):
fixture.expectException(Matcher)fixture.expectException(Class)fixture.expectExceptionMessage(String)fixture.expectExceptionMessage(Matcher)
Wanted Behaviour
I believe it would be nice to also be able to test the details property as it is common practice to use it within Axon Framework, i.e. something like:
fixture.expectExceptionDetails(Object)using equalityfixture.expectExceptionDetails(Class)matching the type of detailsfixture.expectExceptionDetails(Matcher)using a matcher
Possible Workarounds
For now, we can test the details using fixture.expectException(Matcher).
For example (this is Kotlin but the same is doable is Java):
// type check
fixture
.expectException(Matchers.predicate<Exception> {
it is CommandExecutionException && expectedDetails.isInstance(it.getDetails<Any>().orElse(null))
})
// equality check
fixture
expectException(Matchers.predicate<Exception> {
it is CommandExecutionException && expectedDetails == it.getDetails<Any>().orElse(null)
})
Using the above code works but as we use a predicate matcher, we do not have a nice description when the match fails.
💡 If you decide to implement this, it would also be nice to have it in the Kotlin extension, being able to give a KClass instead of a Class for example.
Thanks for drafting up this issue with us, @Arnaud-J. I had an internal discussion on the subject, and we think it's OK to introduce it.
We do feel a caveat here, though.
Mainly around expanding the interface of the ResultValidator even further with more 'detailed' validation cases.
However, that's already the case with the "explosion" of deadline validation steps we can do. As such, I feel an API change would be in order. However, changing the API is not something we do within minor releases.
Thus, since the status quo is to add more, we feel it's justified to add the suggested addition. However, it is to be expected that the solution will change when Axon 5 comes around the corner.
Lastly, I've added the "Ideal for Contribution" label to this issue since I believe it's an ideal contribution. If you're up to it, then we'd very much welcome a PR from your hands, @Arnaud-J.
@smcvb Here it is #2125
As such, I feel an API change would be in order. However, changing the API is not something we do within minor releases.
Thus, since the status quo is to add more, we feel it's justified to add the suggested addition. However, it is to be expected that the solution will change when Axon 5 comes around the corner.
This is more of an addition rather than a change, this does not modify anything in the existing features of AggregateTestFixture. Thus, I feel like it could be integrated safely in a 4.x release. What do you think?
Agreed there, @Arnaud-J.
The point I am trying to make is that we are making an addition, which feels like the ResultValidator is over-encumbered.
Given the current nature of the testing framework, it's only reasonable, though.
More importantly though, thanks for the effort of providing a pull request! I'll have a look as soon as my time allows it.
Closing this issue since it is resolved through pull request #2125.