FixtureResourceParameterResolverFactory not working?

Hey there,

just switched from 2.0.8 to 2.2.0 and noticed that the old SimpleResourceParameterResolverFactory isn’t around anymore. It tried replacing it with FixtureResourceParameterResolverFactory but always get the following error when executing tests:

org.axonframework.test.FixtureExecutionException: No resource of type [org.springframework.data.mongodb.core.MongoTemplate] has been registered. It is required for one of the handlers being executed.
at org.axonframework.test.FixtureResourceParameterResolverFactory$LazyParameterResolver.resolveParameterValue(FixtureResourceParameterResolverFactory.java:94)
at org.axonframework.common.annotation.MethodMessageHandler.invoke(MethodMessageHandler.java:83)
at org.axonframework.commandhandling.annotation.AggregateAnnotationCommandHandler$AggregateCommandHandler.handle(AggregateAnnotationCommandHandler.java:297)
at org.axonframework.commandhandling.annotation.AggregateAnnotationCommandHandler.handle(AggregateAnnotationCommandHandler.java:258)
at org.axonframework.commandhandling.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:63)
at org.axonframework.commandhandling.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:69)
at org.axonframework.test.GivenWhenThenTestFixture$AggregateRegisteringInterceptor.handle(GivenWhenThenTestFixture.java:474)
at org.axonframework.commandhandling.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:61)
at org.axonframework.commandhandling.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:69)
at org.axonframework.commandhandling.SimpleCommandBus.doDispatch(SimpleCommandBus.java:127)
at org.axonframework.commandhandling.SimpleCommandBus.doDispatch(SimpleCommandBus.java:103)
at org.axonframework.commandhandling.SimpleCommandBus.dispatch(SimpleCommandBus.java:75)
at org.axonframework.test.GivenWhenThenTestFixture.when(GivenWhenThenTestFixture.java:238)
at org.axonframework.test.GivenWhenThenTestFixture.when(GivenWhenThenTestFixture.java:227)

I’m calling FixtureResourceParameterResolverFactory.registerResource(Mockito.mock(MongoTemplate.class)); in a method annotated with @Before in before my unit tests. What is the correct way to set up resources for unit tests?

Greets!

I fixed by using the registerInjectableResource method of a Fixture. Example code:

private FixtureConfiguration fixture;

private ProductId id;

@Before
public void setUp() {
fixture = Fixtures.newGivenWhenThenFixture(MyAggregate.class);
fixture.registerInjectableResource(Mockito.mock(MongoTemplate.class));
}

Greets!

Hi Sebastian,

that’s exactly the way it’s supposed to be done :wink:

Cheers,

Allard