Category Archives: MockMVC

Mocking Spring Security Principal for testing Spring MVC Controllers

How do you mock a Spring security principal for testing spring MVC controllers? Create a spring security principal Create a spring authentication Add the spring security authentication to the security context The last step should not be needed because MockMVC … Continue reading

Posted in Java, MockMVC, Spring, Spring MVC, Spring Security | Tagged , , , , , , , , , , , , , , | 2 Comments

Testing Spring MVC Rest controllers

Spring MVC 3.2 introduced the ability to test controllers via MockMVC. In this example, we will test a controller that returns JSON via @ResponseBody. Here are the dependencies that you will need. This is an example of the spring context. … Continue reading

Posted in Java, MockMVC, Spring, Spring MVC | Tagged , , , , , , , | Leave a comment