Property init HandlerMapping in standalone MockMvc
Issue: SPR-13637
This commit is contained in:
parent
62af99a21c
commit
8c127ad3c9
|
|
@ -342,6 +342,7 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
|
|||
StaticRequestMappingHandlerMapping hm = config.getHandlerMapping();
|
||||
hm.setServletContext(wac.getServletContext());
|
||||
hm.setApplicationContext(wac);
|
||||
hm.afterPropertiesSet();
|
||||
hm.registerHandlers(this.controllers);
|
||||
wac.addBean("requestMappingHandlerMapping", hm);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import org.junit.Test;
|
|||
import org.springframework.http.converter.json.SpringHandlerInstantiator;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
|
@ -50,9 +51,10 @@ import static org.junit.Assert.*;
|
|||
*/
|
||||
public class StandaloneMockMvcBuilderTests {
|
||||
|
||||
@Test // SPR-10825
|
||||
public void placeHoldersInRequestMapping() throws Exception {
|
||||
// SPR-10825
|
||||
|
||||
@Test
|
||||
public void placeHoldersInRequestMapping() throws Exception {
|
||||
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController());
|
||||
builder.addPlaceHolderValue("sys.login.ajax", "/foo");
|
||||
builder.build();
|
||||
|
|
@ -66,7 +68,29 @@ public class StandaloneMockMvcBuilderTests {
|
|||
assertEquals("handleWithPlaceholders", ((HandlerMethod) chain.getHandler()).getMethod().getName());
|
||||
}
|
||||
|
||||
@Test // SPR-12553
|
||||
// SPR-13637
|
||||
|
||||
@Test
|
||||
public void suffixPatternMatch() throws Exception {
|
||||
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
|
||||
builder.setUseSuffixPatternMatch(false);
|
||||
builder.build();
|
||||
|
||||
RequestMappingHandlerMapping hm = builder.wac.getBean(RequestMappingHandlerMapping.class);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/persons");
|
||||
HandlerExecutionChain chain = hm.getHandler(request);
|
||||
assertNotNull(chain);
|
||||
assertEquals("persons", ((HandlerMethod) chain.getHandler()).getMethod().getName());
|
||||
|
||||
request = new MockHttpServletRequest("GET", "/persons.xml");
|
||||
chain = hm.getHandler(request);
|
||||
assertNull(chain);
|
||||
}
|
||||
|
||||
// SPR-12553
|
||||
|
||||
@Test
|
||||
public void applicationContextAttribute() {
|
||||
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController());
|
||||
builder.addPlaceHolderValue("sys.login.ajax", "/foo");
|
||||
|
|
@ -100,7 +124,9 @@ public class StandaloneMockMvcBuilderTests {
|
|||
builder.addFilter(new ContinueFilter(), (String) null);
|
||||
}
|
||||
|
||||
@Test // SPR-13375
|
||||
// SPR-13375
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void springHandlerInstantiator() {
|
||||
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
|
||||
|
|
@ -112,6 +138,7 @@ public class StandaloneMockMvcBuilderTests {
|
|||
|
||||
|
||||
@Controller
|
||||
@SuppressWarnings("unused")
|
||||
private static class PlaceholderController {
|
||||
|
||||
@RequestMapping(value = "${sys.login.ajax}")
|
||||
|
|
@ -135,7 +162,14 @@ public class StandaloneMockMvcBuilderTests {
|
|||
}
|
||||
|
||||
@Controller
|
||||
@SuppressWarnings("unused")
|
||||
private static class PersonController {
|
||||
|
||||
@RequestMapping(value="/persons")
|
||||
public String persons() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequestMapping(value="/forward")
|
||||
public String forward() {
|
||||
return "forward:/persons";
|
||||
|
|
@ -143,9 +177,11 @@ public class StandaloneMockMvcBuilderTests {
|
|||
}
|
||||
|
||||
private class ContinueFilter extends OncePerRequestFilter {
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
|
||||
FilterChain filterChain) throws ServletException, IOException {
|
||||
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue