Any hints on how to test Spring dependent aggregates?

I have a small project up and running with Aggregates that have Spring dependencies. With some effort I figured out how to write unittests using the Spring JUnit runner, and I can see that they are loaded and injected just fine.

The reason I write, is that I would like to use the nice GivenWhenThen fixtures to test my code without a full spring context. How do I get the axon test framework to inject my Mockito dependencies when loading the aggregates?

/Mads

Hi Mads,

I am assuming you are using Axon 1.3. You will need to register a Repository with the fixtures, instead of using “createGenericRepository()”. In the constructor of “EventSourcingRepository” (the repository that you most likely want to use), you can pass an AggregateFactory. The AggregateFactory is responsible for creating an uninitialized Aggregate. That’s the place where you can inject resources that the Aggregate may use during its lifecycle.
You don’t need to set an EventBus or EventStore on the Repository; the fixture will do that for you.

Cheers,

Allard

That was my conclusion as well, but I was wondering why SpringPrototypeEventSourcingRepository’s constructor is deprecated?

/Mads

It is deprecated because it is replaced with a normal EventSourcingRepository and a SpringPrototypeAggregateFactory as constructor parameter.
So “new SpringPrototypeEventSourcingRepository()” became “new EventSourcingRepository(new SpringPrototypeAggregateFactory())”. I noticed there is no documentation about the deprecation on the constructor. Must have overlooked that one. Sorry for that.

Cheers,

Allard