Class WebTestClientRequestSpecBuilder
java.lang.Object
io.restassured.module.webtestclient.specification.WebTestClientRequestSpecBuilder
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAttribute(String attributeName, Object attributeValue) Add request attributeaddAttributes(Map<String, ?> attributesMap) Add request attributesaddCookie(io.restassured.http.Cookie cookie) Add a detailed cookieAdd a cookie to be sent with the request.addCookies(Map<String, ?> cookies) Add cookies to be sent with the request as Map e.g:addFormParam(String parameterName, Object... parameterValues) addFormParam(String parameterName, Collection<?> parameterValues) addFormParams(Map<String, ?> parametersMap) addHeader(io.restassured.http.Header header) Add a header to be sent with the request.Add a header to be sent with the requestaddHeaders(Map<String, String> headers) Add headers to be sent with the request as Map.addMultiPart(File file) Specify a file to upload to the server using multi-part form data uploading.addMultiPart(String controlName, File file) Specify a file to upload to the server using multi-part form data uploading with a specific control name.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.addMultiPart(String controlName, String contentBody) Specify a string to send to the server using multi-part form data.addMultiPart(String controlName, String fileName, byte[] bytes) Specify a byte-array to upload to the server using multi-part form data.addMultiPart(String controlName, String fileName, byte[] bytes, String mimeType) Specify a byte-array to upload to the server using multi-part form data.addMultiPart(String controlName, String fileName, InputStream stream) Specify an inputstream to upload to the server using multi-part form data.addMultiPart(String controlName, String fileName, InputStream stream, String mimeType) Specify an inputstream to upload to the server using multi-part form data.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.addParam(String parameterName, Collection<?> parameterValues) addPathParam(String parameterName, Object parameterValue) Specify a path parameter.addPathParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs) Specify multiple path parameter name-value pairs.addPathParams(Map<String, Object> parameterNameValuePairs) Specify multiple path parameter name-value pairs.addQueryParam(String parameterName, Object... parameterValues) addQueryParam(String parameterName, Collection<?> parameterValues) addQueryParams(Map<String, ?> parametersMap) Merge this builder with settings from another specification.and()Returns the same WebTestClientRequestSpecBuilder instance for syntactic sugar.build()Build the request specification.log(io.restassured.filter.log.LogDetail logDetail) Enabled logging with the specified log detail.setBasePath(String basePath) Set the basePath property of the WebTestClientRequestSpecBuilder instead of using static field RestAssuredWebTestClient.basePath.setBody(byte[] body) Specify a byte array request body to be sent with the request.Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request.Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request using a specific object 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 type.Specify a String request body (such as e.g.Define a configuration for redirection settings and http client parameters.setContentType(io.restassured.http.ContentType contentType) Specify the content type of the request.setContentType(String contentType) Specify the content type of the request as string.setSessionId(String sessionIdValue) Set the session id for this request.setSessionId(String sessionIdName, String sessionIdValue) Set the session id name and value for this request.setStandaloneSetup(Object... controllers) The standalone setup to be used by supplying a set of controllers.setStandaloneSetup(org.springframework.test.web.reactive.server.WebTestClient.Builder builder) Initialize with a WebTestClientBuilder that will be used to create theWebTestClientinstance.setWebAppContextSetup(org.springframework.web.context.WebApplicationContext context, org.springframework.test.web.reactive.server.WebTestClientConfigurer... WebTestClientConfigurers) Initialize with aWebApplicationContextthat will be used to create theWebTestClientinstance.setWebTestClient(org.springframework.test.web.reactive.server.WebTestClient webTestClient) The webTestClient instance to use.
-
Constructor Details
-
WebTestClientRequestSpecBuilder
public WebTestClientRequestSpecBuilder()
-
-
Method Details
-
setBody
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
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
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 requestmapper- 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 thatsetBody(Object, ObjectMapper)are the same except for the syntactic difference.- Parameters:
object- The object to serialize and send with the requestmapperType- The object mapper type to be used- Returns:
- The request specification
-
addCookies
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
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 keyvalue- The cookie valuecookieNameValuePairs- Additional cookies values. This will actually create two cookies with the same name but with different values.- Returns:
- The request specification builder
-
addParams
- Parameters:
parametersMap- The Map containing the parameter names and their values to send with the request.- Returns:
- The request specification builder
-
addParam
- 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 keyparameterValues- The parameter values- Returns:
- The request specification builder
-
addQueryParam
public WebTestClientRequestSpecBuilder addQueryParam(String parameterName, Collection<?> parameterValues) - Parameters:
parameterName- The parameter keyparameterValues- The parameter values- Returns:
- The request specification builder
- See Also:
-
addQueryParams
- 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 keyparameterValues- Zero to many parameter values for this parameter name.- Returns:
- The request specification builder
-
addPathParam
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 keyparameterValue- 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 parameterfirstParameterValue- The value of the first parameterparameterNameValuePairs- Additional parameters in name-value pairs.- Returns:
- The request specification
-
addPathParams
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 keyparameterValues- The parameter values- Returns:
- The request specification builder
- See Also:
-
addFormParams
- 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 nameparameterValues- Zero to many parameter values for this parameter name.- Returns:
- The request specification builder
- See Also:
-
addAttribute
Add request attribute- Parameters:
attributeName- The attribute nameattributeValue- The attribute value- Returns:
- The request specification builder
-
addAttributes
Add request attributes- Parameters:
attributesMap- The Map containing the request attribute names and their values- Returns:
- The request specification builder
-
addHeaders
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
Add a header to be sent with the request- Parameters:
headerName- The header nameheaderValue- The header value- Returns:
- The request specification builder
-
addHeader
Add a header to be sent with the request.- Parameters:
header- The header- Returns:
- The request specification builder
-
setContentType
Specify the content type of the request.- Parameters:
contentType- The content type of the request- Returns:
- The request specification builder
- See Also:
-
ContentType
-
setContentType
Specify the content type of the request as string.- Parameters:
contentType- The content type of the request- Returns:
- The request specification builder
-
addMultiPart
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
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 uploadcontrolName- Defines the control name of the body part. In HTML this is the attribute name of the input tag.- Returns:
- The request specification
-
addMultiPart
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 uploadcontrolName- 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 uploadingbytes- 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 uploadingbytes- The bytes you want to sendmimeType- 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 uploadingstream- 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 uploadingstream- The stream you want to sendmimeType- The content-type- Returns:
- The request specification
-
addMultiPart
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 sendmimeType- The mime-type- Returns:
- The request specification
-
setSessionId
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 thesetSessionId(String, String)method to set it for this request only.- Parameters:
sessionIdValue- The session id value.- Returns:
- The request specification
-
setSessionId
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 thesetSessionId(String)method to set the session id value without specifying the name for each request.- Parameters:
sessionIdName- The session id namesessionIdValue- 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)
- 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. Ifnullno config will be used.- Returns:
- The request specification builder
-
build
Build the request specification.- Returns:
- The assembled request specification
-
setBasePath
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 anyWebTestClientinstances configured by other setters.*- Parameters:
webTestClient- The WebTestClient instance- Returns:
- WebTestClientRequestSpecBuilder
-
setStandaloneSetup
The standalone setup to be used by supplying a set of controllers. Note that this will override the anyWebTestClientinstances 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 theWebTestClientinstance. Note that this will override the anyWebTestClientinstances 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 aWebApplicationContextthat will be used to create theWebTestClientinstance. Note that this will override the anyWebTestClientinstances configured by other setters.- Parameters:
context- The WebApplicationContext to useWebTestClientConfigurers-WebTestClientConfigurer's to be applied when creating aWebTestClientinstance of this WebApplicationContext (optional)- Returns:
- WebTestClientRequestSpecBuilder
- See Also:
-
log
Enabled logging with the specified log detail. Set aLogConfigto 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
-