Hello,
I’ve got poc project here https://github.com/bilak/axonframework-poc .
I can’t solve issue (maybe it’s my bad configuration) when doing test. There is one UserTest class which is testing command/event with fixture.
When command is distributed to commandHandler (UserCommandHandler) nullpointerexception is thrown because application complains that Repository is not available (is null) but that’s not true, because when I point to setUserRepository method, I can see that repository is being injected.
Is Axon creating separate bean of commandHandler and holding it somewhere inside it context?
I have this excption:
org.axonframework.test.AxonAssertionError: The published events do not match the expected events
A probable cause for the wrong chain of events is an exception that occurred while handling the command.
java.lang.NullPointerException
at com.github.bilak.axonframework.poc.command.user.UserCommandHandler.handleRegisterUser(UserCommandHandler.java:22)
It’s probably because of an error during the Spring application context bootstrapping. I couldn’t find the initialization of dataSource bean in your Spring config.
check line 22 of UserCommandHandler. As the test result indicates, it raises a Null pointer exception. Note that the test fixtures don’t set up a Spring context. If you need to inject properties in your command handler, you need to so so yourself.
But that’s weird, because when I put some logging to setUserRepository, I can see that it’s injected in there. So I don’t understand why then userRepository is null.
Dňa štvrtok, 6. augusta 2015 21:32:52 UTC+2 Allard Buijze napísal(-a):
OK I found that UserCommandHandler is another instance in JUnit test as that which has injected UserRepository.
But I’m confused, because I don’t know how to repair that.
I just created post on stackoverflow so maybe someone will hep me.
Looks like the question is answered on StackOverflow.
Generally, I don’t advise using Spring configuration in GivenWhenThen tests. Treat them as Unit tests and only inject the necessary components.