Search in sources :

Example 56 with PathPatternsParameterizedTest

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

the class UriTemplateServletAnnotationControllerHandlerMethodTests method customRegex.

@PathPatternsParameterizedTest
void customRegex(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(CustomRegexController.class, usePathPatterns);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/42;q=1;q=2");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).isEqualTo(!usePathPatterns ? "test-42-;q=1;q=2-[1, 2]" : "test-42--[1, 2]");
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 57 with PathPatternsParameterizedTest

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

the class UriTemplateServletAnnotationControllerHandlerMethodTests method variableNamesWithUrlExtension.

// gh-13187
@PathPatternsParameterizedTest
void variableNamesWithUrlExtension(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(VariableNamesController.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", "/test/foo.json");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo(!usePathPatterns ? "foo-foo" : "foo-foo.json");
}
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 58 with PathPatternsParameterizedTest

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

the class UriTemplateServletAnnotationControllerHandlerMethodTests method explicitSubPath.

@PathPatternsParameterizedTest
void explicitSubPath(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(ExplicitSubPathController.class, usePathPatterns);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels/42");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("test-42");
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 59 with PathPatternsParameterizedTest

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

the class UriTemplateServletAnnotationControllerHandlerMethodTests method ambiguous.

@PathPatternsParameterizedTest
void ambiguous(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(AmbiguousUriTemplateController.class, usePathPatterns);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels/new");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("specific");
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 60 with PathPatternsParameterizedTest

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

the class UriTemplateServletAnnotationControllerHandlerMethodTests method typeConversionError.

@PathPatternsParameterizedTest
void typeConversionError(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(SimpleUriTemplateController.class, usePathPatterns);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.xml");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getStatus()).as("Invalid response status code").isEqualTo(HttpServletResponse.SC_BAD_REQUEST);
}
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