Search in sources :

Example 1 with HandlerInterceptorAdapter

use of org.springframework.web.servlet.handler.HandlerInterceptorAdapter in project spring-framework by spring-projects.

the class RequestMappingInfoHandlerMappingTests method getHandlerMappedInterceptors.

@Test
public void getHandlerMappedInterceptors() throws Exception {
    String path = "/foo";
    HandlerInterceptor interceptor = new HandlerInterceptorAdapter() {
    };
    MappedInterceptor mappedInterceptor = new MappedInterceptor(new String[] { path }, interceptor);
    TestRequestMappingInfoHandlerMapping mapping = new TestRequestMappingInfoHandlerMapping();
    mapping.registerHandler(new TestController());
    mapping.setInterceptors(new Object[] { mappedInterceptor });
    mapping.setApplicationContext(new StaticWebApplicationContext());
    HandlerExecutionChain chain = mapping.getHandler(new MockHttpServletRequest("GET", path));
    assertNotNull(chain);
    assertNotNull(chain.getInterceptors());
    assertSame(interceptor, chain.getInterceptors()[0]);
    chain = mapping.getHandler(new MockHttpServletRequest("GET", "/invalid"));
    assertNull(chain);
}
Also used : MappedInterceptor(org.springframework.web.servlet.handler.MappedInterceptor) HandlerInterceptor(org.springframework.web.servlet.HandlerInterceptor) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) HandlerInterceptorAdapter(org.springframework.web.servlet.handler.HandlerInterceptorAdapter) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)1 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)1 HandlerInterceptor (org.springframework.web.servlet.HandlerInterceptor)1 HandlerInterceptorAdapter (org.springframework.web.servlet.handler.HandlerInterceptorAdapter)1 MappedInterceptor (org.springframework.web.servlet.handler.MappedInterceptor)1