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");
}
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);
}
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");
}
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!");
}
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");
}
Aggregations