org.springframework.test.web.servlet.request

## Class MockMvcRequestBuilders

- java.lang.Object
- - org.springframework.test.web.servlet.request.MockMvcRequestBuilders

    public abstract class MockMvcRequestBuilders
    extends Object

Static factory methods for `RequestBuilder`s.

Eclipse users: consider adding this class as a Java editor favorite. To navigate, open the Preferences and type "favorites".

Since:
  3.2
Author:
  Arjen Poutsma, Rossen Stoyanchev

### Method Summary

Methods
`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(String urlTemplate, Object... urlVariables)` Create a `MockHttpServletRequestBuilder` for a DELETE request.
`static MockMultipartHttpServletRequestBuilder` `fileUpload(String urlTemplate, Object... urlVariables)` Create a `MockHttpServletRequestBuilder` for a multipart request.
`static MockHttpServletRequestBuilder` `get(String urlTemplate, Object... urlVariables)` Create a `MockHttpServletRequestBuilder` for a GET request.
`static MockHttpServletRequestBuilder` `options(String urlTemplate, Object... urlVariables)` Create a `MockHttpServletRequestBuilder` for an OPTIONS request.
`static MockHttpServletRequestBuilder` `post(String urlTemplate, Object... urlVariables)` Create a `MockHttpServletRequestBuilder` for a POST request.
`static MockHttpServletRequestBuilder` `put(String urlTemplate, Object... urlVariables)` Create a `MockHttpServletRequestBuilder` for a PUT request.
`static MockHttpServletRequestBuilder` `request(HttpMethod httpMethod, String urlTemplate, Object... urlVariables)` Create a `MockHttpServletRequestBuilder` for a request with the given HTTP method.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### get

    public static MockHttpServletRequestBuilder get(String urlTemplate,
                                    Object... urlVariables)

Create a `MockHttpServletRequestBuilder` for a GET request.

Parameters:
  `urlTemplate` - a URL template; the resulting URL will be encoded
  `urlVariables` - zero or more URL variables

#### post

    public static MockHttpServletRequestBuilder post(String urlTemplate,
                                     Object... urlVariables)

Create a `MockHttpServletRequestBuilder` for a POST request.

Parameters:
  `urlTemplate` - a URL template; the resulting URL will be encoded
  `urlVariables` - zero or more URL variables

#### put

    public static MockHttpServletRequestBuilder put(String urlTemplate,
                                    Object... urlVariables)

Create a `MockHttpServletRequestBuilder` for a PUT request.

Parameters:
  `urlTemplate` - a URL template; the resulting URL will be encoded
  `urlVariables` - zero or more URL variables

#### delete

    public static MockHttpServletRequestBuilder delete(String urlTemplate,
                                       Object... urlVariables)

Create a `MockHttpServletRequestBuilder` for a DELETE request.

Parameters:
  `urlTemplate` - a URL template; the resulting URL will be encoded
  `urlVariables` - zero or more URL variables

#### options

    public static MockHttpServletRequestBuilder options(String urlTemplate,
                                        Object... urlVariables)

Create a `MockHttpServletRequestBuilder` for an OPTIONS request.

Parameters:
  `urlTemplate` - a URL template; the resulting URL will be encoded
  `urlVariables` - zero or more URL variables

#### request

    public static MockHttpServletRequestBuilder request(HttpMethod httpMethod,
                                        String urlTemplate,
                                        Object... urlVariables)

Create a `MockHttpServletRequestBuilder` for a request with the given HTTP method.

Parameters:
  `httpMethod` - the HTTP method
  `urlTemplate` - a URL template; the resulting URL will be encoded
  `urlVariables` - zero or more URL variables

#### fileUpload

    public static MockMultipartHttpServletRequestBuilder fileUpload(String urlTemplate,
                                                    Object... urlVariables)

Create a `MockHttpServletRequestBuilder` for a multipart request.

Parameters:
  `urlTemplate` - a URL template; the resulting URL will be encoded
  `urlVariables` - zero or more URL variables

#### asyncDispatch

    public static RequestBuilder asyncDispatch(MvcResult mvcResult)

Create a `RequestBuilder` for an async dispatch from the `MvcResult` of the request that started async processing.

Usage involves performing one request first that starts async processing:

     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}"));

Parameters:
  `mvcResult` - the result from the request that started async processing