CommandHandler setup issue

140 views
Skip to first unread message

Lukáš Vasek

unread,
Aug 6, 2015, 12:42:41 PM8/6/15
to Axon Framework Users
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

Expected                                                            |  Actual
--------------------------------------------------------------------|--------------------------------------------------------------------
com.github.bilak.axonframework.poc.domain.user.UserRegisteredEvent <|> 

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)



can somebody please suggest some fix for this?

Thanks 

Nedim Sabic

unread,
Aug 6, 2015, 1:51:07 PM8/6/15
to Axon Framework Users

Hi,

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.

Allard Buijze

unread,
Aug 6, 2015, 3:32:52 PM8/6/15
to Axon Framework Users
Lukas,

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.

Cheers,

Allard
--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lukáš Vasek

unread,
Aug 6, 2015, 5:26:47 PM8/6/15
to Axon Framework Users
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):

Allard Buijze

unread,
Aug 7, 2015, 1:08:42 AM8/7/15
to Axon Framework Users
It might also be another value on that line. Only debugging can provide the answer...

Lukáš Vasek

unread,
Aug 7, 2015, 2:38:26 AM8/7/15
to Axon Framework Users
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.

Allard Buijze

unread,
Aug 7, 2015, 10:05:02 AM8/7/15
to Axon Framework Users
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.

--
Reply all
Reply to author
Forward
0 new messages