I want to test my spring mvc controller.
The controller has a service:
@Autowired UserService userService
And my user service depends on (autowired) my UserDao and some other services like mongoDb etc.
Now I want the business logic to be tested in my UserService, but of course I want to mock the answers from my UserDao and Mongodb, etc.
How to configure my unit test?
Is it possible to reuse the container xml spring file that has all my beans, etc., or am I creating a new one? (I assume I need to get the spring container here)
Looking for some guidance on this, any lessons will be greatly appreciated.
Update
What seems strange to me is that for my spring controller (which is not implemented with Controller) I managed to access my private varialbe to manually install my service, for example:
@Controller public class UserController { @Autowired UserService userService; }
And in my unit test, I could do:
UserController controller = new UserController(); controller.userService = ....
But for my UserService, which has a UserDao answering machine, I cannot access the userDao property:
UserService userService = new UserServiceImpl(); userService.userDao = .... // not available
This makes sense since it is private, but how does it work for my controller?