Testing Non-aggregate events

I’m trying to get some advice on how to test the behaviour of aggregates when processing events that are dispatched from a non aggregate.

I’m trying to ensure an aggregate field is unique on creation. I’m trying to handle the eventually consistency of the projections by using the following flow:

  1. Command creates a new aggregate
  2. Aggregate issues creation event
  3. Event handler attempts to materialize the projection and if there is a uniqueness violation, it emits a UniqueConstraintViolationEvent
  4. Aggregate consumes this event and marks itself as deleted

I’m trying to use the AggregateTestFixture to test this, but it doesn’t appear to allow you to preform any assertions without issuing a command (whenThenTimeElapses seems to allow assertions, but I get a NPE when asserting the aggregate has been deleted). Is there a way to use the test fixture for this case, or is it not designed to account for non-aggregate events. If not, is there another way to verify that the aggregate has been removed?

I’m not confident that this is actually the correct approach. I’ve also considered dispatching a command in (3) or using a saga to manage the interaction. If I dispatch a command instead of an event, it seems to simply force me to write more boilerplate to emit the UniqueConstraintViolationEvent from the aggregate. Likewise, if I use a saga to model this interaction, I’m unsure how to end the saga’s lifecycle without having the projection materializer emit a success event that the saga consumes.

Any advice is greatly appreciated!

SO link: https://stackoverflow.com/questions/58703889/test-axon-aggregates-behaviour-with-non-aggregate-events
Github Issue: https://github.com/AxonFramework/AxonFramework/issues/1268