Class WebTestClientRequestSpecBuilder

java.lang.Object
io.restassured.module.webtestclient.specification.WebTestClientRequestSpecBuilder

public class WebTestClientRequestSpecBuilder extends Object
  • Constructor Details

    • WebTestClientRequestSpecBuilder

      public WebTestClientRequestSpecBuilder()
  • Method Details

    • setBody

      public WebTestClientRequestSpecBuilder setBody(String body)
      Specify a String request body (such as e.g. JSON or XML) to be sent with the request. This works for the POST, PUT and PATCH methods only. Trying to do this for the other http methods will cause an exception to be thrown.

      Parameters:
      body - The body to send.
      Returns:
      The request specification builder
    • setBody

      public WebTestClientRequestSpecBuilder setBody(byte[] body)
      Specify a byte array request body to 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.
      Parameters:
      body - The body to send.
      Returns:
      The request specification builder
    • setBody

      public WebTestClientRequestSpecBuilder setBody(Object object)
      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, PUT and PATCH methods only. Trying to do this for the other http methods will cause an exception to be thrown.

      Parameters:
      object - The object to serialize and send with the request
      Returns:
      The request specification
    • setBody

      public WebTestClientRequestSpecBuilder setBody(Object object, io.restassured.mapper.ObjectMapper mapper)
      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.

      Note that setBody(Object, ObjectMapperType) are the same except for the syntactic difference.

      Parameters:
      object - The object to serialize and send with the request
      mapper - The object mapper
      Returns:
      The request specification
    • setBody

      public WebTestClientRequestSpecBuilder setBody(Object object, io.restassured.mapper.ObjectMapperType mapperType)
      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");
       

      Note that setBody(Object, ObjectMapper) are the same except for the syntactic difference.

      Parameters:
      object - The object to serialize and send with the request
      mapperType - The object mapper type to be used
      Returns:
      The request specification
    • addCookies

      public WebTestClientRequestSpecBuilder addCookies(Map<String,?> cookies)
      Add cookies to be sent with the request as Map e.g:
      Parameters:
      cookies - The Map containing the cookie names and their values to set in the request.
      Returns:
      The request specification builder
    • addCookie

      public WebTestClientRequestSpecBuilder addCookie(io.restassured.http.Cookie cookie)
      Add a detailed cookie
      Parameters:
      cookie - The cookie to add.
      Returns:
      The request specification builder
    • addCookie

      public WebTestClientRequestSpecBuilder addCookie(String key, Object value, Object... cookieNameValuePairs)
      Add a cookie to be sent with the request.
      Parameters:
      key - The cookie key
      value - The cookie value
      cookieNameValuePairs - Additional cookies values. This will actually create two cookies with the same name but with different values.
      Returns:
      The request specification builder
    • addParams

      public WebTestClientRequestSpecBuilder addParams(Map<String,?> parametersMap)
      Parameters:
      parametersMap - The Map containing the parameter names and their values to send with the request.
      Returns:
      The request specification builder
    • addParam

      public WebTestClientRequestSpecBuilder addParam(String parameterName, Object... parameterValues)
      Parameters:
      parameterValues - Zero to many parameter values for this parameter name.
      Returns:
      The request specification builder
    • addParam

      public WebTestClientRequestSpecBuilder addParam(String parameterName, Collection<?> parameterValues)
      Parameters:
      parameterName - The parameter key
      parameterValues - The parameter values
      Returns:
      The request specification builder
    • addQueryParam

      public WebTestClientRequestSpecBuilder addQueryParam(String parameterName, Collection<?> parameterValues)
      Parameters:
      parameterName - The parameter key
      parameterValues - The parameter values
      Returns:
      The request specification builder
      See Also:
    • addQueryParams

      public WebTestClientRequestSpecBuilder addQueryParams(Map<String,?> parametersMap)
      Parameters:
      parametersMap - The Map containing the parameter names and their values to send with the request.
      Returns:
      The request specification builder
    • addQueryParam

      public WebTestClientRequestSpecBuilder addQueryParam(String parameterName, Object... parameterValues)
      Parameters:
      parameterName - The parameter key
      parameterValues - Zero to many parameter values for this parameter name.
      Returns:
      The request specification builder
    • addPathParam

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

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

       expect().statusCode(200).when().get("/item/{itemNumber}/buy/{amount}", myItem.getItemNumber(), 2);
       
      Parameters:
      parameterName - The parameter key
      parameterValue - The parameter value
      Returns:
      The request specification
    • addPathParams

      public WebTestClientRequestSpecBuilder addPathParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
      Specify multiple path parameter name-value pairs. Path parameters are used to improve readability of the request path. E.g. instead of writing:
       expect().statusCode(200).when().get("/item/"+myItem.getItemNumber()+"/buy/"+2);
       
      you can write:
       given().
               pathParam("itemNumber", myItem.getItemNumber(), "amount", 2).
       expect().
                statusCode(200).
       when().
              get("/item/{itemNumber}/buy/{amount}");
       

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

       expect().statusCode(200).when().get("/item/{itemNumber}/buy/{amount}", myItem.getItemNumber(), 2);
       
      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
    • addPathParams

      public WebTestClientRequestSpecBuilder addPathParams(Map<String,Object> parameterNameValuePairs)
      Specify multiple path parameter name-value pairs. Path parameters are used to improve readability of the request path. E.g. instead of writing:
       expect().statusCode(200).when().get("/item/"+myItem.getItemNumber()+"/buy/"+2);
       
      you can write:
       Map<String,Object> pathParams = new HashMap<String,Object>();
       pathParams.add("itemNumber",myItem.getItemNumber());
       pathParams.add("amount",2);
      
       given().
               pathParameters(pathParams).
       expect().
                statusCode(200).
       when().
              get("/item/{itemNumber}/buy/{amount}");
       

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

       expect().statusCode(200).when().get("/item/{itemNumber}/buy/{amount}", myItem.getItemNumber(), 2);
       
      Parameters:
      parameterNameValuePairs - A map containing the path parameters.
      Returns:
      The request specification
    • addFormParam

      public WebTestClientRequestSpecBuilder addFormParam(String parameterName, Collection<?> parameterValues)
      Parameters:
      parameterName - The parameter key
      parameterValues - The parameter values
      Returns:
      The request specification builder
      See Also:
    • addFormParams

      public WebTestClientRequestSpecBuilder addFormParams(Map<String,?> parametersMap)
      Parameters:
      parametersMap - The Map containing the parameter names and their values to send with the request.
      Returns:
      The request specification builder
    • addFormParam

      public WebTestClientRequestSpecBuilder addFormParam(String parameterName, Object... parameterValues)
      Parameters:
      parameterName - The parameter name
      parameterValues - Zero to many parameter values for this parameter name.
      Returns:
      The request specification builder
      See Also:
    • addAttribute

      public WebTestClientRequestSpecBuilder addAttribute(String attributeName, Object attributeValue)
      Add request attribute
      Parameters:
      attributeName - The attribute name
      attributeValue - The attribute value
      Returns:
      The request specification builder
    • addAttributes

      public WebTestClientRequestSpecBuilder addAttributes(Map<String,?> attributesMap)
      Add request attributes
      Parameters:
      attributesMap - The Map containing the request attribute names and their values
      Returns:
      The request specification builder
    • addHeaders

      public WebTestClientRequestSpecBuilder addHeaders(Map<String,String> headers)
      Add headers to be sent with the request as Map.
      Parameters:
      headers - The Map containing the header names and their values to send with the request.
      Returns:
      The request specification builder
    • addHeader

      public WebTestClientRequestSpecBuilder addHeader(String headerName, String headerValue)
      Add a header to be sent with the request
      Parameters:
      headerName - The header name
      headerValue - The header value
      Returns:
      The request specification builder
    • addHeader

      public WebTestClientRequestSpecBuilder addHeader(io.restassured.http.Header header)
      Add a header to be sent with the request.
      Parameters:
      header - The header
      Returns:
      The request specification builder
    • setContentType

      public WebTestClientRequestSpecBuilder setContentType(io.restassured.http.ContentType contentType)
      Specify the content type of the request.
      Parameters:
      contentType - The content type of the request
      Returns:
      The request specification builder
      See Also:
      • ContentType
    • setContentType

      public WebTestClientRequestSpecBuilder setContentType(String contentType)
      Specify the content type of the request as string.
      Parameters:
      contentType - The content type of the request
      Returns:
      The request specification builder
    • addMultiPart

      public WebTestClientRequestSpecBuilder addMultiPart(File file)
      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 content-type is application/octet-stream. If this is not what you want please use an overloaded method.
      Parameters:
      file - The file to upload
      Returns:
      The request specification
    • addMultiPart

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

      public WebTestClientRequestSpecBuilder addMultiPart(String controlName, File file, String mimeType)
      Specify a file to upload to the server using multi-part form data uploading with a specific control name and content-type.
      Parameters:
      file - The file to upload
      controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
      mimeType - The content-type
      Returns:
      The request specification
    • addMultiPart

      public WebTestClientRequestSpecBuilder addMultiPart(String controlName, String fileName, byte[] bytes)
      Specify a byte-array to upload to the server using multi-part form data. It will use the content-type application/octet-stream. If this is not what you want please use an overloaded method.
      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
    • addMultiPart

      public WebTestClientRequestSpecBuilder addMultiPart(String controlName, String fileName, byte[] bytes, String mimeType)
      Specify a byte-array to upload to the server using multi-part form data.
      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 content-type
      Returns:
      The request specification
    • addMultiPart

      public WebTestClientRequestSpecBuilder addMultiPart(String controlName, String fileName, InputStream stream)
      Specify an inputstream to upload to the server using multi-part form data. It will use the content-type application/octet-stream. If this is not what you want please use an overloaded method.
      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
    • addMultiPart

      public WebTestClientRequestSpecBuilder addMultiPart(String controlName, String fileName, InputStream stream, String mimeType)
      Specify an inputstream to upload to the server using multi-part form data.
      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 content-type
      Returns:
      The request specification
    • addMultiPart

      public WebTestClientRequestSpecBuilder addMultiPart(String controlName, String contentBody)
      Specify a string to send to the server using multi-part form data. It will use the content-type text/plain. If this is not what you want please use an overloaded method.
      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
    • addMultiPart

      public WebTestClientRequestSpecBuilder addMultiPart(String controlName, String contentBody, String mimeType)
      Specify a string to send to the server using multi-part form data with a specific mime-type.
      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
    • setSessionId

      public WebTestClientRequestSpecBuilder setSessionId(String sessionIdValue)
      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:
           RestAssuredWebTestClient.config = newConfig().sessionConfig(new SessionConfig().sessionIdName(<sessionIdName>));
       
      or you can use the setSessionId(String, String) method to set it for this request only.
      Parameters:
      sessionIdValue - The session id value.
      Returns:
      The request specification
    • setSessionId

      public WebTestClientRequestSpecBuilder setSessionId(String sessionIdName, String sessionIdValue)
      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:
           RestAssuredWebTestClient.config = newConfig().sessionConfig(new SessionConfig().sessionIdName(<sessionIdName>));
       
      and then you can use the setSessionId(String) method to set the session id value without specifying the name for each request.
      Parameters:
      sessionIdName - The session id name
      sessionIdValue - The session id value.
      Returns:
      The request specification
    • addWebTestClientRequestSpecification

      public WebTestClientRequestSpecBuilder addWebTestClientRequestSpecification(WebTestClientRequestSpecification specification)
      Merge this builder with settings from another specification. Note that the supplied specification can overwrite data in the current specification. The following settings are overwritten:
      • Content type
      • Request body
      • Interceptors
      • Config (if defined)
      The following settings are merged:
      • Parameters
      • Cookies
      • Headers
      Parameters:
      specification - The specification to add
      Returns:
      The request specification builder
    • setConfig

      Define a configuration for redirection settings and http client parameters.
      Parameters:
      config - The configuration to use for this request. If null no config will be used.
      Returns:
      The request specification builder
    • build

      Build the request specification.
      Returns:
      The assembled request specification
    • setBasePath

      public WebTestClientRequestSpecBuilder setBasePath(String basePath)
      Set the basePath property of the WebTestClientRequestSpecBuilder instead of using static field RestAssuredWebTestClient.basePath.

       WebTestClientRequestSpecBuilder builder = new WebTestClientRequestSpecBuilder();
       builder.setBasePath("/something");
       WebTestClientRequestSpecification specs = builder.build();
       given().spec(specs)
       
      Parameters:
      basePath -
      Returns:
      WebTestClientRequestSpecBuilder
    • setWebTestClient

      public WebTestClientRequestSpecBuilder setWebTestClient(org.springframework.test.web.reactive.server.WebTestClient webTestClient)
      The webTestClient instance to use.

      Note that this will override the any WebTestClient instances configured by other setters.*

      Parameters:
      webTestClient - The WebTestClient instance
      Returns:
      WebTestClientRequestSpecBuilder
    • setStandaloneSetup

      public WebTestClientRequestSpecBuilder setStandaloneSetup(Object... controllers)
      The standalone setup to be used by supplying a set of controllers.

      Note that this will override the any WebTestClient instances configured by other setters.

      Parameters:
      controllers - The controllers to use
      Returns:
      WebTestClientRequestSpecBuilder
      See Also:
    • setStandaloneSetup

      public WebTestClientRequestSpecBuilder setStandaloneSetup(org.springframework.test.web.reactive.server.WebTestClient.Builder builder)
      Initialize with a WebTestClientBuilder that will be used to create the WebTestClient instance.

      Note that this will override the any WebTestClient instances configured by other setters.

      Parameters:
      builder - The builder to use
      Returns:
      WebTestClientRequestSpecBuilder
      See Also:
    • setWebAppContextSetup

      public WebTestClientRequestSpecBuilder setWebAppContextSetup(org.springframework.web.context.WebApplicationContext context, org.springframework.test.web.reactive.server.WebTestClientConfigurer... WebTestClientConfigurers)
      Initialize with a WebApplicationContext that will be used to create the WebTestClient instance.

      Note that this will override the any WebTestClient instances configured by other setters.

      Parameters:
      context - The WebApplicationContext to use
      WebTestClientConfigurers - WebTestClientConfigurer's to be applied when creating a WebTestClient instance of this WebApplicationContext (optional)
      Returns:
      WebTestClientRequestSpecBuilder
      See Also:
    • log

      public WebTestClientRequestSpecBuilder log(io.restassured.filter.log.LogDetail logDetail)
      Enabled logging with the specified log detail. Set a LogConfig to configure the print stream and pretty printing options.
      Parameters:
      logDetail - The log detail.
      Returns:
      WebTestClientRequestSpecBuilder
    • and

      Returns the same WebTestClientRequestSpecBuilder instance for syntactic sugar.
      Returns:
      WebTestClientRequestSpecBuilder