Class MockMvcRequestSpecificationImpl

java.lang.Object
io.restassured.module.mockmvc.internal.MockMvcRequestSpecificationImpl
All Implemented Interfaces:
MockMvcAuthenticationSpecification, MockMvcRequestSender, MockMvcRequestSpecification, io.restassured.specification.RequestSenderOptions<MockMvcResponse>

public class MockMvcRequestSpecificationImpl extends Object implements MockMvcRequestSpecification, MockMvcAuthenticationSpecification
  • Constructor Details

  • Method Details

    • mockMvc

      public MockMvcRequestSpecification mockMvc(org.springframework.test.web.servlet.MockMvc mockMvc)
      Description copied from interface: MockMvcRequestSpecification
      Provide a MockMvc instance to that REST Assured will use when making this request.
      Specified by:
      mockMvc in interface MockMvcRequestSpecification
      Parameters:
      mockMvc - The mock mvc instance to use.
      Returns:
      The request specification
    • standaloneSetup

      public MockMvcRequestSpecification standaloneSetup(Object... controllerOrMockMvcConfigurer)
      Description copied from interface: MockMvcRequestSpecification
      Build a MockMvc by registering one or more @Controller's instances and configuring Spring MVC infrastructure programmatically. This allows full control over the instantiation and initialization of controllerOrMockMvcConfigurer, and their dependencies, similar to plain unit tests while also making it possible to test one controller at a time.

      When this option is used, the minimum infrastructure required by the DispatcherServlet to serve requests with annotated controllerOrMockMvcConfigurer is automatically created, and can be customized, resulting in configuration that is equivalent to what the MVC Java configuration provides except using builder style methods.

      If the Spring MVC configuration of an application is relatively straight-forward, for example when using the MVC namespace or the MVC Java config, then using this builder might be a good option for testing a majority of controllers. A much smaller number of tests can be used to focus on testing and verifying the actual Spring MVC configuration.

      Specified by:
      standaloneSetup in interface MockMvcRequestSpecification
      Parameters:
      controllerOrMockMvcConfigurer - one or more @Controller's to test or a combination of controllers and MockMvcConfigurer
    • standaloneSetup

      public MockMvcRequestSpecification standaloneSetup(org.springframework.test.web.servlet.MockMvcBuilder builder)
      Description copied from interface: MockMvcRequestSpecification
      Build a MockMvc by using a provided AbstractMockMvcBuilder for configuring Spring MVC infrastructure programmatically. This allows full control over the instantiation and initialization of controllers, and their dependencies, similar to plain unit tests while also making it possible to test one controller at a time.

      If the Spring MVC configuration of an application is relatively straight-forward, for example when using the MVC namespace or the MVC Java config, then using this builder might be a good option for testing a majority of controllers. A much smaller number of tests can be used to focus on testing and verifying the actual Spring MVC configuration.

      Specified by:
      standaloneSetup in interface MockMvcRequestSpecification
      Parameters:
      builder - AbstractMockMvcBuilder to build the MVC mock
    • webAppContextSetup

      public MockMvcRequestSpecification webAppContextSetup(org.springframework.web.context.WebApplicationContext context, org.springframework.test.web.servlet.setup.MockMvcConfigurer... mockMvcConfigurers)
      Description copied from interface: MockMvcRequestSpecification
      Build a MockMvc using the given, fully initialized, i.e. refreshed, WebApplicationContext and assign it to REST Assured. The DispatcherServlet will use the context to discover Spring MVC infrastructure and application controllers in it. The context must have been configured with a ServletContext.
      Specified by:
      webAppContextSetup in interface MockMvcRequestSpecification
      Parameters:
      context - The web application context to use
      mockMvcConfigurers - MockMvcConfigurer's to be applied when creating a MockMvc instance of this WebApplicationContext (optional)
    • interceptor

      Description copied from interface: MockMvcRequestSpecification
      Intercept the MockHttpServletRequestBuilder created by REST Assured before it's used to perform the request.
      Specified by:
      interceptor in interface MockMvcRequestSpecification
      Parameters:
      interceptor - The interceptor
      Returns:
      The request specification
    • and

      Description copied from interface: MockMvcRequestSpecification
      Syntactic sugar
      Specified by:
      and in interface MockMvcRequestSpecification
      Returns:
      The same MockMvcRequestSpecification instance.
    • postProcessors

      public MockMvcRequestSpecification postProcessors(org.springframework.test.web.servlet.request.RequestPostProcessor postProcessor, org.springframework.test.web.servlet.request.RequestPostProcessor... additionalPostProcessors)
      Description copied from interface: MockMvcRequestSpecification
      An extension point for further initialization of MockHttpServletRequest in ways not built directly into the MockHttpServletRequestBuilder. Implementation of this interface can have builder-style methods themselves and be made accessible through static factory methods.

      Note that it's recommended to use MockMvcAuthenticationSpecification.with(RequestPostProcessor, RequestPostProcessor...) instead of this method when setting authentication/authorization based RequestPostProcessors. For example:

       given().auth().with(httpBasic("username", "password")). ..
       

      Specified by:
      postProcessors in interface MockMvcRequestSpecification
      Parameters:
      postProcessor - a post-processor to add
      additionalPostProcessors - Additional post-processors to add
      See Also:
      • AbstractMockHttpServletRequestBuilder.with(RequestPostProcessor)
    • auth

      Description copied from interface: MockMvcRequestSpecification
      Specify authentication details that'll be used in the request.
      Specified by:
      auth in interface MockMvcRequestSpecification
      Returns:
      A MockMvcAuthenticationSpecification.
    • contentType

      public MockMvcRequestSpecification contentType(io.restassured.http.ContentType contentType)
      Description copied from interface: MockMvcRequestSpecification
      Specify the content type of the request.
      Specified by:
      contentType in interface MockMvcRequestSpecification
      Parameters:
      contentType - The content type of the request
      Returns:
      The request specification
      See Also:
      • ContentType
    • contentType

      public MockMvcRequestSpecification contentType(org.springframework.http.MediaType mediaType)
      Description copied from interface: MockMvcRequestSpecification
      Specify the content type of the request.
      Specified by:
      contentType in interface MockMvcRequestSpecification
      Parameters:
      mediaType - The content type of the request
      Returns:
      The request specification
      See Also:
      • ContentType
      • MediaType
    • contentType

      public MockMvcRequestSpecification contentType(String contentType)
      Description copied from interface: MockMvcRequestSpecification
      Specify the content type of the request.
      Specified by:
      contentType in interface MockMvcRequestSpecification
      Parameters:
      contentType - The content type of the request
      Returns:
      The request specification
      See Also:
      • ContentType
    • accept

      public MockMvcRequestSpecification accept(io.restassured.http.ContentType contentType)
      Description copied from interface: MockMvcRequestSpecification
      Specify the accept header of the request. This just a shortcut for:
       header("Accept", contentType);
       
      Specified by:
      accept in interface MockMvcRequestSpecification
      Parameters:
      contentType - The content type whose accept header ContentType.getAcceptHeader() will be used as Accept header in the request.
      Returns:
      The request specification
      See Also:
    • accept

      public MockMvcRequestSpecification accept(org.springframework.http.MediaType... mediaTypes)
      Description copied from interface: MockMvcRequestSpecification
      Specify the accept header of the request. This just a shortcut for:
       header("Accept", contentType);
       
      Specified by:
      accept in interface MockMvcRequestSpecification
      Parameters:
      mediaTypes - The media type(s) that will be used as Accept header in the request.
      Returns:
      The request specification
      See Also:
    • accept

      public MockMvcRequestSpecification accept(String mediaTypes)
      Description copied from interface: MockMvcRequestSpecification
      Specify the accept header of the request. This just a shortcut for:
       header("Accept", contentType);
       
      Specified by:
      accept in interface MockMvcRequestSpecification
      Parameters:
      mediaTypes - The media type(s) that will be used as Accept header in the request.
      Returns:
      The request specification
      See Also:
    • headers

      public MockMvcRequestSpecification headers(String firstHeaderName, Object firstHeaderValue, Object... headerNameValuePairs)
      Description copied from interface: MockMvcRequestSpecification
      Specify the headers that'll be sent with the request. This is done by specifying the headers in name-value pairs, e.g:
       given().headers("headerName1", "headerValue1", "headerName2", "headerValue2").then().expect().body(equalTo("something")).when().get("/headers");
       

      This will send a GET request to "/headers" with two headers:

      1. headerName1=headerValue1
      2. headerName2=headerValue2
      and expect that the response body is equal to "something".
      Specified by:
      headers in interface MockMvcRequestSpecification
      Parameters:
      firstHeaderName - The name of the first header
      firstHeaderValue - The value of the first header
      headerNameValuePairs - Additional headers in name-value pairs.
      Returns:
      The request specification
    • headers

      public MockMvcRequestSpecification headers(Map<String,?> headers)
      Description copied from interface: MockMvcRequestSpecification
      Specify the headers that'll be sent with the request as Map e.g:
       Map<String, String> headers = new HashMap<String, String>();
       parameters.put("headerName1", "headerValue1");
       parameters.put("headerName2", "headerValue2");
       given().headers(headers).then().expect().body(equalTo("something")).when().get("/headers");
       

      This will send a GET request to "/headers" with two headers:

      1. headerName1=headerValue1
      2. headerName2=headerValue2
      and expect that the response body is equal to "something".
      Specified by:
      headers in interface MockMvcRequestSpecification
      Parameters:
      headers - The Map containing the header names and their values to send with the request.
      Returns:
      The request specification
    • headers

      public MockMvcRequestSpecification headers(io.restassured.http.Headers headers)
      Description copied from interface: MockMvcRequestSpecification
      Specify the headers that'll be sent with the request as Headers, e.g:
       Header first = new Header("headerName1", "headerValue1");
       Header second = new Header("headerName2", "headerValue2");
       Headers headers = new Header(first, second);
       given().headers(headers).then().expect().body(equalTo("something")).when().get("/headers");
       

      This will send a GET request to "/headers" with two headers:

      1. headerName1=headerValue1
      2. headerName2=headerValue2
      and expect that the response body is equal to "something".
      Specified by:
      headers in interface MockMvcRequestSpecification
      Parameters:
      headers - The headers to use in the request
      Returns:
      The request specification
    • header

      public MockMvcRequestSpecification header(String headerName, Object headerValue, Object... additionalHeaderValues)
      Description copied from interface: MockMvcRequestSpecification
      Specify a header that'll be sent with the request e.g:

       given().header("username", "John").and().expect().body(equalTo("something")).when().get("/header");
       
      This will set the header username=John in the GET request to "/header".

      You can also specify several headers like this:

       given().header("username", "John").and().header("zipCode", "12345").and().expect().body(equalTo("something")).when().get("/header");
       

      If you specify additionalHeaderValues then the Header will be a multi-value header. This means that you'll create several headers with the same name but with different values.

      Specified by:
      header in interface MockMvcRequestSpecification
      Parameters:
      headerName - The header name
      headerValue - The header value
      additionalHeaderValues - Additional header values. This will actually create two headers with the same name but with different values.
      Returns:
      The request specification
      See Also:
    • header

      public MockMvcRequestSpecification header(io.restassured.http.Header header)
      Description copied from interface: MockMvcRequestSpecification
      Specify a Header to send with the request.

       Header someHeader = new Header("some_name", "some_value");
       given().header(someHeader).and().expect().body(equalTo("x")).when().get("/header");
       
      This will set the header some_name=some_value in the GET request to "/header".

      Specified by:
      header in interface MockMvcRequestSpecification
      Parameters:
      header - The header to add to the request
      Returns:
      The request specification
      See Also:
    • log

      Description copied from interface: MockMvcRequestSpecification
      Returns the MockMvcRequestLogSpecification that allows you to log different parts of the MockMvcRequestSpecification. This is mainly useful for debug purposes when writing your tests.
      Specified by:
      log in interface MockMvcRequestSpecification
      Returns:
      the request log specification
    • params

      public MockMvcRequestSpecification params(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
      Description copied from interface: MockMvcRequestSpecification
      Specify the parameters that'll be sent with the request. This is done by specifying the parameters in name-value pairs, e.g:
       given().params("username", "John", "token", "1234").when().get("/parameters").then().assertThat().body(equalTo("username, token"));
       

      This will send a GET request to "/parameters" with two parameters:

      1. username=John
      2. token=1234
      and expect that the response body is equal to "username, token".
      Specified by:
      params in interface MockMvcRequestSpecification
      Parameters:
      firstParameterName - The name of the first parameter
      firstParameterValue - The value of the first parameter
      parameterNameValuePairs - Additional parameters in name-value pairs.
      Returns:
      The request specification
    • params

      public MockMvcRequestSpecification params(Map<String,?> parametersMap)
      Description copied from interface: MockMvcRequestSpecification
      Specify the parameters that'll be sent with the request as Map e.g:
       Map<String, String> parameters = new HashMap<String, String>();
       parameters.put("username", "John");
       parameters.put("token", "1234");
       given().params(parameters).when().get("/cookie").then().assertThat().body(equalTo("username, token")).;
       

      This will send a GET request to "/cookie" with two parameters:

      1. username=John
      2. token=1234
      and expect that the response body is equal to "username, token".
      Specified by:
      params in interface MockMvcRequestSpecification
      Parameters:
      parametersMap - The Map containing the parameter names and their values to send with the request.
      Returns:
      The request specification
    • param

      public MockMvcRequestSpecification param(String parameterName, Object... parameterValues)
      Description copied from interface: MockMvcRequestSpecification
      Specify a parameter that'll be sent with the request e.g:

       given().parameter("username", "John").and().expect().body(equalTo("username")).when().get("/cookie");
       
      This will set the parameter username=John in the GET request to "/cookie".

      You can also specify several parameters like this:

       given().param("username", "John").and().param("password", "1234").when().get("/cookie").then().assertThat().body(equalTo("username")).;
       

      Specified by:
      param in interface MockMvcRequestSpecification
      Parameters:
      parameterName - The parameter name
      parameterValues - Zero to many parameter values for this parameter name
      Returns:
      The request specification
      See Also:
    • param

      public MockMvcRequestSpecification param(String parameterName, Collection<?> parameterValues)
      Description copied from interface: MockMvcRequestSpecification
      Specify a multi-value parameter that'll be sent with the request e.g:

       given().param("cars", asList("Volvo", "Saab"))..;
       
      This will set the parameter cars=Volvo and cars=Saab.

      Specified by:
      param in interface MockMvcRequestSpecification
      Parameters:
      parameterName - The parameter name
      parameterValues - The parameter values
      Returns:
      The request specification
    • queryParams

      public MockMvcRequestSpecification queryParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
      Description copied from interface: MockMvcRequestSpecification
      Specify the query parameters that'll be sent with the request. Note that this method is the same as MockMvcRequestSpecification.params(String, Object, Object...) for all http methods except for POST where MockMvcRequestSpecification.params(String, Object, Object...) sets the form parameters and this method sets the query parameters.
      Specified by:
      queryParams in interface MockMvcRequestSpecification
      Parameters:
      firstParameterName - The name of the first parameter
      firstParameterValue - The value of the first parameter
      parameterNameValuePairs - The value of the first parameter followed by additional parameters in name-value pairs.
      Returns:
      The request specification
    • queryParams

      public MockMvcRequestSpecification queryParams(Map<String,?> parametersMap)
      Description copied from interface: MockMvcRequestSpecification
      Specify the query parameters that'll be sent with the request. Note that this method is the same as MockMvcRequestSpecification.params(Map) for all http methods except for POST where MockMvcRequestSpecification.params(Map) sets the form parameters and this method sets the query parameters.
      Specified by:
      queryParams in interface MockMvcRequestSpecification
      Parameters:
      parametersMap - The Map containing the parameter names and their values to send with the request.
      Returns:
      The request specification
    • queryParam

      public MockMvcRequestSpecification queryParam(String parameterName, Object... parameterValues)
      Description copied from interface: MockMvcRequestSpecification
      Specify a query parameter that'll be sent with the request. Note that this method is the same as MockMvcRequestSpecification.param(String, Object...) for all http methods except for POST where MockMvcRequestSpecification.param(String, Object...) adds a form parameter and this method sets a query parameter.
      Specified by:
      queryParam in interface MockMvcRequestSpecification
      Parameters:
      parameterName - The parameter name
      parameterValues - Zero to many parameter values, i.e. you can specify multiple values for the same parameter
      Returns:
      The request specification
      See Also:
    • queryParam

      public MockMvcRequestSpecification queryParam(String parameterName, Collection<?> parameterValues)
      Description copied from interface: MockMvcRequestSpecification
      Specify a multi-value query parameter that'll be sent with the request e.g:

       given().queryParam("cars", asList("Volvo", "Saab"))..;
       
      This will set the parameter cars=Volvo and cars=Saab.

      Note that this method is the same as MockMvcRequestSpecification.param(String, java.util.Collection) for all http methods except for POST where MockMvcRequestSpecification.param(String, java.util.Collection) adds a form parameter and this method sets a query parameter.

      Specified by:
      queryParam in interface MockMvcRequestSpecification
      Parameters:
      parameterName - The parameter name
      parameterValues - The parameter values
      Returns:
      The request specification
    • pathParams

      public MockMvcRequestSpecification pathParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
      Description copied from interface: MockMvcRequestSpecification
      Specify the path parameters that'll be sent with the request.
      Specified by:
      pathParams in interface MockMvcRequestSpecification
      Parameters:
      firstParameterName - The name of the first parameter
      firstParameterValue - The value of the first parameter
      parameterNameValuePairs - The value of the first parameter followed by additional parameters in name-value pairs.
      Returns:
      The request specification
    • pathParams

      public MockMvcRequestSpecification pathParams(Map<String,Object> parametersMap)
      Description copied from interface: MockMvcRequestSpecification
      Specify the path parameters that'll be sent with the request.
      Specified by:
      pathParams in interface MockMvcRequestSpecification
      Parameters:
      parametersMap - The Map containing the parameter names and their values to send with the request.
      Returns:
      The request specification
    • pathParam

      public MockMvcRequestSpecification pathParam(String parameterName, Object parameterValue)
      Description copied from interface: MockMvcRequestSpecification
      Specify a path parameter. Path parameters are used to improve readability of the request path. E.g. instead of writing:
       when().
              get("/item/"+myItem.getItemNumber()+"/buy/"+2).
       then().
              statusCode(200);
       
      you can write:
       given().
               pathParam("itemNumber", myItem.getItemNumber()).
               pathParam("amount", 2).
       when().
              get("/item/{itemNumber}/buy/{amount}").
       then().
                statusCode(200);
       

      which improves readability and allows the path to be reusable in many tests. Another alternative is to use:

       when().get("/item/{itemNumber}/buy/{amount}", myItem.getItemNumber(), 2).then().statusCode(200).;
       
      Specified by:
      pathParam in interface MockMvcRequestSpecification
      Parameters:
      parameterName - The parameter name
      parameterValue - The parameter value
      Returns:
      The request specification
    • formParams

      public MockMvcRequestSpecification formParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
      Description copied from interface: MockMvcRequestSpecification
      Specify the form parameters that'll be sent with the request. Note that this method is the same as MockMvcRequestSpecification.params(String, Object, Object...) for all http methods except for POST where MockMvcRequestSpecification.params(String, Object, Object...) sets the form parameters and this method sets the form parameters.
      Specified by:
      formParams in interface MockMvcRequestSpecification
      Parameters:
      firstParameterName - The name of the first parameter
      firstParameterValue - The value of the first parameter
      parameterNameValuePairs - The value of the first parameter followed by additional parameters in name-value pairs.
      Returns:
      The request specification
    • formParams

      public MockMvcRequestSpecification formParams(Map<String,?> parametersMap)
      Description copied from interface: MockMvcRequestSpecification
      Specify the form parameters that'll be sent with the request. Note that this method is the same as MockMvcRequestSpecification.params(Map) for all http methods except for POST where MockMvcRequestSpecification.params(Map) sets the form parameters and this method sets the form parameters.
      Specified by:
      formParams in interface MockMvcRequestSpecification
      Parameters:
      parametersMap - The Map containing the parameter names and their values to send with the request.
      Returns:
      The request specification
    • formParam

      public MockMvcRequestSpecification formParam(String parameterName, Object... parameterValues)
      Description copied from interface: MockMvcRequestSpecification
      Specify a form parameter that'll be sent with the request. Note that this method is the same as MockMvcRequestSpecification.param(String, Object...) for all http methods except for POST where MockMvcRequestSpecification.param(String, Object...) adds a form parameter and this method sets a form parameter.
      Specified by:
      formParam in interface MockMvcRequestSpecification
      Parameters:
      parameterName - The parameter name
      parameterValues - Zero to many parameter values, i.e. you can specify multiple values for the same parameter
      Returns:
      The request specification
      See Also:
    • formParam

      public MockMvcRequestSpecification formParam(String parameterName, Collection<?> parameterValues)
      Description copied from interface: MockMvcRequestSpecification
      Specify a multi-value form parameter that'll be sent with the request e.g:

       given().formParam("cars", asList("Volvo", "Saab"))..;
       
      This will set the parameter cars=Volvo and cars=Saab.

      Note that this method is the same as MockMvcRequestSpecification.param(String, java.util.Collection) for all http methods except for POST where MockMvcRequestSpecification.param(String, java.util.Collection) adds a form parameter and this method sets a form parameter.

      Specified by:
      formParam in interface MockMvcRequestSpecification
      Parameters:
      parameterName - The parameter name
      parameterValues - The parameter values
      Returns:
      The request specification
    • attribute

      public MockMvcRequestSpecification attribute(String attributeName, Object attributeValue)
      Description copied from interface: MockMvcRequestSpecification
      Specify a single-value request attribute
      Specified by:
      attribute in interface MockMvcRequestSpecification
      Parameters:
      attributeName - The attribute name
      attributeValue - The attribute value
      Returns:
      The request specification
    • attributes

      public MockMvcRequestSpecification attributes(Map<String,?> attributesMap)
      Description copied from interface: MockMvcRequestSpecification
      Specify request attributes as a map
      Specified by:
      attributes in interface MockMvcRequestSpecification
      Parameters:
      attributesMap - The Map containing the request attribute names and their values
      Returns:
      The request specification
    • body

      public MockMvcRequestSpecification body(String body)
      Description copied from interface: MockMvcRequestSpecification
      Specify a String request body (such as e.g. JSON or XML) that'll be sent with the request. This works for the POST and PUT methods only. Trying to do this for the other http methods will cause an exception to be thrown.

      Example of use:

       given().body("{ \"message\" : \"hello world\"}").then().expect().body(equalTo("hello world")).when().post("/json");
       
      This will POST a request containing JSON to "/json" and expect that the response body equals to "hello world".

      Specified by:
      body in interface MockMvcRequestSpecification
      Parameters:
      body - The body to send.
      Returns:
      The request specification
    • body

      public MockMvcRequestSpecification body(byte[] body)
      Description copied from interface: MockMvcRequestSpecification
      Specify a byte array request body that'll be sent with the request. This only works for the POST http method. Trying to do this for the other http methods will cause an exception to be thrown.

      Example of use:

       byte[] someBytes = ..
       given().body(someBytes).then().expect().body(equalTo("hello world")).when().post("/json");
       
      This will POST a request containing someBytes to "/json" and expect that the response body equals to "hello world".

      Specified by:
      body in interface MockMvcRequestSpecification
      Parameters:
      body - The body to send.
      Returns:
      The request specification
    • body

      public MockMvcRequestSpecification body(File body)
      Description copied from interface: MockMvcRequestSpecification
      Specify file content that'll be sent with the request. This only works for the POST, PATCH and PUT http method. Trying to do this for the other http methods will cause an exception to be thrown.

      Example of use:

       File myFile = ..
       given().content(myFile).when().post("/json").then().content(equalTo("hello world"));
       
      This will POST a request containing myFile to "/json" and expect that the response content equals to "hello world".

      Specified by:
      body in interface MockMvcRequestSpecification
      Parameters:
      body - The content to send.
      Returns:
      The request specification
    • body

      public MockMvcRequestSpecification body(Object object)
      Description copied from interface: MockMvcRequestSpecification
      Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request. If the object is a primitive or Number the object will be converted to a String and put in the request body. This works for the POST and PUT methods only. Trying to do this for the other http methods will cause an exception to be thrown.

      Example of use:

       Message message = new Message();
       message.setMessage("My beautiful message");
      
       given().
               contentType("application/json").
               body(message).
       expect().
               content(equalTo("Response to a beautiful message")).
       when().
               post("/beautiful-message");
       

      Since the content-type is "application/json" then REST Assured will automatically try to serialize the object using Jackson or Gson if they are available in the classpath. If any of these frameworks are not in the classpath then an exception is thrown.
      If the content-type is "application/xml" then REST Assured will automatically try to serialize the object using JAXB if it's available in the classpath. Otherwise an exception will be thrown.
      If no request content-type is specified then REST Assured determine the parser in the following order:
      1. Jackson
      2. Gson
      3. JAXB
      Specified by:
      body in interface MockMvcRequestSpecification
      Parameters:
      object - The object to serialize and send with the request
      Returns:
      The request specification
    • body

      public MockMvcRequestSpecification body(Object object, io.restassured.mapper.ObjectMapper mapper)
      Description copied from interface: MockMvcRequestSpecification
      Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request using a specific object mapper. This works for the POST, PATCH and PUT methods only. Trying to do this for the other http methods will cause an exception to be thrown.

      Example of use:

       Message message = new Message();
       message.setMessage("My beautiful message");
      
       given().
               body(message, new MyObjectMapper()).
       expect().
               content(equalTo("Response to a beautiful message")).
       when().
               post("/beautiful-message");
       
      Specified by:
      body in interface MockMvcRequestSpecification
      Parameters:
      object - The object to serialize and send with the request
      mapper - The object mapper
      Returns:
      The request specification
    • body

      public MockMvcRequestSpecification body(Object object, io.restassured.mapper.ObjectMapperType mapperType)
      Description copied from interface: MockMvcRequestSpecification
      Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request using a specific object mapper type. This works for the POST, PATCH and PUT methods only. Trying to do this for the other http methods will cause an exception to be thrown.

      Example of use:

       Message message = new Message();
       message.setMessage("My beautiful message");
      
       given().
               body(message, ObjectMapper.GSON).
       expect().
               content(equalTo("Response to a beautiful message")).
       when().
               post("/beautiful-message");
       
      Specified by:
      body in interface MockMvcRequestSpecification
      Parameters:
      object - The object to serialize and send with the request
      mapperType - The object mapper type to be used
      Returns:
      The request specification
    • cookies

      public MockMvcRequestSpecification cookies(String firstCookieName, Object firstCookieValue, Object... cookieNameValuePairs)
      Description copied from interface: MockMvcRequestSpecification
      Specify the cookies that'll be sent with the request. This is done by specifying the cookies in name-value pairs, e.g:
       given().cookies("username", "John", "token", "1234").then().expect().body(equalTo("username, token")).when().get("/cookie");
       

      This will send a GET request to "/cookie" with two cookies:

      1. username=John
      2. token=1234
      and expect that the response body is equal to "username, token".
      Specified by:
      cookies in interface MockMvcRequestSpecification
      Parameters:
      firstCookieName - The name of the first cookie
      firstCookieValue - The value of the first cookie
      cookieNameValuePairs - Additional cookies in name-value pairs.
      Returns:
      The request specification
    • cookies

      public MockMvcRequestSpecification cookies(Map<String,?> cookies)
      Description copied from interface: MockMvcRequestSpecification
      Specify the cookies that'll be sent with the request as Map e.g:
       Map<String, String> cookies = new HashMap<String, String>();
       cookies.put("username", "John");
       cookies.put("token", "1234");
       given().cookies(cookies).then().expect().body(equalTo("username, token")).when().get("/cookie");
       

      This will send a GET request to "/cookie" with two cookies:

      1. username=John
      2. token=1234
      and expect that the response body is equal to "username, token".
      Specified by:
      cookies in interface MockMvcRequestSpecification
      Parameters:
      cookies - The Map containing the cookie names and their values to set in the request.
      Returns:
      The request specification
    • cookies

      public MockMvcRequestSpecification cookies(io.restassured.http.Cookies cookies)
      Description copied from interface: MockMvcRequestSpecification
      Specify the cookies that'll be sent with the request as Cookies:
       Cookie cookie1 = Cookie.Builder("username", "John").setComment("comment 1").build();
       Cookie cookie2 = Cookie.Builder("token", 1234).setComment("comment 2").build();
       Cookies cookies = new Cookies(cookie1, cookie2);
       given().cookies(cookies).then().expect().body(equalTo("username, token")).when().get("/cookie");
       

      This will send a GET request to "/cookie" with two cookies:

      1. username=John
      2. token=1234
      and expect that the response body is equal to "username, token".
      Specified by:
      cookies in interface MockMvcRequestSpecification
      Parameters:
      cookies - The cookies to set in the request.
      Returns:
      The request specification
    • cookie

      public MockMvcRequestSpecification cookie(String cookieName, Object cookieValue, Object... additionalValues)
      Description copied from interface: MockMvcRequestSpecification
      Specify a cookie that'll be sent with the request e.g:

       given().cookie("username", "John").and().expect().body(equalTo("username")).when().get("/cookie");
       
      This will set the cookie username=John in the GET request to "/cookie".

      You can also specify several cookies like this:

       given().cookie("username", "John").and().cookie("password", "1234").and().expect().body(equalTo("username")).when().get("/cookie");
       

      If you specify additionalValues then the Cookie will be a multi-value cookie. This means that you'll create several cookies with the same name but with different values.

      Specified by:
      cookie in interface MockMvcRequestSpecification
      Parameters:
      cookieName - The cookie cookieName
      cookieValue - The cookie value
      additionalValues - Additional cookies values. This will actually create two cookies with the same name but with different values.
      Returns:
      The request specification
      See Also:
    • cookie

      public MockMvcRequestSpecification cookie(io.restassured.http.Cookie cookie)
      Description copied from interface: MockMvcRequestSpecification
      Specify a Cookie to send with the request.

       Cookie someCookie = new Cookie.Builder("some_cookie", "some_value").setSecured(true).build();
       given().cookie(someCookie).and().expect().body(equalTo("x")).when().get("/cookie");
       
      This will set the cookie someCookie in the GET request to "/cookie".

      Specified by:
      cookie in interface MockMvcRequestSpecification
      Parameters:
      cookie - The cookie to add to the request
      Returns:
      The request specification
      See Also:
    • multiPart

      public MockMvcRequestSpecification multiPart(File file)
      Description copied from interface: MockMvcRequestSpecification
      Specify a file to upload to the server using multi-part form data uploading. It will assume that the control name is file and the mime-type is application/octet-stream. If this is not what you want please use an overloaded method.
      Specified by:
      multiPart in interface MockMvcRequestSpecification
      Parameters:
      file - The file to upload
      Returns:
      The request specification
    • multiPart

      public MockMvcRequestSpecification multiPart(String controlName, File file)
      Description copied from interface: MockMvcRequestSpecification
      Specify a file to upload to the server using multi-part form data uploading with a specific control name. It will use the mime-type application/octet-stream. If this is not what you want please use an overloaded method.
      Specified by:
      multiPart in interface MockMvcRequestSpecification
      Parameters:
      controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
      file - The file to upload
      Returns:
      The request specification
    • multiPart

      public MockMvcRequestSpecification multiPart(String controlName, File file, String mimeType)
      Description copied from interface: MockMvcRequestSpecification
      Specify a file to upload to the server using multi-part form data uploading with a specific control name and mime-type.
      Specified by:
      multiPart in interface MockMvcRequestSpecification
      Parameters:
      controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
      file - The file to upload
      mimeType - The mime-type
      Returns:
      The request specification
    • multiPart

      public MockMvcRequestSpecification multiPart(String controlName, Object object)
      Description copied from interface: MockMvcRequestSpecification
      Specify an object that will be serialized to JSON and uploaded to the server using multi-part form data uploading with a specific control name. It will use mime-type application/json. If this is not what you want please use an overloaded method.
      Specified by:
      multiPart in interface MockMvcRequestSpecification
      Parameters:
      controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
      object - The object to serialize to JSON or XML and send to the server
      Returns:
      The request specification
    • multiPart

      public MockMvcRequestSpecification multiPart(String controlName, Object object, String mimeType)
      Description copied from interface: MockMvcRequestSpecification
      Specify an object that will be serialized and uploaded to the server using multi-part form data uploading with a specific control name.
      Specified by:
      multiPart in interface MockMvcRequestSpecification
      Parameters:
      controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
      object - The object to serialize to JSON or XML and send to the server
      mimeType - The mime-type
      Returns:
      The request specification
    • multiPart

      public MockMvcRequestSpecification multiPart(String controlName, String filename, Object object, String mimeType)
      Description copied from interface: MockMvcRequestSpecification
      Specify an object that will be serialized and uploaded to the server using multi-part form data uploading with a specific control name.
      Specified by:
      multiPart in interface MockMvcRequestSpecification
      Parameters:
      controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
      filename - The name of the content you're uploading
      object - The object to serialize to JSON or XML and send to the server
      mimeType - The mime-type
      Returns:
      The request specification
    • multiPart

      public MockMvcRequestSpecification multiPart(String controlName, String fileName, byte[] bytes)
      Description copied from interface: MockMvcRequestSpecification
      Specify a byte-array to upload to the server using multi-part form data. It will use the mime-type application/octet-stream. If this is not what you want please use an overloaded method.
      Specified by:
      multiPart in interface MockMvcRequestSpecification
      Parameters:
      controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
      fileName - The name of the content you're uploading
      bytes - The bytes you want to send
      Returns:
      The request specification
    • multiPart

      public MockMvcRequestSpecification multiPart(String controlName, String fileName, byte[] bytes, String mimeType)
      Description copied from interface: MockMvcRequestSpecification
      Specify a byte-array to upload to the server using multi-part form data.
      Specified by:
      multiPart in interface MockMvcRequestSpecification
      Parameters:
      controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
      fileName - The name of the content you're uploading
      bytes - The bytes you want to send
      mimeType - The mime-type
      Returns:
      The request specification
    • multiPart

      public MockMvcRequestSpecification multiPart(String controlName, String fileName, InputStream stream)
      Description copied from interface: MockMvcRequestSpecification
      Specify an inputstream to upload to the server using multi-part form data. It will use the mime-type application/octet-stream. If this is not what you want please use an overloaded method.
      Specified by:
      multiPart in interface MockMvcRequestSpecification
      Parameters:
      controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
      fileName - The name of the content you're uploading
      stream - The stream you want to send
      Returns:
      The request specification
    • multiPart

      public MockMvcRequestSpecification multiPart(String controlName, String fileName, InputStream stream, String mimeType)
      Description copied from interface: MockMvcRequestSpecification
      Specify an inputstream to upload to the server using multi-part form data.
      Specified by:
      multiPart in interface MockMvcRequestSpecification
      Parameters:
      controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
      fileName - The name of the content you're uploading
      stream - The stream you want to send
      mimeType - The mime-type
      Returns:
      The request specification
    • multiPart

      public MockMvcRequestSpecification multiPart(String controlName, String contentBody)
      Description copied from interface: MockMvcRequestSpecification
      Specify a string to send to the server using multi-part form data. It will use the mime-type text/plain. If this is not what you want please use an overloaded method.
      Specified by:
      multiPart in interface MockMvcRequestSpecification
      Parameters:
      controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
      contentBody - The string to send
      Returns:
      The request specification
    • multiPart

      public MockMvcRequestSpecification multiPart(String controlName, String contentBody, String mimeType)
      Description copied from interface: MockMvcRequestSpecification
      Specify a string to send to the server using multi-part form data with a specific mime-type.
      Specified by:
      multiPart in interface MockMvcRequestSpecification
      Parameters:
      controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
      contentBody - The string to send
      mimeType - The mime-type
      Returns:
      The request specification
    • config

      Description copied from interface: MockMvcRequestSpecification
      Define a REST Assured Mock Mvc configuration. E.g.
       given().config(newConfig().logConfig(new LogConfig(captor, true))). ..
       

      newConfig() can be statically imported from RestAssuredMockMvcConfig.

      Specified by:
      config in interface MockMvcRequestSpecification
      Parameters:
      config - The configuration to use for this request. If null no config will be used.
      Returns:
      The request specification
    • spec

      public MockMvcRequestSpecification spec(MockMvcRequestSpecification requestSpecificationToMerge)
      Description copied from interface: MockMvcRequestSpecification
      Add request data from a pre-defined specification. E.g.
       MockMvcRequestSpecification requestSpec = new MockMvcRequestSpecBuilder().addParam("parameter1", "value1").build();
      
       given().
               spec(requestSpec).
               param("parameter2", "value2").
       when().
              get("/something");
       

      This is useful when you want to reuse an entire specification across multiple requests.

      The specification passed to this method is merged with the current specification. Note that the supplied specification can overwrite data in the current specification. The following settings are overwritten:

      • Content type
      • Request body
      • Interceptions
      • Log (if defined in requestSpecificationToMerge)
      • Config
      The following settings are merged:
      • Parameters
      • Attributes
      • Cookies
      • Headers

      Specified by:
      spec in interface MockMvcRequestSpecification
      Parameters:
      requestSpecificationToMerge - The specification to merge with.
      Returns:
      the request specification
    • sessionAttrs

      public MockMvcRequestSpecification sessionAttrs(Map<String,Object> sessionAttributes)
      Set session attributes.
      Specified by:
      sessionAttrs in interface MockMvcRequestSpecification
      Parameters:
      sessionAttributes - the session attributes
    • sessionId

      public MockMvcRequestSpecification sessionId(String sessionIdValue)
      Description copied from interface: MockMvcRequestSpecification
      Set the session id for this request. It will use the configured session id name from the configuration (by default this is ). You can configure the session id name by using:
           RestAssured.config = newConfig().sessionConfig(new SessionConfig().sessionIdName(<sessionIdName>));
       
      or you can use the MockMvcRequestSpecification.sessionId(String, String) method to set it for this request only.
      Specified by:
      sessionId in interface MockMvcRequestSpecification
      Parameters:
      sessionIdValue - The session id value.
      Returns:
      The request specification
    • sessionId

      public MockMvcRequestSpecification sessionId(String sessionIdName, String sessionIdValue)
      Description copied from interface: MockMvcRequestSpecification
      Set the session id name and value for this request. It'll override the default session id name from the configuration (by default this is ). You can configure the default session id name by using:
           RestAssured.config = newConfig().sessionConfig(new SessionConfig().sessionIdName(<sessionIdName>));
       
      and then you can use the MockMvcRequestSpecification.sessionId(String) method to set the session id value without specifying the name for each request.
      Specified by:
      sessionId in interface MockMvcRequestSpecification
      Parameters:
      sessionIdName - The session id name
      sessionIdValue - The session id value.
      Returns:
      The request specification
    • resultHandlers

      public MockMvcRequestSpecification resultHandlers(org.springframework.test.web.servlet.ResultHandler resultHandler, org.springframework.test.web.servlet.ResultHandler... resultHandlers)
    • when

      Description copied from interface: MockMvcRequestSpecification
      Call this method when you're done setting up the request specification.
      Specified by:
      when in interface MockMvcRequestSpecification
      Returns:
      The MockMvcRequestSender that let's you send the request.
    • get

      public MockMvcResponse get(String path, Object... pathParams)
      Specified by:
      get in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • get

      public MockMvcResponse get(String path, Map<String,?> pathParams)
      Specified by:
      get in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • post

      public MockMvcResponse post(String path, Object... pathParams)
      Specified by:
      post in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • post

      public MockMvcResponse post(String path, Map<String,?> pathParams)
      Specified by:
      post in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • put

      public MockMvcResponse put(String path, Object... pathParams)
      Specified by:
      put in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • put

      public MockMvcResponse put(String path, Map<String,?> pathParams)
      Specified by:
      put in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • delete

      public MockMvcResponse delete(String path, Object... pathParams)
      Specified by:
      delete in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • delete

      public MockMvcResponse delete(String path, Map<String,?> pathParams)
      Specified by:
      delete in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • head

      public MockMvcResponse head(String path, Object... pathParams)
      Specified by:
      head in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • head

      public MockMvcResponse head(String path, Map<String,?> pathParams)
      Specified by:
      head in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • patch

      public MockMvcResponse patch(String path, Object... pathParams)
      Specified by:
      patch in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • patch

      public MockMvcResponse patch(String path, Map<String,?> pathParams)
      Specified by:
      patch in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • options

      public MockMvcResponse options(String path, Object... pathParams)
      Specified by:
      options in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • options

      public MockMvcResponse options(String path, Map<String,?> pathParams)
      Specified by:
      options in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • get

      public MockMvcResponse get(URI uri)
      Specified by:
      get in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • post

      public MockMvcResponse post(URI uri)
      Specified by:
      post in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • put

      public MockMvcResponse put(URI uri)
      Specified by:
      put in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • delete

      public MockMvcResponse delete(URI uri)
      Specified by:
      delete in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • head

      public MockMvcResponse head(URI uri)
      Specified by:
      head in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • patch

      public MockMvcResponse patch(URI uri)
      Specified by:
      patch in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • options

      public MockMvcResponse options(URI uri)
      Specified by:
      options in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • get

      public MockMvcResponse get(URL url)
      Specified by:
      get in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • post

      public MockMvcResponse post(URL url)
      Specified by:
      post in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • put

      public MockMvcResponse put(URL url)
      Specified by:
      put in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • delete

      public MockMvcResponse delete(URL url)
      Specified by:
      delete in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • head

      public MockMvcResponse head(URL url)
      Specified by:
      head in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • patch

      public MockMvcResponse patch(URL url)
      Specified by:
      patch in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • options

      public MockMvcResponse options(URL url)
      Specified by:
      options in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • get

      public MockMvcResponse get()
      Specified by:
      get in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • post

      public MockMvcResponse post()
      Specified by:
      post in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • put

      public MockMvcResponse put()
      Specified by:
      put in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • delete

      public MockMvcResponse delete()
      Specified by:
      delete in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • head

      public MockMvcResponse head()
      Specified by:
      head in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • patch

      public MockMvcResponse patch()
      Specified by:
      patch in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • options

      public MockMvcResponse options()
      Specified by:
      options in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • request

      public MockMvcResponse request(io.restassured.http.Method method)
      Specified by:
      request in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • request

      public MockMvcResponse request(String method)
      Specified by:
      request in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • request

      public MockMvcResponse request(io.restassured.http.Method method, String path, Object... pathParams)
      Specified by:
      request in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • request

      public MockMvcResponse request(String method, String path, Object... pathParams)
      Specified by:
      request in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • request

      public MockMvcResponse request(io.restassured.http.Method method, URI uri)
      Specified by:
      request in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • request

      public MockMvcResponse request(io.restassured.http.Method method, URL url)
      Specified by:
      request in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • request

      public MockMvcResponse request(String method, URI uri)
      Specified by:
      request in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • request

      public MockMvcResponse request(String method, URL url)
      Specified by:
      request in interface io.restassured.specification.RequestSenderOptions<MockMvcResponse>
    • getRestAssuredConfig

      public io.restassured.config.RestAssuredConfig getRestAssuredConfig()
    • setRequestLoggingFilter

      public void setRequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter requestLoggingFilter)
    • getMockMvcFactory

      public MockMvcFactory getMockMvcFactory()
    • getBasePath

      public String getBasePath()
    • getParams

      public Map<String,Object> getParams()
    • getQueryParams

      public Map<String,Object> getQueryParams()
    • getPathParams

      public Map<String,Object> getPathParams()
    • getFormParams

      public Map<String,Object> getFormParams()
    • getAttributes

      public Map<String,Object> getAttributes()
    • getRequestBody

      public Object getRequestBody()
    • getAuthentication

      public Object getAuthentication()
    • getRestAssuredMockMvcConfig

      public RestAssuredMockMvcConfig getRestAssuredMockMvcConfig()
    • getRequestHeaders

      public io.restassured.http.Headers getRequestHeaders()
    • getCookies

      public io.restassured.http.Cookies getCookies()
    • getRequestContentType

      public String getRequestContentType()
    • getMultiParts

      public List<io.restassured.module.mockmvc.internal.MockMvcMultiPart> getMultiParts()
    • getRequestLoggingFilter

      public io.restassured.filter.log.RequestLoggingFilter getRequestLoggingFilter()
    • getResultHandlers

      public List<org.springframework.test.web.servlet.ResultHandler> getResultHandlers()
    • getRequestPostProcessors

      public List<org.springframework.test.web.servlet.request.RequestPostProcessor> getRequestPostProcessors()
    • getInterceptor

    • basePath

      public MockMvcRequestSpecification basePath(String path)
    • principal

      public MockMvcRequestSpecification principal(Principal principal)
      Description copied from interface: MockMvcAuthenticationSpecification
      Authenticate using the given principal. This method simply delegates to AbstractMockHttpServletRequestBuilder.principal(java.security.Principal).
      Specified by:
      principal in interface MockMvcAuthenticationSpecification
      Parameters:
      principal - The principal to use.
      Returns:
      The request specification
      See Also:
      • AbstractMockHttpServletRequestBuilder.principal(java.security.Principal)
    • with

      public MockMvcRequestSpecification with(org.springframework.test.web.servlet.request.RequestPostProcessor requestPostProcessor, org.springframework.test.web.servlet.request.RequestPostProcessor... additionalRequestPostProcessor)
      Description copied from interface: MockMvcAuthenticationSpecification
      Authenticate using a RequestPostProcessor. This is mainly useful when you have added the spring-security-test artifact to classpath. This allows you to do for example:
       given().auth().with(user("username").password("password")). ..
       
      where user is statically imported from org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.
      Specified by:
      with in interface MockMvcAuthenticationSpecification
      Parameters:
      requestPostProcessor - The first request post processor to be used for authentication
      additionalRequestPostProcessor - Additional request post processors to be used for authentication
      Returns:
      A MockMvcAuthenticationScheme instance.
    • principal

      public MockMvcRequestSpecification principal(Object principal)
      Description copied from interface: MockMvcAuthenticationSpecification
      Authenticate using the given principal. The principal will be used like this:
       SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(principal, ""));
       

      Note that this method require Spring Security to be on the classpath. Also note that if you use this method Rest Assured will NOT be thread-safe.

      Specified by:
      principal in interface MockMvcAuthenticationSpecification
      Parameters:
      principal - The principal to use.
      Returns:
      The request specification
    • principalWithCredentials

      public MockMvcRequestSpecification principalWithCredentials(Object principal, Object credentials, String... authorities)
      Description copied from interface: MockMvcAuthenticationSpecification
      Authenticate using the given principal and credentials. The principal and credentials will be used like this:
       SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(principal, credentials, authorities));
       

      Note that this method require Spring Security to be on the classpath. Also note that if you use this method Rest Assured will NOT be thread-safe.

      Specified by:
      principalWithCredentials in interface MockMvcAuthenticationSpecification
      Parameters:
      principal - The principal to use.
      credentials - The credentials to use
      authorities - Optional list of authorities
      Returns:
      The request specification
    • authentication

      public MockMvcRequestSpecification authentication(Object authentication)
      Description copied from interface: MockMvcAuthenticationSpecification
      Authenticate using the given authentication instance. The authentication instance will be used like this:
       SecurityContextHolder.getContext().setAuthentication(authentication);
       
      This means that the supplied object must be an instance of org.springframework.security.core.Authentication.

      Note that this method require Spring Security to be on the classpath. Also note that if you use this method Rest Assured will NOT be thread-safe.

      Specified by:
      authentication in interface MockMvcAuthenticationSpecification
      Parameters:
      authentication - the spring security authentication to use.
      Returns:
      The request specification
    • none

      Description copied from interface: MockMvcAuthenticationSpecification
      Explicitly state that you don't which to use any authentication in this request. This is useful only in cases where you've specified a default authentication scheme and you wish to override it for a single request.
      Specified by:
      none in interface MockMvcAuthenticationSpecification
      Returns:
      The request specification
    • getLogRepository

      public io.restassured.internal.log.LogRepository getLogRepository()
    • getAsyncConfig

      public AsyncConfig getAsyncConfig()
    • sessionAttr

      public MockMvcRequestSpecification sessionAttr(String name, Object value)
      Set a session attribute.
      Specified by:
      sessionAttr in interface MockMvcRequestSpecification
      Parameters:
      name - the session attribute name
      value - the session attribute value