public abstract class MockMvcRequestBuilders
extends java.lang.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() |
Modifier and Type | Method and Description |
---|---|
static RequestBuilder |
asyncDispatch(MvcResult mvcResult)
Create a
RequestBuilder for an async dispatch from the
MvcResult of the request that started async processing. |
static MockHttpServletRequestBuilder |
delete(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create a
MockHttpServletRequestBuilder for a DELETE request. |
static MockHttpServletRequestBuilder |
delete(java.net.URI uri)
Create a
MockHttpServletRequestBuilder for a DELETE request. |
static MockMultipartHttpServletRequestBuilder |
fileUpload(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create a
MockMultipartHttpServletRequestBuilder for a multipart request. |
static MockMultipartHttpServletRequestBuilder |
fileUpload(java.net.URI uri)
Create a
MockMultipartHttpServletRequestBuilder for a multipart request. |
static MockHttpServletRequestBuilder |
get(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create a
MockHttpServletRequestBuilder for a GET request. |
static MockHttpServletRequestBuilder |
get(java.net.URI uri)
Create a
MockHttpServletRequestBuilder for a GET request. |
static MockHttpServletRequestBuilder |
head(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create a
MockHttpServletRequestBuilder for a HEAD request. |
static MockHttpServletRequestBuilder |
head(java.net.URI uri)
Create a
MockHttpServletRequestBuilder for a HEAD request. |
static MockHttpServletRequestBuilder |
options(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create a
MockHttpServletRequestBuilder for an OPTIONS request. |
static MockHttpServletRequestBuilder |
options(java.net.URI uri)
Create a
MockHttpServletRequestBuilder for an OPTIONS request. |
static MockHttpServletRequestBuilder |
patch(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create a
MockHttpServletRequestBuilder for a PATCH request. |
static MockHttpServletRequestBuilder |
patch(java.net.URI uri)
Create a
MockHttpServletRequestBuilder for a PATCH request. |
static MockHttpServletRequestBuilder |
post(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create a
MockHttpServletRequestBuilder for a POST request. |
static MockHttpServletRequestBuilder |
post(java.net.URI uri)
Create a
MockHttpServletRequestBuilder for a POST request. |
static MockHttpServletRequestBuilder |
put(java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create a
MockHttpServletRequestBuilder for a PUT request. |
static MockHttpServletRequestBuilder |
put(java.net.URI uri)
Create a
MockHttpServletRequestBuilder for a PUT request. |
static MockHttpServletRequestBuilder |
request(HttpMethod method,
java.lang.String urlTemplate,
java.lang.Object... uriVars)
Create a
MockHttpServletRequestBuilder for a request with the given HTTP method. |
static MockHttpServletRequestBuilder |
request(HttpMethod httpMethod,
java.net.URI uri)
Create a
MockHttpServletRequestBuilder for a request with the given HTTP method. |
static MockHttpServletRequestBuilder |
request(java.lang.String httpMethod,
java.net.URI uri)
Alternative factory method that allows for custom HTTP verbs (e.g.
|
public static MockHttpServletRequestBuilder get(java.lang.String urlTemplate, java.lang.Object... uriVars)
MockHttpServletRequestBuilder
for a GET request.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockHttpServletRequestBuilder get(java.net.URI uri)
MockHttpServletRequestBuilder
for a GET request.uri
- the URLpublic static MockHttpServletRequestBuilder post(java.lang.String urlTemplate, java.lang.Object... uriVars)
MockHttpServletRequestBuilder
for a POST request.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockHttpServletRequestBuilder post(java.net.URI uri)
MockHttpServletRequestBuilder
for a POST request.uri
- the URLpublic static MockHttpServletRequestBuilder put(java.lang.String urlTemplate, java.lang.Object... uriVars)
MockHttpServletRequestBuilder
for a PUT request.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockHttpServletRequestBuilder put(java.net.URI uri)
MockHttpServletRequestBuilder
for a PUT request.uri
- the URLpublic static MockHttpServletRequestBuilder patch(java.lang.String urlTemplate, java.lang.Object... uriVars)
MockHttpServletRequestBuilder
for a PATCH request.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockHttpServletRequestBuilder patch(java.net.URI uri)
MockHttpServletRequestBuilder
for a PATCH request.uri
- the URLpublic static MockHttpServletRequestBuilder delete(java.lang.String urlTemplate, java.lang.Object... uriVars)
MockHttpServletRequestBuilder
for a DELETE request.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockHttpServletRequestBuilder delete(java.net.URI uri)
MockHttpServletRequestBuilder
for a DELETE request.uri
- the URLpublic static MockHttpServletRequestBuilder options(java.lang.String urlTemplate, java.lang.Object... uriVars)
MockHttpServletRequestBuilder
for an OPTIONS request.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockHttpServletRequestBuilder options(java.net.URI uri)
MockHttpServletRequestBuilder
for an OPTIONS request.uri
- the URLpublic static MockHttpServletRequestBuilder head(java.lang.String urlTemplate, java.lang.Object... uriVars)
MockHttpServletRequestBuilder
for a HEAD request.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockHttpServletRequestBuilder head(java.net.URI uri)
MockHttpServletRequestBuilder
for a HEAD request.uri
- the URLpublic static MockHttpServletRequestBuilder request(HttpMethod method, java.lang.String urlTemplate, java.lang.Object... uriVars)
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 encodeduriVars
- zero or more URI variablespublic static MockHttpServletRequestBuilder request(HttpMethod httpMethod, java.net.URI uri)
MockHttpServletRequestBuilder
for a request with the given HTTP method.httpMethod
- the HTTP method (GET, POST, etc)uri
- the URLpublic static MockHttpServletRequestBuilder request(java.lang.String httpMethod, java.net.URI uri)
httpMethod
- the HTTP methoduri
- the URLpublic static MockMultipartHttpServletRequestBuilder fileUpload(java.lang.String urlTemplate, java.lang.Object... uriVars)
MockMultipartHttpServletRequestBuilder
for a multipart request.urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockMultipartHttpServletRequestBuilder fileUpload(java.net.URI 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