public class RestAssuredMockMvc extends Object
RestAssured
. This is the starting point of the DSL.
Note that some Javadoc is copied from Spring MVC's test documentation.
Modifier and Type | Field and Description |
---|---|
static String |
basePath
The base path that's used by REST assured when making requests.
|
static RestAssuredMockMvcConfig |
config
Define a REST Assured Mock Mvc configuration.
|
static org.springframework.test.web.servlet.MockMvc |
mockMvc
Set a
MockMvc instance that REST Assured will use when making requests unless overwritten
by a MockMvcRequestSpecification . |
static MockMvcRequestSpecification |
requestSpecification
Specify a default request specification that will be sent with each request.
|
static ResponseSpecification |
responseSpecification
Specify a default response specification that will be sent with each request.
|
Constructor and Description |
---|
RestAssuredMockMvc() |
Modifier and Type | Method and Description |
---|---|
static MockMvcResponse |
delete()
Perform a DELETE request to the statically configured base path.
|
static MockMvcResponse |
delete(String path,
Map<String,?> pathParams)
Perform a DELETE request to a
path . |
static MockMvcResponse |
delete(String path,
Object... pathParams)
Perform a DELETE request to a
path . |
static MockMvcResponse |
delete(URI uri)
Perform a DELETE request to a
uri . |
static MockMvcResponse |
delete(URL url)
Perform a DELETE request to a
url . |
static MockMvcResponse |
get()
Perform a GET request to the statically configured base path.
|
static MockMvcResponse |
get(String path,
Map<String,?> pathParams)
Perform a GET request to a
path . |
static MockMvcResponse |
get(String path,
Object... pathParams)
Perform a GET request to a
path . |
static MockMvcResponse |
get(URI uri)
Perform a GET request to a
uri . |
static MockMvcResponse |
get(URL url)
Perform a GET request to a
url . |
static MockMvcRequestSpecification |
given() |
static MockMvcResponse |
head()
Perform a HEAD request to the statically configured base path.
|
static MockMvcResponse |
head(String path,
Map<String,?> pathParams)
Perform a HEAD request to a
path . |
static MockMvcResponse |
head(String path,
Object... pathParams)
Perform a HEAD request to a
path . |
static MockMvcResponse |
head(URI uri)
Perform a HEAD request to a
uri . |
static MockMvcResponse |
head(URL url)
Perform a HEAD request to a
url . |
static MockMvcResponse |
options()
Perform a OPTIONS request to the statically configured base path.
|
static MockMvcResponse |
options(String path,
Map<String,?> pathParams)
Perform a OPTIONS request to a
path . |
static MockMvcResponse |
options(String path,
Object... pathParams)
Perform a OPTIONS request to a
path . |
static MockMvcResponse |
options(URI uri)
Perform a OPTIONS request to a
uri . |
static MockMvcResponse |
options(URL url)
Perform a OPTIONS request to a
url . |
static MockMvcResponse |
patch()
Perform a PATCH request to the statically configured base path.
|
static MockMvcResponse |
patch(String path,
Map<String,?> pathParams)
Perform a PATCH request to a
path . |
static MockMvcResponse |
patch(String path,
Object... pathParams)
Perform a PATCH request to a
path . |
static MockMvcResponse |
patch(URI uri)
Perform a PATCH request to a
uri . |
static MockMvcResponse |
patch(URL url)
Perform a PATCH request to a
url . |
static MockMvcResponse |
post()
Perform a POST request to the statically configured base path.
|
static MockMvcResponse |
post(String path,
Map<String,?> pathParams)
Perform a POST request to a
path . |
static MockMvcResponse |
post(String path,
Object... pathParams)
Perform a POST request to a
path . |
static MockMvcResponse |
post(URI uri)
Perform a POST request to a
uri . |
static MockMvcResponse |
post(URL url)
Perform a POST request to a
url . |
static MockMvcResponse |
put()
Perform a PUT request to the statically configured base path.
|
static MockMvcResponse |
put(String path,
Object... pathParams)
Perform a PUT request to a
path . |
static MockMvcResponse |
put(URI uri)
Perform a PUT request to a
uri . |
static MockMvcResponse |
put(URL url)
Perform a PUT request to a
url . |
static void |
reset()
Reset all static configurations to their default values.
|
static List<org.springframework.test.web.servlet.ResultHandler> |
resultHandlers() |
static void |
resultHandlers(org.springframework.test.web.servlet.ResultHandler resultHandler,
org.springframework.test.web.servlet.ResultHandler... resultHandlers)
Assign one or more
ResultHandler that'll be executes after a request has been made. |
static void |
standaloneSetup(Object... controllers)
Build a
MockMvc by registering one or more @Controller 's
instances and configuring Spring MVC infrastructure programmatically. |
static void |
webAppContextSetup(org.springframework.web.context.WebApplicationContext context)
Build a
MockMvc using the given, fully initialized, i.e. |
public static org.springframework.test.web.servlet.MockMvc mockMvc
MockMvc
instance that REST Assured will use when making requests unless overwritten
by a MockMvcRequestSpecification
.public static RestAssuredMockMvcConfig config
given().config(newConfig().logConfig(new LogConfig(captor, true))). ..
newConfig()
can be statically imported from RestAssuredMockMvcConfig
.public static MockMvcRequestSpecification requestSpecification
RestAssuredMockMvc.requestSpecification = new MockMvcRequestSpecBuilder().addParam("parameter1", "value1").build();means that for each request by Rest Assured "parameter1" will be equal to "value1".
public static ResponseSpecification responseSpecification
RestAssuredMockMvc.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
null
(which means no base path).public static MockMvcRequestSpecification given()
public static void standaloneSetup(Object... controllers)
MockMvc
by registering one or more @Controller
's
instances and configuring Spring MVC infrastructure 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.
When this option is used, the minimum infrastructure required by the
org.springframework.web.servlet.DispatcherServlet
to serve requests with annotated controllers is
automatically created, and can be customized, resulting in configuration
that is equivalent to what the MVC Java configuration provides except
using builder style methods.
If the Spring MVC configuration of an application is relatively straight-forward, for example when using the MVC namespace or the MVC Java config, then using this builder might be a good option for testing a majority of controllers. A much smaller number of tests can be used to focus on testing and verifying the actual Spring MVC configuration.
controllers
- one or more @Controller
's to testpublic static void webAppContextSetup(org.springframework.web.context.WebApplicationContext context)
MockMvc
using the given, fully initialized, i.e.
refreshed, WebApplicationContext
and assign it to REST Assured.
The org.springframework.web.servlet.DispatcherServlet
will use the context to discover Spring MVC infrastructure and
application controllers in it. The context must have been configured with
a ServletContext
.public static void resultHandlers(org.springframework.test.web.servlet.ResultHandler resultHandler, org.springframework.test.web.servlet.ResultHandler... resultHandlers)
ResultHandler
that'll be executes after a request has been made.resultHandler
- The result handlerresultHandlers
- Additional result handlers (optional)public static List<org.springframework.test.web.servlet.ResultHandler> resultHandlers()
public static void reset()
public static MockMvcResponse 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 MockMvcResponse 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 MockMvcResponse 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 MockMvcResponse 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 MockMvcResponse 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 MockMvcResponse 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 MockMvcResponse 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 MockMvcResponse 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 MockMvcResponse 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 MockMvcResponse 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 MockMvcResponse 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 MockMvcResponse 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 MockMvcResponse 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 MockMvcResponse get(URI uri)
uri
.uri
- The uri to send the request to.public static MockMvcResponse post(URI uri)
uri
.uri
- The uri to send the request to.public static MockMvcResponse put(URI uri)
uri
.uri
- The uri to send the request to.public static MockMvcResponse delete(URI uri)
uri
.uri
- The uri to send the request to.public static MockMvcResponse head(URI uri)
uri
.uri
- The uri to send the request to.public static MockMvcResponse patch(URI uri)
uri
.uri
- The uri to send the request to.public static MockMvcResponse options(URI uri)
uri
.uri
- The uri to send the request to.public static MockMvcResponse get(URL url)
url
.url
- The url to send the request to.public static MockMvcResponse post(URL url)
url
.url
- The url to send the request to.public static MockMvcResponse put(URL url)
url
.url
- The url to send the request to.public static MockMvcResponse delete(URL url)
url
.url
- The url to send the request to.public static MockMvcResponse head(URL url)
url
.url
- The url to send the request to.public static MockMvcResponse patch(URL url)
url
.url
- The url to send the request to.public static MockMvcResponse options(URL url)
url
.url
- The url to send the request to.public static MockMvcResponse get()
public static MockMvcResponse post()
public static MockMvcResponse put()
public static MockMvcResponse delete()
public static MockMvcResponse head()
public static MockMvcResponse patch()
public static MockMvcResponse options()
Copyright © 2010–2014. All rights reserved.