I am writing a unit test for a service that I created which uses the Spring Security Core default User domain object which uses springSecurityService auto-wired. Here is the basic test code:
This fails because of the following:
Which points to default User domain object line that is:
How can I auto-wire or set the User domain object variable in this unit test:
I found out some more when I tried some different searches for other issues I was seeing. Here is a page on how to work in controller unit tests to get something similar working:
I tried this approach, as well, and it almost works in my controller that is using the service. After it has successfully used the service from the controller, I try to assert User.count() == 1 and it throws another exception on the encodePassword method as before. Why would the beforeInsert method on the User domain object get called even when asking for count()? I tried User.findByUsername(...) and it did the same thing?
When I tried the approach described in the article for the service it did not work. In fact, there is a comment on the article where a user had the same problem that I did:
This problem originally was listed on grails-user mailing list: