|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2012 the original author or authors. |
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
@ -13,18 +13,14 @@ |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.test.web.servlet.samples.standalone; |
|
|
|
package org.springframework.test.web.servlet.samples.standalone; |
|
|
|
|
|
|
|
|
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
import java.security.Principal; |
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
|
|
|
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; |
|
|
|
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
|
|
|
|
|
|
|
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
|
|
|
|
import org.springframework.mock.web.MockHttpServletRequest; |
|
|
|
import org.springframework.mock.web.MockHttpServletRequest; |
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
import org.springframework.test.web.servlet.MockMvc; |
|
|
|
import org.springframework.test.web.servlet.MockMvc; |
|
|
@ -36,7 +32,10 @@ import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
import org.springframework.web.context.WebApplicationContext; |
|
|
|
import org.springframework.web.context.WebApplicationContext; |
|
|
|
|
|
|
|
|
|
|
|
import java.security.Principal; |
|
|
|
import static org.mockito.Mockito.*; |
|
|
|
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; |
|
|
|
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; |
|
|
|
|
|
|
|
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Demonstrates use of SPI extension points: |
|
|
|
* Demonstrates use of SPI extension points: |
|
|
@ -48,6 +47,7 @@ import java.security.Principal; |
|
|
|
* </ul> |
|
|
|
* </ul> |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
|
|
|
|
* @since 4.1 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class FrameworkExtensionTests { |
|
|
|
public class FrameworkExtensionTests { |
|
|
|
|
|
|
|
|
|
|
@ -59,7 +59,6 @@ public class FrameworkExtensionTests { |
|
|
|
this.mockMvc = standaloneSetup(new SampleController()).apply(defaultSetup()).build(); |
|
|
|
this.mockMvc = standaloneSetup(new SampleController()).apply(defaultSetup()).build(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void fooHeader() throws Exception { |
|
|
|
public void fooHeader() throws Exception { |
|
|
|
this.mockMvc.perform(get("/").with(headers().foo("a=b"))).andExpect(content().string("Foo")); |
|
|
|
this.mockMvc.perform(get("/").with(headers().foo("a=b"))).andExpect(content().string("Foo")); |
|
|
@ -70,7 +69,6 @@ public class FrameworkExtensionTests { |
|
|
|
this.mockMvc.perform(get("/").with(headers().bar("a=b"))).andExpect(content().string("Bar")); |
|
|
|
this.mockMvc.perform(get("/").with(headers().bar("a=b"))).andExpect(content().string("Bar")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static TestMockMvcConfigurer defaultSetup() { |
|
|
|
private static TestMockMvcConfigurer defaultSetup() { |
|
|
|
return new TestMockMvcConfigurer(); |
|
|
|
return new TestMockMvcConfigurer(); |
|
|
|
} |
|
|
|
} |
|
|
@ -80,7 +78,6 @@ public class FrameworkExtensionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Test {@code RequestPostProcessor}. |
|
|
|
* Test {@code RequestPostProcessor}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -119,7 +116,8 @@ public class FrameworkExtensionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder, WebApplicationContext context) { |
|
|
|
public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder, |
|
|
|
|
|
|
|
WebApplicationContext context) { |
|
|
|
return request -> { |
|
|
|
return request -> { |
|
|
|
request.setUserPrincipal(mock(Principal.class)); |
|
|
|
request.setUserPrincipal(mock(Principal.class)); |
|
|
|
return request; |
|
|
|
return request; |
|
|
|