public abstract class MockMvcRequestBuilders extends Object
RequestBuilders
.
Methods in this class will reuse a
MockServletContext
that was created by the Spring TestContext Framework.
Consider adding this class as a Java editor favorite. To navigate to this setting, open the Preferences and type "favorites".
Constructor and Description |
---|
MockMvcRequestBuilders() |
public static MockHttpServletRequestBuilder get(String urlTemplate, Object... uriVariables)
MockHttpServletRequestBuilder
for a GET request.urlTemplate
- a URL template; the resulting URL will be encodeduriVariables
- zero or more URI variablespublic static MockHttpServletRequestBuilder get(URI uri)
MockHttpServletRequestBuilder
for a GET request.uri
- the URLpublic static MockHttpServletRequestBuilder post(String urlTemplate, Object... uriVariables)
MockHttpServletRequestBuilder
for a POST request.urlTemplate
- a URL template; the resulting URL will be encodeduriVariables
- zero or more URI variablespublic static MockHttpServletRequestBuilder post(URI uri)
MockHttpServletRequestBuilder
for a POST request.uri
- the URLpublic static MockHttpServletRequestBuilder put(String urlTemplate, Object... uriVariables)
MockHttpServletRequestBuilder
for a PUT request.urlTemplate
- a URL template; the resulting URL will be encodeduriVariables
- zero or more URI variablespublic static MockHttpServletRequestBuilder put(URI uri)
MockHttpServletRequestBuilder
for a PUT request.uri
- the URLpublic static MockHttpServletRequestBuilder patch(String urlTemplate, Object... uriVariables)
MockHttpServletRequestBuilder
for a PATCH request.urlTemplate
- a URL template; the resulting URL will be encodeduriVariables
- zero or more URI variablespublic static MockHttpServletRequestBuilder patch(URI uri)
MockHttpServletRequestBuilder
for a PATCH request.uri
- the URLpublic static MockHttpServletRequestBuilder delete(String urlTemplate, Object... uriVariables)
MockHttpServletRequestBuilder
for a DELETE request.urlTemplate
- a URL template; the resulting URL will be encodeduriVariables
- zero or more URI variablespublic static MockHttpServletRequestBuilder delete(URI uri)
MockHttpServletRequestBuilder
for a DELETE request.uri
- the URLpublic static MockHttpServletRequestBuilder options(String urlTemplate, Object... uriVariables)
MockHttpServletRequestBuilder
for an OPTIONS request.urlTemplate
- a URL template; the resulting URL will be encodeduriVariables
- zero or more URI variablespublic static MockHttpServletRequestBuilder options(URI uri)
MockHttpServletRequestBuilder
for an OPTIONS request.uri
- the URLpublic static MockHttpServletRequestBuilder head(String urlTemplate, Object... uriVariables)
MockHttpServletRequestBuilder
for a HEAD request.urlTemplate
- a URL template; the resulting URL will be encodeduriVariables
- zero or more URI variablespublic static MockHttpServletRequestBuilder head(URI uri)
MockHttpServletRequestBuilder
for a HEAD request.uri
- the URLpublic static MockHttpServletRequestBuilder request(HttpMethod method, String urlTemplate, Object... uriVariables)
MockHttpServletRequestBuilder
for a request with the given HTTP method.method
- the HTTP method (GET, POST, etc)urlTemplate
- a URL template; the resulting URL will be encodeduriVariables
- zero or more URI variablespublic static MockHttpServletRequestBuilder request(HttpMethod httpMethod, URI uri)
MockHttpServletRequestBuilder
for a request with the given HTTP method.httpMethod
- the HTTP method (GET, POST, etc)uri
- the URLpublic static MockHttpServletRequestBuilder request(String httpMethod, URI uri)
httpMethod
- the HTTP methoduri
- the URLpublic static MockMultipartHttpServletRequestBuilder multipart(String urlTemplate, Object... uriVariables)
MockMultipartHttpServletRequestBuilder
for a multipart request,
using POST as the HTTP method.urlTemplate
- a URL template; the resulting URL will be encodeduriVariables
- zero or more URI variablespublic static MockMultipartHttpServletRequestBuilder multipart(HttpMethod httpMethod, String urlTemplate, Object... uriVariables)
multipart(String, Object...)
that also accepts an
HttpMethod
.httpMethod
- the HTTP method to useurlTemplate
- a URL template; the resulting URL will be encodeduriVariables
- zero or more URI variablespublic static MockMultipartHttpServletRequestBuilder multipart(URI uri)
multipart(String, Object...)
with a URI
.uri
- the URLpublic static MockMultipartHttpServletRequestBuilder multipart(HttpMethod httpMethod, URI uri)
httpMethod
- the HTTP method to useuri
- the URL@Deprecated public static MockMultipartHttpServletRequestBuilder fileUpload(String urlTemplate, Object... uriVariables)
multipart(String, Object...)
MockMultipartHttpServletRequestBuilder
for a multipart request.urlTemplate
- a URL template; the resulting URL will be encodeduriVariables
- zero or more URI variables@Deprecated public static MockMultipartHttpServletRequestBuilder fileUpload(URI uri)
multipart(URI)
MockMultipartHttpServletRequestBuilder
for a multipart request.uri
- the URLpublic static RequestBuilder asyncDispatch(MvcResult mvcResult)
RequestBuilder
for an async dispatch from the
MvcResult
of the request that started async processing.
Usage involves performing a request that starts async processing first:
MvcResult mvcResult = this.mockMvc.perform(get("/1")) .andExpect(request().asyncStarted()) .andReturn();
And then performing the async dispatch re-using the MvcResult
:
this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
mvcResult
- the result from the request that started async processing