Creating tests on secured applications
Spring TestContext can also provide ways to test methods and controllers that need login credentials, which many applications with Spring Security integration require. This recipe builds MockMvc to the ApplicationContext container secured by the Spring Security 4.x module.
Getting ready
Open the Maven project ch04 and add test classes to test secured methods.
How to do it...
Let us apply security model to some service methods and test them using Spring TestContext:
- Add the Spring Test module, JUnit 4, and Mockito Maven dependencies to the project's
pom.xmlfile. - Add a specialized Spring Security Test dependency to the
pom.xmlfile:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>4.2.2.BUILD-SNAPSHOT</version>
<scope>test</scope>
</dependency> - Inside
src/test/java...