Search in sources :

Example 96 with PathPatternsParameterizedTest

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

the class ServletAnnotationControllerHandlerMethodTests method explicitAndEmptyPathsControllerMapping.

@PathPatternsParameterizedTest
void explicitAndEmptyPathsControllerMapping(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(ExplicitAndEmptyPathsController.class, usePathPatterns);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("get");
    request = new MockHttpServletRequest("GET", "");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    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)

Example 97 with PathPatternsParameterizedTest

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

the class ServletAnnotationControllerHandlerMethodTests method testMatchWithoutMethodLevelPath.

@PathPatternsParameterizedTest
void testMatchWithoutMethodLevelPath(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(NoPathGetAndM2PostController.class, usePathPatterns);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/t1/m2");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getStatus()).isEqualTo(405);
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 98 with PathPatternsParameterizedTest

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

the class ServletAnnotationControllerHandlerMethodTests method parameterCsvAsStringArray.

@PathPatternsParameterizedTest
void parameterCsvAsStringArray(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(CsvController.class, usePathPatterns, wac -> {
        RootBeanDefinition csDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
        RootBeanDefinition wbiDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);
        wbiDef.getPropertyValues().add("conversionService", csDef);
        RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
        adapterDef.getPropertyValues().add("webBindingInitializer", wbiDef);
        wac.registerBeanDefinition("handlerAdapter", adapterDef);
    });
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/integerArray");
    request.setMethod("POST");
    request.addParameter("content", "1,2");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("1-2");
}
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 99 with PathPatternsParameterizedTest

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

the class ServletAnnotationControllerHandlerMethodTests method responseStatus.

@PathPatternsParameterizedTest
void responseStatus(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(ResponseStatusController.class, usePathPatterns);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/something");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("something");
    assertThat(response.getStatus()).isEqualTo(201);
    assertThat(response.getErrorMessage()).isEqualTo("It's alive!");
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 100 with PathPatternsParameterizedTest

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

the class ServletAnnotationControllerHandlerMethodTests method httpHeadExplicit.

@PathPatternsParameterizedTest
void httpHeadExplicit(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(ResponseEntityController.class, usePathPatterns);
    MockHttpServletRequest request = new MockHttpServletRequest("HEAD", "/stores");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getHeader("h1")).isEqualTo("v1");
}
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