How to simulate a SimpleCorrelationDataProvider with AggregateTestFixture?

I am using a SimpleCorrelationDataProvider to copy metadata from my CommandMessage to every EventMessage.

How can i simulate this behaviour using AggregateTestFixture?

I can use fixture.registerCommandDispatchInterceptor(…) which works fine to add metadata to all my test commands.

But the RecordingEventStore implementation of registerDispatchInterceptor has no effect at all.

I am injecting my metadata on my event handler like this:

fun on(payload: Payload, meta: MetaData) {


I relay on certain fields to be set in the metadata object here.

Should i consider putting required fields into the payload?

On the other hand the @MetaDataValue annotation also has a required flag.

Using axon 4.1

Hi Stefan,

in your ‘given’ events, you will need to add the meta data yourself, if your aggregate relies on it. The dispatch interceptor on the command bus will only affect the events generated as a result of commands.

You can use GenericEventMessage.asEventMessage(…).andMetaData(…) to attach meta data to events.

Hope this helps.


Hi Allard,

thanks for the fast reply.

You are right, i could use given(events) but i want to use givenCommands(…) to test the decision making code.

But the event that i apply in the @CommandHandler is missing the metadata and then my @EventSourcingHandler fails.

Something like this:

Hi Stefan,

The same suggestion to populate MetaData beforehand on events applies to commands.
To that end, you could utilize the GenericCommandMessage.asCommandMessage({your-command-object}).andMetaData(…) chain to achieve just that.

Additionally, I’d like to point out that if you are event sourcing your Aggregates, we typically suggest to not use the expectState method.
Your aggregate is derived from the events it publishes, so verifying the events should be sufficient to testing your scenario.
The expecState method was introduced for the users which use a state-stored approach for aggregates instead of event sourcing.

Hope this helps!