Search in sources :

Example 51 with PathPatternsParameterizedTest

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

the class ServletAnnotationControllerHandlerMethodTests method relativeMethodPathDispatchingController.

@PathPatternsParameterizedTest
void relativeMethodPathDispatchingController(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(MyRelativeMethodPathDispatchingController.class, usePathPatterns, wac -> {
        if (!usePathPatterns) {
            RootBeanDefinition mappingDef = new RootBeanDefinition(RequestMappingHandlerMapping.class);
            mappingDef.getPropertyValues().add("useSuffixPatternMatch", true);
            wac.registerBeanDefinition("handlerMapping", mappingDef);
        }
    });
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myApp/myHandle");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("myView");
    request = new MockHttpServletRequest("GET", "/yourApp/myOther");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("myOtherView");
    request = new MockHttpServletRequest("GET", "/hisApp/myLang");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("myLangView");
    request = new MockHttpServletRequest("GET", "/herApp/surprise.do");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    if (!usePathPatterns) {
        assertThat(response.getStatus()).isEqualTo(200);
        assertThat(response.getContentAsString()).isEqualTo("mySurpriseView");
    } else {
        assertThat(response.getStatus()).as("Suffixes pattern matching should not work with PathPattern's").isEqualTo(404);
    }
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 52 with PathPatternsParameterizedTest

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

the class ServletAnnotationControllerHandlerMethodTests method multipartFileAsSingleString.

@PathPatternsParameterizedTest
void multipartFileAsSingleString(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(MultipartController.class, usePathPatterns);
    MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
    request.setRequestURI("/singleString");
    request.addFile(new MockMultipartFile("content", "Juergen".getBytes()));
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("Juergen");
}
Also used : MockMultipartFile(org.springframework.web.testfixture.servlet.MockMultipartFile) MockMultipartHttpServletRequest(org.springframework.web.testfixture.servlet.MockMultipartHttpServletRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 53 with PathPatternsParameterizedTest

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

the class ServletAnnotationControllerHandlerMethodTests method bridgeMethodsWithMultipleInterfaces.

@PathPatternsParameterizedTest
void bridgeMethodsWithMultipleInterfaces(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(ArticleController.class, usePathPatterns);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/method");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 54 with PathPatternsParameterizedTest

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

the class UriTemplateServletAnnotationControllerHandlerMethodTests method extension.

@PathPatternsParameterizedTest
void extension(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(SimpleUriTemplateController.class, usePathPatterns, wac -> {
        if (!usePathPatterns) {
            RootBeanDefinition mappingDef = new RootBeanDefinition(RequestMappingHandlerMapping.class);
            mappingDef.getPropertyValues().add("useSuffixPatternMatch", true);
            mappingDef.getPropertyValues().add("removeSemicolonContent", "false");
            wac.registerBeanDefinition("handlerMapping", mappingDef);
        }
    });
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/42;jsessionid=c0o7fszeb1;q=24.xml");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo(!usePathPatterns ? "test-42-24" : "test-42-24.xml");
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 55 with PathPatternsParameterizedTest

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

the class UriTemplateServletAnnotationControllerHandlerMethodTests method menuTree.

// gh-11306
@PathPatternsParameterizedTest
void menuTree(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(MenuTreeController.class, usePathPatterns);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/book/menu/type/M5");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("M5");
}
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