类 MockMvcRequestBuilders
java.lang.Object
cn.taketoday.test.web.servlet.request.MockMvcRequestBuilders
Static factory methods for
RequestBuilders.
Integration with the Infra TestContext Framework
Methods in this class will reuse a
MockServletContext
that was created by the Infra TestContext Framework.
Eclipse Users
Consider adding this class as a Java editor favorite. To navigate to this setting, open the Preferences and type "favorites".
- 从以下版本开始:
- 4.0
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Greg Turnquist, Sebastien Deleuze, Sam Brannen, Kamill Sokol
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static RequestBuilderasyncDispatch(MvcResult mvcResult) Create aRequestBuilderfor an async dispatch from theMvcResultof the request that started async processing.Create aMockHttpServletRequestBuilderfor a DELETE request.Create aMockHttpServletRequestBuilderfor a DELETE request.Create aMockHttpServletRequestBuilderfor a GET request.Create aMockHttpServletRequestBuilderfor a GET request.Create aMockHttpServletRequestBuilderfor a HEAD request.Create aMockHttpServletRequestBuilderfor a HEAD request.Variant ofmultipart(String, Object...)that also accepts anHttpMethod.Create aMockMultipartHttpServletRequestBuilderfor a multipart request, using POST as the HTTP method.Variant ofmultipart(String, Object...)with aURI.Create aMockHttpServletRequestBuilderfor an OPTIONS request.Create aMockHttpServletRequestBuilderfor an OPTIONS request.Create aMockHttpServletRequestBuilderfor a PATCH request.Create aMockHttpServletRequestBuilderfor a PATCH request.Create aMockHttpServletRequestBuilderfor a POST request.Create aMockHttpServletRequestBuilderfor a POST request.Create aMockHttpServletRequestBuilderfor a PUT request.Create aMockHttpServletRequestBuilderfor a PUT request.Create aMockHttpServletRequestBuilderfor a request with the given HTTP method.Create aMockHttpServletRequestBuilderfor a request with the given HTTP method.Alternative factory method that allows for custom HTTP verbs (e.g.
-
构造器详细资料
-
MockMvcRequestBuilders
public MockMvcRequestBuilders()
-
-
方法详细资料
-
get
Create aMockHttpServletRequestBuilderfor a GET request.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVariables- zero or more URI variables
-
get
Create aMockHttpServletRequestBuilderfor a GET request.- 参数:
uri- the URL
-
post
Create aMockHttpServletRequestBuilderfor a POST request.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVariables- zero or more URI variables
-
post
Create aMockHttpServletRequestBuilderfor a POST request.- 参数:
uri- the URL
-
put
Create aMockHttpServletRequestBuilderfor a PUT request.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVariables- zero or more URI variables
-
put
Create aMockHttpServletRequestBuilderfor a PUT request.- 参数:
uri- the URL
-
patch
Create aMockHttpServletRequestBuilderfor a PATCH request.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVariables- zero or more URI variables
-
patch
Create aMockHttpServletRequestBuilderfor a PATCH request.- 参数:
uri- the URL
-
delete
Create aMockHttpServletRequestBuilderfor a DELETE request.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVariables- zero or more URI variables
-
delete
Create aMockHttpServletRequestBuilderfor a DELETE request.- 参数:
uri- the URL
-
options
Create aMockHttpServletRequestBuilderfor an OPTIONS request.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVariables- zero or more URI variables
-
options
Create aMockHttpServletRequestBuilderfor an OPTIONS request.- 参数:
uri- the URL
-
head
Create aMockHttpServletRequestBuilderfor a HEAD request.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVariables- zero or more URI variables
-
head
Create aMockHttpServletRequestBuilderfor a HEAD request.- 参数:
uri- the URL
-
request
public static MockHttpServletRequestBuilder request(cn.taketoday.http.HttpMethod method, String urlTemplate, Object... uriVariables) Create aMockHttpServletRequestBuilderfor 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 variables
-
request
public static MockHttpServletRequestBuilder request(cn.taketoday.http.HttpMethod httpMethod, URI uri) Create aMockHttpServletRequestBuilderfor a request with the given HTTP method.- 参数:
httpMethod- the HTTP method (GET, POST, etc)uri- the URL
-
request
Alternative factory method that allows for custom HTTP verbs (e.g. WebDAV).- 参数:
httpMethod- the HTTP methoduri- the URL
-
multipart
public static MockMultipartHttpServletRequestBuilder multipart(String urlTemplate, Object... uriVariables) Create aMockMultipartHttpServletRequestBuilderfor a multipart request, using POST as the HTTP method.- 参数:
urlTemplate- a URL template; the resulting URL will be encodeduriVariables- zero or more URI variables
-
multipart
public static MockMultipartHttpServletRequestBuilder multipart(cn.taketoday.http.HttpMethod httpMethod, String urlTemplate, Object... uriVariables) Variant ofmultipart(String, Object...)that also accepts anHttpMethod.- 参数:
httpMethod- the HTTP method to useurlTemplate- a URL template; the resulting URL will be encodeduriVariables- zero or more URI variables
-
multipart
Variant ofmultipart(String, Object...)with aURI.- 参数:
uri- the URL
-
multipart
public static MockMultipartHttpServletRequestBuilder multipart(cn.taketoday.http.HttpMethod httpMethod, URI uri) - 参数:
httpMethod- the HTTP method to useuri- the URL
-
asyncDispatch
Create aRequestBuilderfor an async dispatch from theMvcResultof 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
-