use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class UriTemplateServletAnnotationControllerHandlerMethodTests method literalMappingWithPathParams.
// gh-25864
@PathPatternsParameterizedTest
void literalMappingWithPathParams(boolean usePathPatterns) throws Exception {
initDispatcherServlet(MultipleUriTemplateController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/data");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsString()).isEqualTo("test");
if (!usePathPatterns) {
request = new MockHttpServletRequest("GET", "/data;foo=bar");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(404);
}
request = new MockHttpServletRequest("GET", "/data;jsessionid=123");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsString()).isEqualTo("test");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class UriTemplateServletAnnotationControllerHandlerMethodTests method simple.
@PathPatternsParameterizedTest
void simple(boolean usePathPatterns) throws Exception {
initDispatcherServlet(SimpleUriTemplateController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/42");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("test-42-7");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method requestParamMap.
@PathPatternsParameterizedTest
void requestParamMap(boolean usePathPatterns) throws Exception {
initDispatcherServlet(RequestParamMapController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/map");
request.addParameter("key1", "value1");
request.addParameter("key2", "value21", "value22");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("key1=value1,key2=value21");
request.setRequestURI("/multiValueMap");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("key1=[value1],key2=[value21,value22]");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method emptyValueMapping.
@PathPatternsParameterizedTest
void emptyValueMapping(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ControllerWithEmptyValueMapping.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
request.setContextPath("/foo");
request.setServletPath("");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("test");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method httpPatch.
@PathPatternsParameterizedTest
void httpPatch(boolean usePathPatterns) throws Exception {
initDispatcherServlet(RequestResponseBodyController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("PATCH", "/something");
String requestBody = "Hello world!";
request.setContent(requestBody.getBytes(StandardCharsets.UTF_8));
request.addHeader("Content-Type", "text/plain; charset=utf-8");
request.addHeader("Accept", "text/*, */*");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsString()).isEqualTo(requestBody);
}
Aggregations