|
@@ -18,25 +18,19 @@ package org.springframework.security.samples.config;
|
|
|
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.*;
|
|
|
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*;
|
|
|
import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.*;
|
|
|
+import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
|
|
|
|
-import javax.servlet.Filter;
|
|
|
-
|
|
|
import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.security.samples.mvc.config.WebMvcConfiguration;
|
|
|
import org.springframework.security.test.context.support.WithMockUser;
|
|
|
-import org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener;
|
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
|
-import org.springframework.test.context.TestExecutionListeners;
|
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
-import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
|
|
-import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
|
|
-import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
|
|
-import org.springframework.test.context.web.ServletTestExecutionListener;
|
|
|
import org.springframework.test.context.web.WebAppConfiguration;
|
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
|
@@ -50,25 +44,18 @@ import org.springframework.web.context.WebApplicationContext;
|
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
@ContextConfiguration(classes = { RootConfiguration.class, WebMvcConfiguration.class })
|
|
|
@WebAppConfiguration
|
|
|
-@TestExecutionListeners(listeners = { ServletTestExecutionListener.class,
|
|
|
- DependencyInjectionTestExecutionListener.class,
|
|
|
- DirtiesContextTestExecutionListener.class,
|
|
|
- TransactionalTestExecutionListener.class,
|
|
|
- WithSecurityContextTestExecutionListener.class })
|
|
|
public class SecurityConfigTests {
|
|
|
private MockMvc mvc;
|
|
|
|
|
|
@Autowired
|
|
|
private WebApplicationContext context;
|
|
|
|
|
|
- @Autowired
|
|
|
- private Filter springSecurityFilterChain;
|
|
|
|
|
|
@Before
|
|
|
public void setup() {
|
|
|
mvc = MockMvcBuilders.webAppContextSetup(context)
|
|
|
- .addFilters(springSecurityFilterChain)
|
|
|
- .defaultRequest(get("/").with(testSecurityContext())).build();
|
|
|
+ .apply(springSecurity())
|
|
|
+ .defaultRequest(get("/").accept(MediaType.TEXT_HTML)).build();
|
|
|
}
|
|
|
|
|
|
@Test
|