Search in sources :

Example 71 with PathPatternsParameterizedTest

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

the class UrlFilenameViewControllerTests method withPlainFilename.

@PathPatternsParameterizedTest
void withPlainFilename(Function<String, MockHttpServletRequest> requestFactory) throws Exception {
    UrlFilenameViewController controller = new UrlFilenameViewController();
    MockHttpServletRequest request = requestFactory.apply("/index");
    ModelAndView mv = controller.handleRequest(request, new MockHttpServletResponse());
    assertThat(mv.getViewName()).isEqualTo("index");
    assertThat(mv.getModel().isEmpty()).isTrue();
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 72 with PathPatternsParameterizedTest

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

the class UrlFilenameViewControllerTests method withContextMapping.

@PathPatternsParameterizedTest
void withContextMapping(Function<String, MockHttpServletRequest> requestFactory) throws Exception {
    UrlFilenameViewController controller = new UrlFilenameViewController();
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myapp/docs/cvs/commit.html");
    request.setContextPath("/myapp");
    ServletRequestPathUtils.parseAndCache(request);
    ModelAndView mv = controller.handleRequest(request, new MockHttpServletResponse());
    assertThat(mv.getViewName()).isEqualTo("docs/cvs/commit");
    assertThat(mv.getModel().isEmpty()).isTrue();
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 73 with PathPatternsParameterizedTest

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

the class UrlFilenameViewControllerTests method withPrefixAndSuffix.

@PathPatternsParameterizedTest
void withPrefixAndSuffix(Function<String, MockHttpServletRequest> requestFactory) throws Exception {
    UrlFilenameViewController controller = new UrlFilenameViewController();
    controller.setPrefix("mypre_");
    controller.setSuffix("_mysuf");
    MockHttpServletRequest request = requestFactory.apply("/index.html");
    ModelAndView mv = controller.handleRequest(request, new MockHttpServletResponse());
    assertThat(mv.getViewName()).isEqualTo("mypre_index_mysuf");
    assertThat(mv.getModel().isEmpty()).isTrue();
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 74 with PathPatternsParameterizedTest

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

the class UrlFilenameViewControllerTests method nestedPathisUsedAsViewName_InBreakingChangeFromSpring12Line.

/**
 * This is the expected behavior, and it now has a test to prove it.
 * https://opensource.atlassian.com/projects/spring/browse/SPR-2789
 */
@PathPatternsParameterizedTest
void nestedPathisUsedAsViewName_InBreakingChangeFromSpring12Line(Function<String, MockHttpServletRequest> requestFactory) throws Exception {
    UrlFilenameViewController controller = new UrlFilenameViewController();
    MockHttpServletRequest request = requestFactory.apply("/products/view.html");
    ModelAndView mv = controller.handleRequest(request, new MockHttpServletResponse());
    assertThat(mv.getViewName()).isEqualTo("products/view");
    assertThat(mv.getModel().isEmpty()).isTrue();
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 75 with PathPatternsParameterizedTest

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

the class ServletAnnotationControllerHandlerMethodTests method unmappedPathMapping.

// gh-22543
@PathPatternsParameterizedTest
void unmappedPathMapping(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(UnmappedPathController.class, usePathPatterns);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bogus-unmapped");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getStatus()).isEqualTo(404);
    request = new MockHttpServletRequest("GET", "");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).isEqualTo("get");
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Aggregations

PathPatternsParameterizedTest (org.springframework.web.servlet.handler.PathPatternsParameterizedTest)195 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)171 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)142 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)37 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)19 CorsConfiguration (org.springframework.web.cors.CorsConfiguration)13 ModelAndView (org.springframework.web.servlet.ModelAndView)12 HttpSession (jakarta.servlet.http.HttpSession)7 Map (java.util.Map)7 MultiValueMap (org.springframework.util.MultiValueMap)7 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)6 ModelMap (org.springframework.ui.ModelMap)5 HandlerMethod (org.springframework.web.method.HandlerMethod)5 InvocableHandlerMethod (org.springframework.web.method.support.InvocableHandlerMethod)5 ArrayList (java.util.ArrayList)4 MarshallingHttpMessageConverter (org.springframework.http.converter.xml.MarshallingHttpMessageConverter)4 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)4 RequestMappingInfo (org.springframework.web.servlet.mvc.method.RequestMappingInfo)4 MockMultipartFile (org.springframework.web.testfixture.servlet.MockMultipartFile)4 MockMultipartHttpServletRequest (org.springframework.web.testfixture.servlet.MockMultipartHttpServletRequest)4