Search in sources :

Example 6 with DefaultServletHttpRequestHandler

use of org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler in project spring-framework by spring-projects.

the class MvcNamespaceTests method testDefaultServletHandler.

@Test
public void testDefaultServletHandler() throws Exception {
    loadBeanDefinitions("mvc-config-default-servlet.xml", 6);
    HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
    assertNotNull(adapter);
    DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class);
    assertNotNull(handler);
    SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
    assertNotNull(mapping);
    assertEquals(Ordered.LOWEST_PRECEDENCE, mapping.getOrder());
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/foo.css");
    request.setMethod("GET");
    HandlerExecutionChain chain = mapping.getHandler(request);
    assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler);
    MockHttpServletResponse response = new MockHttpServletResponse();
    ModelAndView mv = adapter.handle(request, response, chain.getHandler());
    assertNull(mv);
}
Also used : HttpRequestHandlerAdapter(org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) DefaultServletHttpRequestHandler(org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler) SimpleUrlHandlerMapping(org.springframework.web.servlet.handler.SimpleUrlHandlerMapping) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

DefaultServletHttpRequestHandler (org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler)6 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)5 Test (org.junit.Test)4 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)2 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 HttpRequestHandlerAdapter (org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter)2 HashMap (java.util.HashMap)1 HttpRequestHandler (org.springframework.web.HttpRequestHandler)1