public class RestAssuredWebTestClient extends Object
RestAssured
. This is the starting point of the DSL.Modifier and Type | Field and Description |
---|---|
static String |
basePath
The base path that's used by REST assured when making requests.
|
static RestAssuredWebTestClientConfig |
config
Define a REST Assured WebTestClient configuration.
|
static WebTestClientRequestSpecification |
requestSpecification
Specify a default request specification that will be sent with each request.
|
static io.restassured.specification.ResponseSpecification |
responseSpecification
Specify a default response specification that will be sent with each request.
|
Constructor and Description |
---|
RestAssuredWebTestClient() |
Modifier and Type | Method and Description |
---|---|
static void |
applicationContextSetup(org.springframework.context.ApplicationContext context,
Object... configurersOrExchangeFilterFunctions)
Build a
WebTestClient using the given, fully initialized, i.e. |
static RestAssuredWebTestClientConfig |
config() |
static WebTestClientResponse |
delete()
Perform a DELETE request to the statically configured base path.
|
static WebTestClientResponse |
delete(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Perform a DELETE request to a path generated from the provided
Function uriFunction . |
static WebTestClientResponse |
delete(String path,
Map<String,?> pathParams)
Perform a DELETE request to a
path . |
static WebTestClientResponse |
delete(String path,
Object... pathParams)
Perform a DELETE request to a
path . |
static WebTestClientResponse |
delete(URI uri)
Perform a DELETE request to a
uri . |
static WebTestClientResponse |
delete(URL url)
Perform a DELETE request to a
url . |
static void |
enableLoggingOfRequestAndResponseIfValidationFails()
Enable logging of both the request and the response if REST Assured test validation fails with log detail equal to
LogDetail.ALL . |
static void |
enableLoggingOfRequestAndResponseIfValidationFails(io.restassured.filter.log.LogDetail logDetail)
Enable logging of both the request and the response if REST Assured test validation fails with the specified log detail.
|
static WebTestClientResponse |
get()
Perform a GET request to the statically configured base path.
|
static WebTestClientResponse |
get(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Perform a GET request to a path generated from the provided
Function uriFunction . |
static WebTestClientResponse |
get(String path,
Map<String,?> pathParams)
Perform a GET request to a
path . |
static WebTestClientResponse |
get(String path,
Object... pathParams)
Perform a GET request to a
path . |
static WebTestClientResponse |
get(URI uri)
Perform a GET request to a
uri . |
static WebTestClientResponse |
get(URL url)
Perform a GET request to a
url . |
static WebTestClientRequestSpecification |
given()
This is usually the entry-point of the API if you need to specify parameters or a body in the request.
|
static WebTestClientResponse |
head()
Perform a HEAD request to the statically configured base path.
|
static WebTestClientResponse |
head(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Perform a HEAD request to a path generated from the provided
Function uriFunction . |
static WebTestClientResponse |
head(String path,
Map<String,?> pathParams)
Perform a HEAD request to a
path . |
static WebTestClientResponse |
head(String path,
Object... pathParams)
Perform a HEAD request to a
path . |
static WebTestClientResponse |
head(URI uri)
Perform a HEAD request to a
uri . |
static WebTestClientResponse |
head(URL url)
Perform a HEAD request to a
url . |
static WebTestClientResponse |
options()
Perform a OPTIONS request to the statically configured base path.
|
static WebTestClientResponse |
options(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Perform a OPTIONS request to a path generated from the provided
Function uriFunction . |
static WebTestClientResponse |
options(String path,
Map<String,?> pathParams)
Perform a OPTIONS request to a
path . |
static WebTestClientResponse |
options(String path,
Object... pathParams)
Perform a OPTIONS request to a
path . |
static WebTestClientResponse |
options(URI uri)
Perform a OPTIONS request to a
uri . |
static WebTestClientResponse |
options(URL url)
Perform a OPTIONS request to a
url . |
static WebTestClientResponse |
patch()
Perform a PATCH request to the statically configured base path.
|
static WebTestClientResponse |
patch(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Perform a PATCH request to a path generated from the provided
Function uriFunction . |
static WebTestClientResponse |
patch(String path,
Map<String,?> pathParams)
Perform a PATCH request to a
path . |
static WebTestClientResponse |
patch(String path,
Object... pathParams)
Perform a PATCH request to a
path . |
static WebTestClientResponse |
patch(URI uri)
Perform a PATCH request to a
uri . |
static WebTestClientResponse |
patch(URL url)
Perform a PATCH request to a
url . |
static WebTestClientResponse |
post()
Perform a POST request to the statically configured base path.
|
static WebTestClientResponse |
post(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Perform a POST request to a path generated from the provided
Function uriFunction . |
static WebTestClientResponse |
post(String path,
Map<String,?> pathParams)
Perform a POST request to a
path . |
static WebTestClientResponse |
post(String path,
Object... pathParams)
Perform a POST request to a
path . |
static WebTestClientResponse |
post(URI uri)
Perform a POST request to a
uri . |
static WebTestClientResponse |
post(URL url)
Perform a POST request to a
url . |
static WebTestClientResponse |
put()
Perform a PUT request to the statically configured base path.
|
static WebTestClientResponse |
put(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Perform a PUT request to a path generated from the provided
Function uriFunction . |
static WebTestClientResponse |
put(String path,
Map<String,?> pathParams) |
static WebTestClientResponse |
put(String path,
Object... pathParams)
Perform a PUT request to a
path . |
static WebTestClientResponse |
put(URI uri)
Perform a PUT request to a
uri . |
static WebTestClientResponse |
put(URL url) |
static WebTestClientResponse |
request(io.restassured.http.Method method)
Perform a request to the pre-configured path (by default
http://localhost:8080 ). |
static WebTestClientResponse |
request(io.restassured.http.Method method,
java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Perform a request to a path generated from the provided
Function uriFunction . |
static WebTestClientResponse |
request(io.restassured.http.Method method,
String path,
Object... pathParams)
Perform a HTTP request to a
path . |
static WebTestClientResponse |
request(io.restassured.http.Method method,
URI uri)
Perform a request to a
uri . |
static WebTestClientResponse |
request(io.restassured.http.Method method,
URL url)
Perform a request to a
url . |
static WebTestClientResponse |
request(String method)
Perform a custom HTTP request to the pre-configured path (by default
http://localhost:8080 ). |
static WebTestClientResponse |
request(String method,
java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Perform a request to a path generated from the provided
Function uriFunction . |
static WebTestClientResponse |
request(String method,
String path,
Object... pathParams)
Perform a custom HTTP request to a
path . |
static WebTestClientResponse |
request(String method,
URI uri)
Perform a custom HTTP request to a
uri . |
static WebTestClientResponse |
request(String method,
URL url)
Perform a custom HTTP request to a
url . |
static void |
reset()
Reset all static configurations to their default values.
|
static void |
standaloneSetup(Object... controllersOrConfigurersOrExchangeFilterFunctions)
Build a
WebTestClient by registering one or more @Controller 's
instances and configuring WebTestClient programmatically. |
static void |
standaloneSetup(org.springframework.web.reactive.function.server.RouterFunction routerFunction,
Object... configurersOrExchangeFilterFunctions)
Build a
WebTestClient by using a provided RouterFunction
for configuring WebTestClient programmatically. |
static void |
standaloneSetup(org.springframework.test.web.reactive.server.WebTestClient.Builder builder)
Build a
WebTestClient by using a provided WebTestClient.Builder
for configuring WebTestClient programmatically. |
static void |
webAppContextSetup(org.springframework.web.context.WebApplicationContext context,
Object... configurersOrExchangeFilterFunctions)
Build a
WebTestClient using the given, fully initialized, i.e. |
static void |
webTestClient(org.springframework.test.web.reactive.server.WebTestClient webTestClient)
Set a
WebTestClient instance that REST Assured will use when making requests unless overwritten
by a WebTestClientRequestSpecification . |
WebTestClientRequestSender |
when()
This is usually the entry-point of the API if you need to specify parameters or a body in the request.
|
static WebTestClientRequestSpecification |
with()
This is usually the entry-point of the API if you need to specify parameters or a body in the request.
|
public static RestAssuredWebTestClientConfig config
given().config(newConfig().logConfig(new LogConfig(captor, true))). ..
newConfig()
can be statically imported from RestAssuredWebTestClientConfig
.public static WebTestClientRequestSpecification requestSpecification
RestAssuredWebTestClient.requestSpecification = new WebTestClientRequestSpecBuilder().addParam("parameter1", "value1").build();means that for each request by Rest Assured "parameter1" will be equal to "value1".
public static io.restassured.specification.ResponseSpecification responseSpecification
RestAssuredWebTestClient.responseSpecification = new ResponseSpecBuilder().expectStatusCode(200).build();means that for each response Rest Assured will assert that the status code is equal to 200.
public static String basePath
/
.public static void webTestClient(org.springframework.test.web.reactive.server.WebTestClient webTestClient)
WebTestClient
instance that REST Assured will use when making requests unless overwritten
by a WebTestClientRequestSpecification
.webTestClient
- The WebTestClient instance to use.public static WebTestClientRequestSpecification given()
given(). param("x", "y"). when(). get("/something"). then(). statusCode(200). body("x.y", notNullValue());Note that this method is the same as
with()
but with another syntax.WebTestClientRequestSpecification
.public static WebTestClientRequestSpecification with()
given()
but with another syntax.WebTestClientRequestSpecification
.public static void standaloneSetup(Object... controllersOrConfigurersOrExchangeFilterFunctions)
WebTestClient
by registering one or more @Controller
's
instances and configuring WebTestClient programmatically.
This allows full control over the instantiation, configuration and initialization of
controllers, and their dependencies, similar to plain unit tests while
also making it possible to test one controller at a time.
It uses WebTestClient.bindToController(Object...)
under the hood.
It also allows you to pass WebTestClientConfigurer
and ExchangeFilterFunction
instances that are used to set up the WebTestClient
instance.
controllersOrConfigurersOrExchangeFilterFunctions
- one or more @Controller
s to test,
as well as WebTestClientConfigurer
s
and ExchangeFilterFunction
s to apply.public static void standaloneSetup(org.springframework.web.reactive.function.server.RouterFunction routerFunction, Object... configurersOrExchangeFilterFunctions)
WebTestClient
by using a provided RouterFunction
for configuring WebTestClient programmatically.
This allows full control over the instantiation, configuration and initialization of
router functions, and their dependencies, similar to plain unit tests while
also making it possible to test one router function at a time.
It uses
WebTestClient.bindToRouterFunction(RouterFunction)
under the hood.
It also allows you to pass WebTestClientConfigurer
and ExchangeFilterFunction
instances that are used to set up the WebTestClient
instance
routerFunction
- RouterFunction
to build WebTestClient.configurersOrExchangeFilterFunctions
- WebTestClientConfigurer
s and ExchangeFilterFunction
s to apply.public static void standaloneSetup(org.springframework.test.web.reactive.server.WebTestClient.Builder builder)
WebTestClient
by using a provided WebTestClient.Builder
for configuring WebTestClient 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.builder
- WebTestClient.Builder
to build WebTestClient.public static void webAppContextSetup(org.springframework.web.context.WebApplicationContext context, Object... configurersOrExchangeFilterFunctions)
WebTestClient
using the given, fully initialized, i.e.
refreshed, WebApplicationContext
and assign it to REST Assured.
The passed WebApplicationContext
will be used as ApplicationContext
.
context
- The web application context to useconfigurersOrExchangeFilterFunctions
- WebTestClientConfigurer
s and ExchangeFilterFunction
s to apply.public static void applicationContextSetup(org.springframework.context.ApplicationContext context, Object... configurersOrExchangeFilterFunctions)
WebTestClient
using the given, fully initialized, i.e.
refreshed, ApplicationContext
and assign it to REST Assured.context
- The application context to useconfigurersOrExchangeFilterFunctions
- WebTestClientConfigurer
s and ExchangeFilterFunction
s to apply.public static void reset()
public static WebTestClientResponse get(String path, Object... pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.path
- The path to send the request to.pathParams
- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do get("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);
.public static WebTestClientResponse get(String path, Map<String,?> pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.path
- The path to send the request to.pathParams
- The path parameters.public static WebTestClientResponse get(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Function
uriFunction
.uriFunction
- The Function<UriBuilder, URI>
used to generate the path to send the request to.public static WebTestClientResponse post(String path, Object... pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.path
- The path to send the request to.pathParams
- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do post("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);
.public static WebTestClientResponse get(URI uri)
uri
.uri
- The uri to send the request to.public static WebTestClientResponse get(URL url)
url
.url
- The url to send the request to.public static WebTestClientResponse get()
public static WebTestClientResponse request(io.restassured.http.Method method)
http://localhost:8080
).method
- The HTTP method to usepublic static WebTestClientResponse request(String method)
http://localhost:8080
).method
- The HTTP method to usepublic static WebTestClientResponse request(io.restassured.http.Method method, String path, Object... pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.method
- The HTTP method to usepath
- The path to send the request to.pathParams
- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do request(Method.TRACE,"/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);
.public static WebTestClientResponse request(String method, String path, Object... pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.method
- The HTTP method to usepath
- The path to send the request to.pathParams
- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do request("method","/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);
.public static WebTestClientResponse request(io.restassured.http.Method method, URI uri)
uri
.method
- The HTTP method to useuri
- The uri to send the request to.public static WebTestClientResponse request(io.restassured.http.Method method, java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Function
uriFunction
.method
- The HTTP method to useuriFunction
- The Function<UriBuilder, URI>
used to generate the path to send the request to.public static WebTestClientResponse request(io.restassured.http.Method method, URL url)
url
.method
- The HTTP method to useurl
- The url to send the request to.public static WebTestClientResponse request(String method, URI uri)
uri
.method
- The HTTP method to useuri
- The uri to send the request to.public static WebTestClientResponse request(String method, java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Function
uriFunction
.method
- The HTTP method to useuriFunction
- The Function<UriBuilder, URI>
used to generate the path to send the request to.public static WebTestClientResponse request(String method, URL url)
url
.method
- The HTTP method to useurl
- The url to send the request to.public static WebTestClientResponse post(String path, Map<String,?> pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.path
- The path to send the request to.pathParams
- The path parameters.public static WebTestClientResponse put(String path, Object... pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.path
- The path to send the request to.pathParams
- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do put("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);
.public static WebTestClientResponse post(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Function
uriFunction
.uriFunction
- The Function<UriBuilder, URI>
used to generate the path to send the request to.public static WebTestClientResponse post(URI uri)
uri
.uri
- The uri to send the request to.public static WebTestClientResponse post(URL url)
url
.url
- The url to send the request to.public static WebTestClientResponse post()
public static WebTestClientResponse delete(String path, Object... pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.path
- The path to send the request to.pathParams
- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do delete("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);
.public static WebTestClientResponse put(String path, Map<String,?> pathParams)
public static WebTestClientResponse put(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Function
uriFunction
.uriFunction
- The Function<UriBuilder, URI>
used to generate the path to send the request to.public static WebTestClientResponse put(URI uri)
uri
.uri
- The uri to send the request to.public static WebTestClientResponse put(URL url)
public static WebTestClientResponse put()
public static WebTestClientResponse delete(String path, Map<String,?> pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.path
- The path to send the request to.pathParams
- The path parameters.public static WebTestClientResponse head(String path, Object... pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.path
- The path to send the request to.pathParams
- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do head("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);
.public static WebTestClientResponse delete(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Function
uriFunction
.uriFunction
- The Function<UriBuilder, URI>
used to generate the path to send the request to.public static WebTestClientResponse delete(URI uri)
uri
.uri
- The uri to send the request to.public static WebTestClientResponse delete(URL url)
url
.url
- The url to send the request to.public static WebTestClientResponse delete()
public static WebTestClientResponse head(String path, Map<String,?> pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.path
- The path to send the request to.pathParams
- The path parameters.public static WebTestClientResponse patch(String path, Object... pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.path
- The path to send the request to.pathParams
- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do head("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);
.public static WebTestClientResponse head(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Function
uriFunction
.uriFunction
- The Function<UriBuilder, URI>
used to generate the path to send the request to.public static WebTestClientResponse head(URI uri)
uri
.uri
- The uri to send the request to.public static WebTestClientResponse head(URL url)
url
.url
- The url to send the request to.public static WebTestClientResponse head()
public static WebTestClientResponse patch(String path, Map<String,?> pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.path
- The path to send the request to.pathParams
- The path parameters.public static WebTestClientResponse patch(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Function
uriFunction
.uriFunction
- The Function<UriBuilder, URI>
used to generate the path to send the request to.public static WebTestClientResponse patch(URI uri)
uri
.uri
- The uri to send the request to.public static WebTestClientResponse patch(URL url)
url
.url
- The url to send the request to.public static WebTestClientResponse patch()
public static WebTestClientResponse options(String path, Object... pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.path
- The path to send the request to.pathParams
- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do head("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);
.public static WebTestClientResponse options(String path, Map<String,?> pathParams)
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.path
- The path to send the request to.pathParams
- The path parameters.public static WebTestClientResponse options(java.util.function.Function<org.springframework.web.util.UriBuilder,URI> uriFunction)
Function
uriFunction
.uriFunction
- The Function<UriBuilder, URI>
used to generate the path to send the request to.public static WebTestClientResponse options(URI uri)
uri
.uri
- The uri to send the request to.public static WebTestClientResponse options(URL url)
url
.url
- The url to send the request to.public static WebTestClientResponse options()
public static void enableLoggingOfRequestAndResponseIfValidationFails()
LogDetail.ALL
.
This is just a shortcut for:
RestAssuredWebTestClient.config = new RestAssuredWebTestClientConfig().logConfig(logConfig().enableLoggingOfRequestAndResponseIfValidationFails());
public static void enableLoggingOfRequestAndResponseIfValidationFails(io.restassured.filter.log.LogDetail logDetail)
This is just a shortcut for:
RestAssured.config = new RestAssuredWebTestClientConfig().logConfig(logConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail));
logDetail
- The log detail to show in the logpublic WebTestClientRequestSender when()
when(). get("/x"). then(). body("x.y.z1", equalTo("Z1")). body("x.y.z2", equalTo("Z2"));
Note that if you need to add parameters, headers, cookies or other request properties use the given()
method.
public static RestAssuredWebTestClientConfig config()
Copyright © 2010–2022. All rights reserved.