Class RestAssuredWebTestClient
java.lang.Object
io.restassured.module.webtestclient.RestAssuredWebTestClient
The Spring Web Test Client module's equivalent of
RestAssured. This is the starting point of the DSL.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic StringThe base path that's used by REST assured when making requests.Define a REST Assured WebTestClient configuration.Specify a default request specification that will be sent with each request.static io.restassured.specification.ResponseSpecificationSpecify a default response specification that will be sent with each request. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplicationContextSetup(org.springframework.context.ApplicationContext context, Object... configurersOrExchangeFilterFunctions) Build aWebTestClientusing the given, fully initialized, i.e.config()static WebTestClientResponsedelete()Perform a DELETE request to the statically configured base path.static WebTestClientResponsePerform a DELETE request to apath.static WebTestClientResponsePerform a DELETE request to apath.static WebTestClientResponsePerform a DELETE request to auri.static WebTestClientResponsePerform a DELETE request to aurl.static WebTestClientResponsePerform a DELETE request to a path generated from the providedFunctionuriFunction.static voidEnable logging of both the request and the response if REST Assured test validation fails with log detail equal toLogDetail.ALL.static voidenableLoggingOfRequestAndResponseIfValidationFails(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 WebTestClientResponseget()Perform a GET request to the statically configured base path.static WebTestClientResponsePerform a GET request to apath.static WebTestClientResponsePerform a GET request to apath.static WebTestClientResponsePerform a GET request to auri.static WebTestClientResponsePerform a GET request to aurl.static WebTestClientResponsePerform a GET request to a path generated from the providedFunctionuriFunction.given()This is usually the entry-point of the API if you need to specify parameters or a body in the request.static WebTestClientResponsehead()Perform a HEAD request to the statically configured base path.static WebTestClientResponsePerform a HEAD request to apath.static WebTestClientResponsePerform a HEAD request to apath.static WebTestClientResponsePerform a HEAD request to auri.static WebTestClientResponsePerform a HEAD request to aurl.static WebTestClientResponsePerform a HEAD request to a path generated from the providedFunctionuriFunction.static WebTestClientResponseoptions()Perform a OPTIONS request to the statically configured base path.static WebTestClientResponsePerform a OPTIONS request to apath.static WebTestClientResponsePerform a OPTIONS request to apath.static WebTestClientResponsePerform a OPTIONS request to auri.static WebTestClientResponsePerform a OPTIONS request to aurl.static WebTestClientResponsePerform a OPTIONS request to a path generated from the providedFunctionuriFunction.static WebTestClientResponsepatch()Perform a PATCH request to the statically configured base path.static WebTestClientResponsePerform a PATCH request to apath.static WebTestClientResponsePerform a PATCH request to apath.static WebTestClientResponsePerform a PATCH request to auri.static WebTestClientResponsePerform a PATCH request to aurl.static WebTestClientResponsePerform a PATCH request to a path generated from the providedFunctionuriFunction.static WebTestClientResponsepost()Perform a POST request to the statically configured base path.static WebTestClientResponsePerform a POST request to apath.static WebTestClientResponsePerform a POST request to apath.static WebTestClientResponsePerform a POST request to auri.static WebTestClientResponsePerform a POST request to aurl.static WebTestClientResponsePerform a POST request to a path generated from the providedFunctionuriFunction.static WebTestClientResponseput()Perform a PUT request to the statically configured base path.static WebTestClientResponsePerform a PUT request to apath.static WebTestClientResponsestatic WebTestClientResponsePerform a PUT request to auri.static WebTestClientResponsestatic WebTestClientResponsePerform a PUT request to a path generated from the providedFunctionuriFunction.static WebTestClientResponserequest(io.restassured.http.Method method) Perform a request to the pre-configured path (by defaulthttp://localhost:8080).static WebTestClientResponsePerform a HTTP request to apath.static WebTestClientResponsePerform a request to auri.static WebTestClientResponsePerform a request to aurl.static WebTestClientResponserequest(io.restassured.http.Method method, Function<org.springframework.web.util.UriBuilder, URI> uriFunction) Perform a request to a path generated from the providedFunctionuriFunction.static WebTestClientResponsePerform a custom HTTP request to the pre-configured path (by defaulthttp://localhost:8080).static WebTestClientResponsePerform a custom HTTP request to apath.static WebTestClientResponsePerform a custom HTTP request to auri.static WebTestClientResponsePerform a custom HTTP request to aurl.static WebTestClientResponsePerform a request to a path generated from the providedFunctionuriFunction.static voidreset()Reset all static configurations to their default values.static voidstandaloneSetup(Object... controllersOrConfigurersOrExchangeFilterFunctions) Build aWebTestClientby registering one or more@Controller's instances and configuring WebTestClient programmatically.static voidstandaloneSetup(org.springframework.test.web.reactive.server.WebTestClient.Builder builder) Build aWebTestClientby using a providedWebTestClient.Builderfor configuring WebTestClient programmatically.static voidstandaloneSetup(org.springframework.web.reactive.function.server.RouterFunction routerFunction, Object... configurersOrExchangeFilterFunctions) Build aWebTestClientby using a providedRouterFunctionfor configuring WebTestClient programmatically.static voidwebAppContextSetup(org.springframework.web.context.WebApplicationContext context, Object... configurersOrExchangeFilterFunctions) Build aWebTestClientusing the given, fully initialized, i.e.static voidwebTestClient(org.springframework.test.web.reactive.server.WebTestClient webTestClient) Set aWebTestClientinstance that REST Assured will use when making requests unless overwritten by aWebTestClientRequestSpecification.when()This is usually the entry-point of the API if you need to specify parameters or a body in the request.with()This is usually the entry-point of the API if you need to specify parameters or a body in the request.
-
Field Details
-
config
Define a REST Assured WebTestClient configuration. E.g.given().config(newConfig().logConfig(new LogConfig(captor, true))). ..
newConfig()can be statically imported fromRestAssuredWebTestClientConfig. -
requestSpecification
Specify a default request specification that will be sent with each request. E,g.RestAssuredWebTestClient.requestSpecification = new WebTestClientRequestSpecBuilder().addParam("parameter1", "value1").build();means that for each request by Rest Assured "parameter1" will be equal to "value1". -
responseSpecification
public static io.restassured.specification.ResponseSpecification responseSpecificationSpecify a default response specification that will be sent with each request. E,g.RestAssuredWebTestClient.responseSpecification = new ResponseSpecBuilder().expectStatusCode(200).build();
means that for each response Rest Assured will assert that the status code is equal to 200. -
basePath
The base path that's used by REST assured when making requests. The base path is prepended to the request path. Default value is/.
-
-
Constructor Details
-
RestAssuredWebTestClient
public RestAssuredWebTestClient()
-
-
Method Details
-
webTestClient
public static void webTestClient(org.springframework.test.web.reactive.server.WebTestClient webTestClient) Set aWebTestClientinstance that REST Assured will use when making requests unless overwritten by aWebTestClientRequestSpecification.- Parameters:
webTestClient- The WebTestClient instance to use.
-
given
This is usually the entry-point of the API if you need to specify parameters or a body in the request. For example:given(). param("x", "y"). when(). get("/something"). then(). statusCode(200). body("x.y", notNullValue());Note that this method is the same aswith()but with another syntax.- Returns:
- a
WebTestClientRequestSpecification.
-
with
This is usually the entry-point of the API if you need to specify parameters or a body in the request. For example: Note that this method is the same asgiven()but with another syntax.- Returns:
- A
WebTestClientRequestSpecification.
-
standaloneSetup
Build aWebTestClientby 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 passWebTestClientConfigurerandExchangeFilterFunctioninstances that are used to set up theWebTestClientinstance.- Parameters:
controllersOrConfigurersOrExchangeFilterFunctions- one or more@Controllers to test, as well asWebTestClientConfigurers andExchangeFilterFunctions to apply.
-
standaloneSetup
public static void standaloneSetup(org.springframework.web.reactive.function.server.RouterFunction routerFunction, Object... configurersOrExchangeFilterFunctions) Build aWebTestClientby using a providedRouterFunctionfor 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 usesWebTestClient.bindToRouterFunction(RouterFunction)under the hood. It also allows you to passWebTestClientConfigurerandExchangeFilterFunctioninstances that are used to set up theWebTestClientinstance- Parameters:
routerFunction-RouterFunctionto build WebTestClient.configurersOrExchangeFilterFunctions-WebTestClientConfigurers andExchangeFilterFunctions to apply.
-
standaloneSetup
public static void standaloneSetup(org.springframework.test.web.reactive.server.WebTestClient.Builder builder) Build aWebTestClientby using a providedWebTestClient.Builderfor 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.- Parameters:
builder-WebTestClient.Builderto build WebTestClient.
-
webAppContextSetup
public static void webAppContextSetup(org.springframework.web.context.WebApplicationContext context, Object... configurersOrExchangeFilterFunctions) Build aWebTestClientusing the given, fully initialized, i.e. refreshed,WebApplicationContextand assign it to REST Assured.The passed
WebApplicationContextwill be used asApplicationContext.- Parameters:
context- The web application context to useconfigurersOrExchangeFilterFunctions-WebTestClientConfigurers andExchangeFilterFunctions to apply.
-
applicationContextSetup
public static void applicationContextSetup(org.springframework.context.ApplicationContext context, Object... configurersOrExchangeFilterFunctions) Build aWebTestClientusing the given, fully initialized, i.e. refreshed,ApplicationContextand assign it to REST Assured.- Parameters:
context- The application context to useconfigurersOrExchangeFilterFunctions-WebTestClientConfigurers andExchangeFilterFunctions to apply.
-
reset
public static void reset()Reset all static configurations to their default values. -
get
Perform a GET request to apath. 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.- Parameters:
path- The path to send the request to.pathParams- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can doget("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);.- Returns:
- The response of the GET request.
-
get
Perform a GET request to apath. 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.- Parameters:
path- The path to send the request to.pathParams- The path parameters.- Returns:
- The response of the GET request.
-
get
public static WebTestClientResponse get(Function<org.springframework.web.util.UriBuilder, URI> uriFunction) Perform a GET request to a path generated from the providedFunctionuriFunction.- Parameters:
uriFunction- TheFunction<UriBuilder, URI>used to generate the path to send the request to.- Returns:
- The response of the GET request.
-
post
Perform a POST request to apath. 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.- Parameters:
path- The path to send the request to.pathParams- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can dopost("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);.- Returns:
- The response of the request.
-
get
Perform a GET request to auri.- Parameters:
uri- The uri to send the request to.- Returns:
- The response of the GET request.
-
get
Perform a GET request to aurl.- Parameters:
url- The url to send the request to.- Returns:
- The response of the GET request.
-
get
Perform a GET request to the statically configured base path.- Returns:
- The response of the GET request.
-
request
Perform a request to the pre-configured path (by defaulthttp://localhost:8080).- Parameters:
method- The HTTP method to use- Returns:
- The response of the request.
-
request
Perform a custom HTTP request to the pre-configured path (by defaulthttp://localhost:8080).- Parameters:
method- The HTTP method to use- Returns:
- The response of the request.
-
request
public static WebTestClientResponse request(io.restassured.http.Method method, String path, Object... pathParams) Perform a HTTP request to apath. 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.- Parameters:
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 dorequest(Method.TRACE,"/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);.- Returns:
- The response of the request.
-
request
Perform a custom HTTP request to apath. 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.- Parameters:
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 dorequest("method","/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);.- Returns:
- The response of the request.
-
request
Perform a request to auri.- Parameters:
method- The HTTP method to useuri- The uri to send the request to.- Returns:
- The response of the GET request.
-
request
public static WebTestClientResponse request(io.restassured.http.Method method, Function<org.springframework.web.util.UriBuilder, URI> uriFunction) Perform a request to a path generated from the providedFunctionuriFunction.- Parameters:
method- The HTTP method to useuriFunction- TheFunction<UriBuilder, URI>used to generate the path to send the request to.- Returns:
- The response of the request.
-
request
Perform a request to aurl.- Parameters:
method- The HTTP method to useurl- The url to send the request to.- Returns:
- The response of the GET request.
-
request
Perform a custom HTTP request to auri.- Parameters:
method- The HTTP method to useuri- The uri to send the request to.- Returns:
- The response of the GET request.
-
request
public static WebTestClientResponse request(String method, Function<org.springframework.web.util.UriBuilder, URI> uriFunction) Perform a request to a path generated from the providedFunctionuriFunction.- Parameters:
method- The HTTP method to useuriFunction- TheFunction<UriBuilder, URI>used to generate the path to send the request to.- Returns:
- The response of the request.
-
request
Perform a custom HTTP request to aurl.- Parameters:
method- The HTTP method to useurl- The url to send the request to.- Returns:
- The response of the GET request.
-
post
Perform a POST request to apath. 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.- Parameters:
path- The path to send the request to.pathParams- The path parameters.- Returns:
- The response of the request.
-
put
Perform a PUT request to apath. 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.- Parameters:
path- The path to send the request to.pathParams- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can doput("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);.- Returns:
- The response of the request.
-
post
public static WebTestClientResponse post(Function<org.springframework.web.util.UriBuilder, URI> uriFunction) Perform a POST request to a path generated from the providedFunctionuriFunction.- Parameters:
uriFunction- TheFunction<UriBuilder, URI>used to generate the path to send the request to.- Returns:
- The response of the POST request.
-
post
Perform a POST request to auri.- Parameters:
uri- The uri to send the request to.- Returns:
- The response of the request.
-
post
Perform a POST request to aurl.- Parameters:
url- The url to send the request to.- Returns:
- The response of the request.
-
post
Perform a POST request to the statically configured base path.- Returns:
- The response of the request.
-
delete
Perform a DELETE request to apath. 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.- Parameters:
path- The path to send the request to.pathParams- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can dodelete("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);.- Returns:
- The response of the request.
-
put
-
put
public static WebTestClientResponse put(Function<org.springframework.web.util.UriBuilder, URI> uriFunction) Perform a PUT request to a path generated from the providedFunctionuriFunction.- Parameters:
uriFunction- TheFunction<UriBuilder, URI>used to generate the path to send the request to.- Returns:
- The response of the PUT request.
-
put
Perform a PUT request to auri.- Parameters:
uri- The uri to send the request to.- Returns:
- The response of the request.
-
put
-
put
Perform a PUT request to the statically configured base path.- Returns:
- The response of the request.
-
delete
Perform a DELETE request to apath. 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.- Parameters:
path- The path to send the request to.pathParams- The path parameters.- Returns:
- The response of the request.
-
head
Perform a HEAD request to apath. 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.- Parameters:
path- The path to send the request to.pathParams- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can dohead("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);.- Returns:
- The response of the request.
-
delete
public static WebTestClientResponse delete(Function<org.springframework.web.util.UriBuilder, URI> uriFunction) Perform a DELETE request to a path generated from the providedFunctionuriFunction.- Parameters:
uriFunction- TheFunction<UriBuilder, URI>used to generate the path to send the request to.- Returns:
- The response of the DELETE request.
-
delete
Perform a DELETE request to auri.- Parameters:
uri- The uri to send the request to.- Returns:
- The response of the request.
-
delete
Perform a DELETE request to aurl.- Parameters:
url- The url to send the request to.- Returns:
- The response of the request.
-
delete
Perform a DELETE request to the statically configured base path.- Returns:
- The response of the request.
-
head
Perform a HEAD request to apath. 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.- Parameters:
path- The path to send the request to.pathParams- The path parameters.- Returns:
- The response of the request.
-
patch
Perform a PATCH request to apath. 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.- Parameters:
path- The path to send the request to.pathParams- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can dohead("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);.- Returns:
- The response of the request.
-
head
public static WebTestClientResponse head(Function<org.springframework.web.util.UriBuilder, URI> uriFunction) Perform a HEAD request to a path generated from the providedFunctionuriFunction.- Parameters:
uriFunction- TheFunction<UriBuilder, URI>used to generate the path to send the request to.- Returns:
- The response of the HEAD request.
-
head
Perform a HEAD request to auri.- Parameters:
uri- The uri to send the request to.- Returns:
- The response of the request.
-
head
Perform a HEAD request to aurl.- Parameters:
url- The url to send the request to.- Returns:
- The response of the request.
-
head
Perform a HEAD request to the statically configured base path.- Returns:
- The response of the request.
-
patch
Perform a PATCH request to apath. 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.- Parameters:
path- The path to send the request to.pathParams- The path parameters.- Returns:
- The response of the request.
-
patch
public static WebTestClientResponse patch(Function<org.springframework.web.util.UriBuilder, URI> uriFunction) Perform a PATCH request to a path generated from the providedFunctionuriFunction.- Parameters:
uriFunction- TheFunction<UriBuilder, URI>used to generate the path to send the request to.- Returns:
- The response of the PATCH request.
-
patch
Perform a PATCH request to auri.- Parameters:
uri- The uri to send the request to.- Returns:
- The response of the request.
-
patch
Perform a PATCH request to aurl.- Parameters:
url- The url to send the request to.- Returns:
- The response of the request.
-
patch
Perform a PATCH request to the statically configured base path.- Returns:
- The response of the request.
-
options
Perform a OPTIONS request to apath. 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.- Parameters:
path- The path to send the request to.pathParams- The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can dohead("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);.- Returns:
- The response of the request.
-
options
Perform a OPTIONS request to apath. 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.- Parameters:
path- The path to send the request to.pathParams- The path parameters.- Returns:
- The response of the request.
-
options
public static WebTestClientResponse options(Function<org.springframework.web.util.UriBuilder, URI> uriFunction) Perform a OPTIONS request to a path generated from the providedFunctionuriFunction.- Parameters:
uriFunction- TheFunction<UriBuilder, URI>used to generate the path to send the request to.- Returns:
- The response of the OPTIONS request.
-
options
Perform a OPTIONS request to auri.- Parameters:
uri- The uri to send the request to.- Returns:
- The response of the request.
-
options
Perform a OPTIONS request to aurl.- Parameters:
url- The url to send the request to.- Returns:
- The response of the request.
-
options
Perform a OPTIONS request to the statically configured base path.- Returns:
- The response of the request.
-
enableLoggingOfRequestAndResponseIfValidationFails
public static void enableLoggingOfRequestAndResponseIfValidationFails()Enable logging of both the request and the response if REST Assured test validation fails with log detail equal toLogDetail.ALL.This is just a shortcut for:
RestAssuredWebTestClient.config = new RestAssuredWebTestClientConfig().logConfig(logConfig().enableLoggingOfRequestAndResponseIfValidationFails());
-
enableLoggingOfRequestAndResponseIfValidationFails
public 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.This is just a shortcut for:
RestAssured.config = new RestAssuredWebTestClientConfig().logConfig(logConfig().enableLoggingOfRequestAndResponseIfValidationFails(logDetail));
- Parameters:
logDetail- The log detail to show in the log
-
when
This is usually the entry-point of the API if you need to specify parameters or a body in the request. For example: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.- Returns:
- A request sender interface that lets you call resources on the server.
-
config
- Returns:
- The assigned config or a new config is no config is assigned
-