Search in sources :

Example 61 with PathPatternsParameterizedTest

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

the class UriTemplateServletAnnotationControllerHandlerMethodTests method crud.

@PathPatternsParameterizedTest
void crud(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(CrudController.class, usePathPatterns);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("list");
    request = new MockHttpServletRequest("GET", "/hotels/");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("list");
    request = new MockHttpServletRequest("POST", "/hotels");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("create");
    request = new MockHttpServletRequest("GET", "/hotels/42");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("show-42");
    request = new MockHttpServletRequest("GET", "/hotels/42/");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("show-42");
    request = new MockHttpServletRequest("PUT", "/hotels/42");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("createOrUpdate-42");
    request = new MockHttpServletRequest("DELETE", "/hotels/42");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("remove-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 62 with PathPatternsParameterizedTest

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

the class DefaultRequestToViewNameTranslatorTests method testGetViewNameWithSuffix.

@PathPatternsParameterizedTest
void testGetViewNameWithSuffix(Function<String, MockHttpServletRequest> requestFactory) {
    final String suffix = ".fiona";
    MockHttpServletRequest request = requestFactory.apply(VIEW_NAME);
    this.translator.setSuffix(suffix);
    assertViewName(request, VIEW_NAME + suffix);
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 63 with PathPatternsParameterizedTest

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

the class DefaultRequestToViewNameTranslatorTests method testGetViewNameLeavesExtensionIfSoConfigured.

@PathPatternsParameterizedTest
void testGetViewNameLeavesExtensionIfSoConfigured(Function<String, MockHttpServletRequest> requestFactory) {
    MockHttpServletRequest request = requestFactory.apply(VIEW_NAME + EXTENSION);
    this.translator.setStripExtension(false);
    assertViewName(request, VIEW_NAME + EXTENSION);
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 64 with PathPatternsParameterizedTest

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

the class DefaultRequestToViewNameTranslatorTests method testGetViewNameLeavesTrailingSlashIfSoConfigured.

@PathPatternsParameterizedTest
void testGetViewNameLeavesTrailingSlashIfSoConfigured(Function<String, MockHttpServletRequest> requestFactory) {
    MockHttpServletRequest request = requestFactory.apply(VIEW_NAME + "/");
    this.translator.setStripTrailingSlash(false);
    assertViewName(request, VIEW_NAME + "/");
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 65 with PathPatternsParameterizedTest

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

the class DefaultRequestToViewNameTranslatorTests method testGetViewNameWithPrefix.

@PathPatternsParameterizedTest
void testGetViewNameWithPrefix(Function<String, MockHttpServletRequest> requestFactory) {
    final String prefix = "fiona_";
    MockHttpServletRequest request = requestFactory.apply(VIEW_NAME);
    this.translator.setPrefix(prefix);
    assertViewName(request, prefix + VIEW_NAME);
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) 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