Search in sources :

Example 51 with HandlerExecutionChain

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

the class PathMatchingUrlHandlerMappingTests method defaultMapping.

@Test
public void defaultMapping() throws Exception {
    Object bean = wac.getBean("starController");
    MockHttpServletRequest req = new MockHttpServletRequest("GET", "/goggog.html");
    HandlerExecutionChain hec = getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
}
Also used : HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Test(org.junit.Test)

Example 52 with HandlerExecutionChain

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

the class PathMatchingUrlHandlerMappingTests method requestsWithHandlers.

@Test
public void requestsWithHandlers() throws Exception {
    Object bean = wac.getBean("mainController");
    MockHttpServletRequest req = new MockHttpServletRequest("GET", "/welcome.html");
    HandlerExecutionChain hec = getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
    req = new MockHttpServletRequest("GET", "/show.html");
    hec = getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
    req = new MockHttpServletRequest("GET", "/bookseats.html");
    hec = getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
}
Also used : HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Test(org.junit.Test)

Example 53 with HandlerExecutionChain

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

the class RequestMappingInfoHandlerMappingTests method getHandler.

private HandlerMethod getHandler(MockHttpServletRequest request) throws Exception {
    HandlerExecutionChain chain = this.handlerMapping.getHandler(request);
    assertNotNull(chain);
    return (HandlerMethod) chain.getHandler();
}
Also used : HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 54 with HandlerExecutionChain

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

the class CrossOriginTests method customOriginDefinedViaValueAttribute.

@Test
public void customOriginDefinedViaValueAttribute() throws Exception {
    this.handlerMapping.registerHandler(new MethodLevelController());
    this.request.setRequestURI("/customOrigin");
    HandlerExecutionChain chain = this.handlerMapping.getHandler(request);
    CorsConfiguration config = getCorsConfiguration(chain, false);
    assertNotNull(config);
    assertEquals(Arrays.asList("http://example.com"), config.getAllowedOrigins());
    assertTrue(config.getAllowCredentials());
}
Also used : CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) Test(org.junit.Test)

Example 55 with HandlerExecutionChain

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

the class CrossOriginTests method preFlightRequest.

@Test
public void preFlightRequest() throws Exception {
    this.handlerMapping.registerHandler(new MethodLevelController());
    this.request.setMethod("OPTIONS");
    this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
    this.request.setRequestURI("/default");
    HandlerExecutionChain chain = this.handlerMapping.getHandler(request);
    CorsConfiguration config = getCorsConfiguration(chain, true);
    assertNotNull(config);
    assertArrayEquals(new String[] { "GET" }, config.getAllowedMethods().toArray());
    assertArrayEquals(new String[] { "*" }, config.getAllowedOrigins().toArray());
    assertTrue(config.getAllowCredentials());
    assertArrayEquals(new String[] { "*" }, config.getAllowedHeaders().toArray());
    assertTrue(CollectionUtils.isEmpty(config.getExposedHeaders()));
    assertEquals(new Long(1800), config.getMaxAge());
}
Also used : CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) Test(org.junit.Test)

Aggregations

HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)61 Test (org.junit.Test)47 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)28 CorsConfiguration (org.springframework.web.cors.CorsConfiguration)16 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)11 HandlerInterceptor (org.springframework.web.servlet.HandlerInterceptor)9 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)8 ConversionServiceExposingInterceptor (org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor)7 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)7 HandlerMethod (org.springframework.web.method.HandlerMethod)6 ModelAndView (org.springframework.web.servlet.ModelAndView)6 LocaleChangeInterceptor (org.springframework.web.servlet.i18n.LocaleChangeInterceptor)5 ThemeChangeInterceptor (org.springframework.web.servlet.theme.ThemeChangeInterceptor)5 Mock (org.jmock.Mock)4 ContentNegotiationManager (org.springframework.web.accept.ContentNegotiationManager)3 NativeWebRequest (org.springframework.web.context.request.NativeWebRequest)3 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)3 HttpRequestHandlerAdapter (org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ApplicationContext (org.springframework.context.ApplicationContext)2