@Test public void overlappingMappings() throws Exception { BeanNameUrlHandlerMapping hm = (BeanNameUrlHandlerMapping) wac.getBean("handlerMapping"); Object anotherHandler = new Object(); hm.registerHandler("/mypath/testaross*", anotherHandler); Object bean = wac.getBean("godCtrl"); MockHttpServletRequest req = new MockHttpServletRequest("GET", "/mypath/test.html"); HandlerExecutionChain hec = hm.getHandler(req); assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean); req = new MockHttpServletRequest("GET", "/mypath/testarossa"); hec = hm.getHandler(req); assertTrue("Handler is correct bean", hec != null && hec.getHandler() == anotherHandler); req = new MockHttpServletRequest("GET", "/mypath/tes"); hec = hm.getHandler(req); assertTrue("Handler is correct bean", hec == null); }
@Test public void beanNameHandlerMapping() throws Exception { ApplicationContext context = initContext(WebConfig.class); BeanNameUrlHandlerMapping handlerMapping = context.getBean(BeanNameUrlHandlerMapping.class); assertEquals(2, handlerMapping.getOrder()); HttpServletRequest request = new MockHttpServletRequest("GET", "/testController"); HandlerExecutionChain chain = handlerMapping.getHandler(request); assertNotNull(chain); assertNotNull(chain.getInterceptors()); assertEquals(3, chain.getInterceptors().length); assertEquals(ConversionServiceExposingInterceptor.class, chain.getInterceptors()[1].getClass()); assertEquals(ResourceUrlProviderExposingInterceptor.class, chain.getInterceptors()[2].getClass()); }
@Test public void requestsWithFullPaths() throws Exception { BeanNameUrlHandlerMapping hm = new BeanNameUrlHandlerMapping(); hm.setAlwaysUseFullPath(true); hm.setApplicationContext(wac); Object bean = wac.getBean("godCtrl"); MockHttpServletRequest req = new MockHttpServletRequest("GET", "/mypath/welcome.html"); HandlerExecutionChain hec = hm.getHandler(req); assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean); req = new MockHttpServletRequest("GET", "/myapp/mypath/welcome.html"); req.setContextPath("/myapp"); hec = hm.getHandler(req); assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean); req = new MockHttpServletRequest("GET", "/mypath/welcome.html"); req.setContextPath(""); req.setServletPath("/mypath"); hec = hm.getHandler(req); assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean); req = new MockHttpServletRequest("GET", "/Myapp/mypath/welcome.html"); req.setContextPath("/myapp"); req.setServletPath("/mypath"); hec = hm.getHandler(req); assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean); req = new MockHttpServletRequest("GET", "/"); hec = hm.getHandler(req); assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean); }