public class WebTestClientRequestSpecBuilder extends Object
| Constructor and Description |
|---|
WebTestClientRequestSpecBuilder() |
| Modifier and Type | Method and Description |
|---|---|
WebTestClientRequestSpecBuilder |
addAttribute(String attributeName,
Object attributeValue)
Add request attribute
|
WebTestClientRequestSpecBuilder |
addAttributes(Map<String,?> attributesMap)
Add request attributes
|
WebTestClientRequestSpecBuilder |
addCookie(io.restassured.http.Cookie cookie)
Add a detailed cookie
|
WebTestClientRequestSpecBuilder |
addCookie(String key,
Object value,
Object... cookieNameValuePairs)
Add a cookie to be sent with the request.
|
WebTestClientRequestSpecBuilder |
addCookies(Map<String,?> cookies)
Add cookies to be sent with the request as Map e.g:
|
WebTestClientRequestSpecBuilder |
addFormParam(String parameterName,
Collection<?> parameterValues) |
WebTestClientRequestSpecBuilder |
addFormParam(String parameterName,
Object... parameterValues) |
WebTestClientRequestSpecBuilder |
addFormParams(Map<String,?> parametersMap) |
WebTestClientRequestSpecBuilder |
addHeader(io.restassured.http.Header header)
Add a header to be sent with the request.
|
WebTestClientRequestSpecBuilder |
addHeader(String headerName,
String headerValue)
Add a header to be sent with the request
|
WebTestClientRequestSpecBuilder |
addHeaders(Map<String,String> headers)
Add headers to be sent with the request as Map.
|
WebTestClientRequestSpecBuilder |
addMultiPart(File file)
Specify a file to upload to the server using multi-part form data uploading.
|
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.
|
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.
|
WebTestClientRequestSpecBuilder |
addMultiPart(String controlName,
String contentBody)
Specify a string to send to the server using multi-part form data.
|
WebTestClientRequestSpecBuilder |
addMultiPart(String controlName,
String fileName,
byte[] bytes)
Specify a byte-array to upload to the server using multi-part form data.
|
WebTestClientRequestSpecBuilder |
addMultiPart(String controlName,
String fileName,
byte[] bytes,
String mimeType)
Specify a byte-array to upload to the server using multi-part form data.
|
WebTestClientRequestSpecBuilder |
addMultiPart(String controlName,
String fileName,
InputStream stream)
Specify an inputstream to upload to the server using multi-part form data.
|
WebTestClientRequestSpecBuilder |
addMultiPart(String controlName,
String fileName,
InputStream stream,
String mimeType)
Specify an inputstream to upload to the server using multi-part form data.
|
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.
|
WebTestClientRequestSpecBuilder |
addParam(String parameterName,
Collection<?> parameterValues) |
WebTestClientRequestSpecBuilder |
addParam(String parameterName,
Object... parameterValues) |
WebTestClientRequestSpecBuilder |
addParams(Map<String,?> parametersMap) |
WebTestClientRequestSpecBuilder |
addPathParam(String parameterName,
Object parameterValue)
Specify a path parameter.
|
WebTestClientRequestSpecBuilder |
addPathParams(Map<String,Object> parameterNameValuePairs)
Specify multiple path parameter name-value pairs.
|
WebTestClientRequestSpecBuilder |
addPathParams(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
Specify multiple path parameter name-value pairs.
|
WebTestClientRequestSpecBuilder |
addQueryParam(String parameterName,
Collection<?> parameterValues) |
WebTestClientRequestSpecBuilder |
addQueryParam(String parameterName,
Object... parameterValues) |
WebTestClientRequestSpecBuilder |
addQueryParams(Map<String,?> parametersMap) |
WebTestClientRequestSpecBuilder |
addWebTestClientRequestSpecification(WebTestClientRequestSpecification specification)
Merge this builder with settings from another specification.
|
WebTestClientRequestSpecBuilder |
and()
Returns the same WebTestClientRequestSpecBuilder instance for syntactic sugar.
|
WebTestClientRequestSpecification |
build()
Build the request specification.
|
WebTestClientRequestSpecBuilder |
log(io.restassured.filter.log.LogDetail logDetail)
Enabled logging with the specified log detail.
|
WebTestClientRequestSpecBuilder |
setBasePath(String basePath)
Set the basePath property of the WebTestClientRequestSpecBuilder instead of using static field RestAssuredWebTestClient.basePath.
|
WebTestClientRequestSpecBuilder |
setBody(byte[] body)
Specify a byte array request body to be sent with the request.
|
WebTestClientRequestSpecBuilder |
setBody(Object object)
Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request.
|
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.
|
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.
|
WebTestClientRequestSpecBuilder |
setBody(String body)
Specify a String request body (such as e.g.
|
WebTestClientRequestSpecBuilder |
setConfig(RestAssuredWebTestClientConfig config)
Define a configuration for redirection settings and http client parameters.
|
WebTestClientRequestSpecBuilder |
setContentType(io.restassured.http.ContentType contentType)
Specify the content type of the request.
|
WebTestClientRequestSpecBuilder |
setContentType(String contentType)
Specify the content type of the request as string.
|
WebTestClientRequestSpecBuilder |
setSessionId(String sessionIdValue)
Set the session id for this request.
|
WebTestClientRequestSpecBuilder |
setSessionId(String sessionIdName,
String sessionIdValue)
Set the session id name and value for this request.
|
WebTestClientRequestSpecBuilder |
setStandaloneSetup(Object... controllers)
The standalone setup to be used by supplying a set of controllers.
|
WebTestClientRequestSpecBuilder |
setStandaloneSetup(org.springframework.test.web.reactive.server.WebTestClient.Builder builder)
Initialize with a WebTestClientBuilder that will be used to create the
WebTestClient instance. |
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. |
WebTestClientRequestSpecBuilder |
setWebTestClient(org.springframework.test.web.reactive.server.WebTestClient webTestClient)
The webTestClient instance to use.
|
public WebTestClientRequestSpecBuilder setBody(String body)
body - The body to send.public WebTestClientRequestSpecBuilder setBody(byte[] body)
body - The body to send.public WebTestClientRequestSpecBuilder setBody(Object object)
object - The object to serialize and send with the requestpublic WebTestClientRequestSpecBuilder setBody(Object object, io.restassured.mapper.ObjectMapper mapper)
Note that setBody(Object, ObjectMapperType)
are the same except for the syntactic difference.
object - The object to serialize and send with the requestmapper - The object mapperpublic WebTestClientRequestSpecBuilder setBody(Object object, io.restassured.mapper.ObjectMapperType mapperType)
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.
object - The object to serialize and send with the requestmapperType - The object mapper type to be usedpublic WebTestClientRequestSpecBuilder addCookies(Map<String,?> cookies)
cookies - The Map containing the cookie names and their values to set in the request.public WebTestClientRequestSpecBuilder addCookie(io.restassured.http.Cookie cookie)
cookie - The cookie to add.public WebTestClientRequestSpecBuilder addCookie(String key, Object value, Object... cookieNameValuePairs)
key - The cookie keyvalue - The cookie valuecookieNameValuePairs - Additional cookies values. This will actually create two cookies with the same name but with different values.public WebTestClientRequestSpecBuilder addParams(Map<String,?> parametersMap)
parametersMap - The Map containing the parameter names and their values to send with the request.public WebTestClientRequestSpecBuilder addParam(String parameterName, Object... parameterValues)
parameterValues - Zero to many parameter values for this parameter name.public WebTestClientRequestSpecBuilder addParam(String parameterName, Collection<?> parameterValues)
parameterName - The parameter keyparameterValues - The parameter valuespublic WebTestClientRequestSpecBuilder addQueryParam(String parameterName, Collection<?> parameterValues)
parameterName - The parameter keyparameterValues - The parameter valuesaddQueryParam(String, Object...)public WebTestClientRequestSpecBuilder addQueryParams(Map<String,?> parametersMap)
parametersMap - The Map containing the parameter names and their values to send with the request.public WebTestClientRequestSpecBuilder addQueryParam(String parameterName, Object... parameterValues)
parameterName - The parameter keyparameterValues - Zero to many parameter values for this parameter name.public WebTestClientRequestSpecBuilder addPathParam(String parameterName, Object parameterValue)
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);
parameterName - The parameter keyparameterValue - The parameter valuepublic WebTestClientRequestSpecBuilder addPathParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
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);
firstParameterName - The name of the first parameterfirstParameterValue - The value of the first parameterparameterNameValuePairs - Additional parameters in name-value pairs.public WebTestClientRequestSpecBuilder addPathParams(Map<String,Object> parameterNameValuePairs)
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);
parameterNameValuePairs - A map containing the path parameters.public WebTestClientRequestSpecBuilder addFormParam(String parameterName, Collection<?> parameterValues)
parameterName - The parameter keyparameterValues - The parameter valuesaddFormParam(String, Object...)public WebTestClientRequestSpecBuilder addFormParams(Map<String,?> parametersMap)
parametersMap - The Map containing the parameter names and their values to send with the request.public WebTestClientRequestSpecBuilder addFormParam(String parameterName, Object... parameterValues)
parameterName - The parameter nameparameterValues - Zero to many parameter values for this parameter name.addFormParam(String, Object...)public WebTestClientRequestSpecBuilder addAttribute(String attributeName, Object attributeValue)
attributeName - The attribute nameattributeValue - The attribute valuepublic WebTestClientRequestSpecBuilder addAttributes(Map<String,?> attributesMap)
attributesMap - The Map containing the request attribute names and their valuespublic WebTestClientRequestSpecBuilder addHeaders(Map<String,String> headers)
headers - The Map containing the header names and their values to send with the request.public WebTestClientRequestSpecBuilder addHeader(String headerName, String headerValue)
headerName - The header nameheaderValue - The header valuepublic WebTestClientRequestSpecBuilder addHeader(io.restassured.http.Header header)
header - The headerpublic WebTestClientRequestSpecBuilder setContentType(io.restassured.http.ContentType contentType)
contentType - The content type of the requestContentTypepublic WebTestClientRequestSpecBuilder setContentType(String contentType)
contentType - The content type of the requestpublic WebTestClientRequestSpecBuilder addMultiPart(File file)
file - The file to uploadpublic WebTestClientRequestSpecBuilder addMultiPart(String controlName, File file)
file - The file to uploadcontrolName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.public WebTestClientRequestSpecBuilder addMultiPart(String controlName, File file, String mimeType)
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-typepublic WebTestClientRequestSpecBuilder addMultiPart(String controlName, String fileName, byte[] bytes)
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 sendpublic WebTestClientRequestSpecBuilder addMultiPart(String controlName, String fileName, byte[] bytes, String mimeType)
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-typepublic WebTestClientRequestSpecBuilder addMultiPart(String controlName, String fileName, InputStream stream)
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 sendpublic WebTestClientRequestSpecBuilder addMultiPart(String controlName, String fileName, InputStream stream, String mimeType)
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-typepublic WebTestClientRequestSpecBuilder addMultiPart(String controlName, String contentBody)
controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.contentBody - The string to sendpublic WebTestClientRequestSpecBuilder addMultiPart(String controlName, String contentBody, String mimeType)
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-typepublic WebTestClientRequestSpecBuilder setSessionId(String sessionIdValue)
RestAssuredWebTestClient.config = newConfig().sessionConfig(new SessionConfig().sessionIdName(<sessionIdName>));
or you can use the setSessionId(String, String) method to set it for this request only.sessionIdValue - The session id value.public WebTestClientRequestSpecBuilder setSessionId(String sessionIdName, String sessionIdValue)
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.sessionIdName - The session id namesessionIdValue - The session id value.public WebTestClientRequestSpecBuilder addWebTestClientRequestSpecification(WebTestClientRequestSpecification specification)
specification - The specification to addpublic WebTestClientRequestSpecBuilder setConfig(RestAssuredWebTestClientConfig config)
config - The configuration to use for this request. If null no config will be used.public WebTestClientRequestSpecification build()
public WebTestClientRequestSpecBuilder setBasePath(String basePath)
WebTestClientRequestSpecBuilder builder = new WebTestClientRequestSpecBuilder();
builder.setBasePath("/something");
WebTestClientRequestSpecification specs = builder.build();
given().spec(specs)
basePath - public WebTestClientRequestSpecBuilder setWebTestClient(org.springframework.test.web.reactive.server.WebTestClient webTestClient)
WebTestClient instances configured by other setters.*webTestClient - The WebTestClient instancepublic WebTestClientRequestSpecBuilder setStandaloneSetup(Object... controllers)
WebTestClient instances configured by other setters.controllers - The controllers to useWebTestClientRequestSpecification.standaloneSetup(Object...)public WebTestClientRequestSpecBuilder setStandaloneSetup(org.springframework.test.web.reactive.server.WebTestClient.Builder builder)
WebTestClient instance.
Note that this will override the any WebTestClient instances configured by other setters.builder - The builder to useWebTestClientRequestSpecification.standaloneSetup(WebTestClient.Builder)public WebTestClientRequestSpecBuilder setWebAppContextSetup(org.springframework.web.context.WebApplicationContext context, org.springframework.test.web.reactive.server.WebTestClientConfigurer... WebTestClientConfigurers)
WebApplicationContext that will be used to create the WebTestClient instance.
Note that this will override the any WebTestClient instances configured by other setters.context - The WebApplicationContext to useWebTestClientConfigurers - WebTestClientConfigurer's to be applied when creating a WebTestClient instance of this WebApplicationContext (optional)WebTestClientRequestSpecification.webAppContextSetup(WebApplicationContext, WebTestClientConfigurer...)public WebTestClientRequestSpecBuilder log(io.restassured.filter.log.LogDetail logDetail)
LogConfig to configure the print stream and pretty printing options.logDetail - The log detail.public WebTestClientRequestSpecBuilder and()
Copyright © 2010–2025. All rights reserved.