Support custom HTTP verbs in Spring MVC Test

Prior to this commit, Spring MVC Test only supported HTTP methods GET,
POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE and multipart file
upload. This change adds generic methods to MockMvcRequestBuilders in
order to allow testing of arbitrary HTTP methods in a Spring MVC
application.

Issue: SPR-13719
This commit is contained in:
Kamill Sokol
2015-12-28 13:32:47 +01:00
committed by Rossen Stoyanchev
parent 9e16cbda4c
commit 3554348919
3 changed files with 69 additions and 15 deletions

View File

@@ -471,7 +471,9 @@ public class MockHttpServletRequestBuilderTests {
assertEquals(user, request.getUserPrincipal());
}
// SPR-12945
/**
* See SPR-12945
*/
@Test
public void mergeInvokesDefaultRequestPostProcessorFirst() {
final String ATTR = "ATTR";
@@ -492,6 +494,24 @@ public class MockHttpServletRequestBuilderTests {
assertEquals(EXEPCTED, request.getAttribute(ATTR));
}
/**
* See SPR-13719
*/
@Test
public void arbitraryMethod() {
/*
* http method is case-sensitive
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.1
*/
String httpMethod = "REPort";
this.builder = new MockHttpServletRequestBuilder(httpMethod, "/foo/{bar}", 42);
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
assertEquals(httpMethod, request.getMethod());
assertEquals("/foo/42", request.getPathInfo());
}
private final class User implements Principal {