use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method getHandlerTestInvalidContentType.
@PathPatternsParameterizedTest
void getHandlerTestInvalidContentType(TestRequestMappingInfoHandlerMapping mapping) {
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/person/1");
request.setContentType("bogus");
assertThatExceptionOfType(HttpMediaTypeNotSupportedException.class).isThrownBy(() -> mapping.getHandler(request)).withMessage("Invalid mime type \"bogus\": does not contain '/'");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method getHandlerDirectMatch.
@PathPatternsParameterizedTest
void getHandlerDirectMatch(TestRequestMappingInfoHandlerMapping mapping) throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
HandlerMethod handlerMethod = getHandler(mapping, request);
assertThat(handlerMethod.getMethod()).isEqualTo(this.fooMethod.getMethod());
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method handleMatchBestMatchingPatternAttributeNoPatternsDefined.
// gh-22543
@PathPatternsParameterizedTest
void handleMatchBestMatchingPatternAttributeNoPatternsDefined(TestRequestMappingInfoHandlerMapping mapping) {
String path = "";
MockHttpServletRequest request = new MockHttpServletRequest("GET", path);
mapping.handleMatch(RequestMappingInfo.paths().build(), path, request);
assertThat(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)).isEqualTo(path);
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method getHandlerRequestMethodNotAllowed.
@PathPatternsParameterizedTest
void getHandlerRequestMethodNotAllowed(TestRequestMappingInfoHandlerMapping mapping) {
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/bar");
assertThatExceptionOfType(HttpRequestMethodNotSupportedException.class).isThrownBy(() -> mapping.getHandler(request)).satisfies(ex -> assertThat(ex.getSupportedMethods()).containsExactly("GET", "HEAD"));
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class UriTemplateServletAnnotationControllerHandlerMethodTests method pathVarsInModel.
@PathPatternsParameterizedTest
void pathVarsInModel(boolean usePathPatterns) throws Exception {
final Map<String, Object> pathVars = new HashMap<>();
pathVars.put("hotel", "42");
pathVars.put("booking", 21);
pathVars.put("other", "other");
WebApplicationContext wac = initDispatcherServlet(ViewRenderingController.class, usePathPatterns, context -> {
RootBeanDefinition beanDef = new RootBeanDefinition(ModelValidatingViewResolver.class);
beanDef.getConstructorArgumentValues().addGenericArgumentValue(pathVars);
context.registerBeanDefinition("viewResolver", beanDef);
});
HttpServletRequest request = new MockHttpServletRequest("GET", "/hotels/42;q=1,2/bookings/21-other;q=3;r=R");
getServlet().service(request, new MockHttpServletResponse());
ModelValidatingViewResolver resolver = wac.getBean(ModelValidatingViewResolver.class);
assertThat(resolver.validatedAttrCount).isEqualTo(3);
}
Aggregations