|
|
@ -42,17 +42,17 @@ public class SimpleUrlHandlerMappingTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@SuppressWarnings("resource") |
|
|
|
@SuppressWarnings("resource") |
|
|
|
public void handlerBeanNotFound() throws Exception { |
|
|
|
public void handlerBeanNotFound() { |
|
|
|
MockServletContext sc = new MockServletContext(""); |
|
|
|
MockServletContext sc = new MockServletContext(""); |
|
|
|
XmlWebApplicationContext root = new XmlWebApplicationContext(); |
|
|
|
XmlWebApplicationContext root = new XmlWebApplicationContext(); |
|
|
|
root.setServletContext(sc); |
|
|
|
root.setServletContext(sc); |
|
|
|
root.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map1.xml"}); |
|
|
|
root.setConfigLocations("/org/springframework/web/servlet/handler/map1.xml"); |
|
|
|
root.refresh(); |
|
|
|
root.refresh(); |
|
|
|
XmlWebApplicationContext wac = new XmlWebApplicationContext(); |
|
|
|
XmlWebApplicationContext wac = new XmlWebApplicationContext(); |
|
|
|
wac.setParent(root); |
|
|
|
wac.setParent(root); |
|
|
|
wac.setServletContext(sc); |
|
|
|
wac.setServletContext(sc); |
|
|
|
wac.setNamespace("map2err"); |
|
|
|
wac.setNamespace("map2err"); |
|
|
|
wac.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map2err.xml"}); |
|
|
|
wac.setConfigLocations("/org/springframework/web/servlet/handler/map2err.xml"); |
|
|
|
try { |
|
|
|
try { |
|
|
|
wac.refresh(); |
|
|
|
wac.refresh(); |
|
|
|
fail("Should have thrown NoSuchBeanDefinitionException"); |
|
|
|
fail("Should have thrown NoSuchBeanDefinitionException"); |
|
|
@ -95,7 +95,7 @@ public class SimpleUrlHandlerMappingTests { |
|
|
|
MockServletContext sc = new MockServletContext(""); |
|
|
|
MockServletContext sc = new MockServletContext(""); |
|
|
|
XmlWebApplicationContext wac = new XmlWebApplicationContext(); |
|
|
|
XmlWebApplicationContext wac = new XmlWebApplicationContext(); |
|
|
|
wac.setServletContext(sc); |
|
|
|
wac.setServletContext(sc); |
|
|
|
wac.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map2.xml"}); |
|
|
|
wac.setConfigLocations("/org/springframework/web/servlet/handler/map2.xml"); |
|
|
|
wac.refresh(); |
|
|
|
wac.refresh(); |
|
|
|
Object bean = wac.getBean("mainController"); |
|
|
|
Object bean = wac.getBean("mainController"); |
|
|
|
Object otherBean = wac.getBean("otherController"); |
|
|
|
Object otherBean = wac.getBean("otherController"); |
|
|
@ -106,11 +106,13 @@ public class SimpleUrlHandlerMappingTests { |
|
|
|
HandlerExecutionChain hec = getHandler(hm, req); |
|
|
|
HandlerExecutionChain hec = getHandler(hm, req); |
|
|
|
assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean); |
|
|
|
assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean); |
|
|
|
assertEquals("/welcome.html", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)); |
|
|
|
assertEquals("/welcome.html", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)); |
|
|
|
|
|
|
|
assertEquals(bean, req.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE)); |
|
|
|
|
|
|
|
|
|
|
|
req = new MockHttpServletRequest("GET", "/welcome.x"); |
|
|
|
req = new MockHttpServletRequest("GET", "/welcome.x"); |
|
|
|
hec = getHandler(hm, req); |
|
|
|
hec = getHandler(hm, req); |
|
|
|
assertTrue("Handler is correct bean", hec != null && hec.getHandler() == otherBean); |
|
|
|
assertTrue("Handler is correct bean", hec != null && hec.getHandler() == otherBean); |
|
|
|
assertEquals("welcome.x", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)); |
|
|
|
assertEquals("welcome.x", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)); |
|
|
|
|
|
|
|
assertEquals(otherBean, req.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE)); |
|
|
|
|
|
|
|
|
|
|
|
req = new MockHttpServletRequest("GET", "/welcome/"); |
|
|
|
req = new MockHttpServletRequest("GET", "/welcome/"); |
|
|
|
hec = getHandler(hm, req); |
|
|
|
hec = getHandler(hm, req); |
|
|
|