public class RequestSpecificationImpl extends Object implements FilterableRequestSpecification, groovy.lang.GroovyInterceptable
| Constructor and Description |
|---|
RequestSpecificationImpl(String baseURI,
int requestPort,
String basePath,
AuthenticationScheme defaultAuthScheme,
List<Filter> filters,
Object defaultRequestContentType,
RequestSpecification defaultSpec,
boolean urlEncode,
RestAssuredConfig restAssuredConfig,
LogRepository logRepository,
ProxySpecification proxySpecification) |
| Modifier and Type | Method and Description |
|---|---|
RequestSpecification |
and()
Syntactic sugar, e.g.
|
Object |
applyEncoderConfig(HTTPBuilder httpBuilder,
EncoderConfig encoderConfig) |
Object |
applyHttpClientConfig(HttpClientConfig httpClientConfig) |
Object |
applyRedirectConfig(RedirectConfig redirectConfig) |
Object |
applyRestAssuredConfig(HTTPBuilder http) |
Object |
applySessionConfig(SessionConfig sessionConfig) |
Object |
assembleBodyContent(Object httpMethod) |
AuthenticationSpecification |
auth()
A slightly short version of
RequestSpecification.authentication(). |
AuthenticationSpecification |
authentication()
If you need to specify some credentials when performing a request.
|
RequestSpecification |
basePath(String basePath)
Add the basePath property from the RequestSpecification instead of using static field RestAssured.basePath.
|
RequestSpecification |
baseUri(String baseUri)
Adding the baseUri Property from the RequestSpecification instead of using static field RestAssured.baseURI.
|
RequestSpecification |
body(byte... body)
Specify a byte array request body that'll be sent with the request.
|
RequestSpecification |
body(Object object)
Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request.
|
RequestSpecification |
body(Object object,
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.
|
RequestSpecification |
body(Object object,
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.
|
RequestSpecification |
body(String body)
Specify a String request body (such as e.g.
|
RequestSpecification |
config(RestAssuredConfig config)
Define a REST Assured configuration.
|
RequestSpecification |
content(byte... content)
Specify a byte array request content that'll be sent with the request.
|
RequestSpecification |
content(Object object)
Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request.
|
RequestSpecification |
content(Object object,
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.
|
RequestSpecification |
content(Object object,
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.
|
RequestSpecification |
content(String content)
Specify a String request content (such as e.g.
|
RequestSpecification |
contentType(ContentType contentType)
Specify the content type of the request.
|
RequestSpecification |
contentType(String contentType)
Specify the content type of the request.
|
RequestSpecification |
cookie(Cookie cookie)
Specify a
Cookie to send with the request. |
RequestSpecification |
cookie(String cookieName)
Specify a cookie with no value that'll be sent with the request e.g:
|
RequestSpecification |
cookie(String cookieName,
Object value,
Object... additionalValues)
Specify a cookie that'll be sent with the request e.g:
|
RequestSpecification |
cookies(Cookies cookies)
Specify the cookies that'll be sent with the request as
Cookies: |
RequestSpecification |
cookies(Map cookies)
Specify the cookies that'll be sent with the request as Map e.g:
|
RequestSpecification |
cookies(String firstCookieName,
Object firstCookieValue,
Object... cookieNameValuePairs)
Specify the cookies that'll be sent with the request.
|
Response |
delete()
Perform a DELETE request to the statically configured path (by default
http://localhost:8080). |
Response |
delete(String path,
Map pathParams)
Perform a DELETE request to a
path. |
Response |
delete(String path,
Object... pathParams)
Perform a DELETE request to a
path. |
Response |
delete(URI uri)
Perform a DELETE request to a
uri. |
Response |
delete(URL url)
Perform a DELETE request to a
url. |
ResponseSpecification |
expect()
Returns the response specification so that you can setup the expectations on the response.
|
RequestSpecification |
filter(Filter filter)
Add a filter that will be used in the request.
|
RequestSpecification |
filters(Filter filter,
Filter... additionalFilter)
Add filters that will be used in the request.
|
RequestSpecification |
filters(List<Filter> filters)
Add filters that will be used in the request.
|
RequestSpecification |
formParam(String parameterName,
Collection<?> parameterValues)
A slightly shorter version of
RequestSpecification.formParameter(String, java.util.Collection). |
RequestSpecification |
formParam(String parameterName,
Object... parameterValues)
A slightly shorter version of
RequestSpecification.formParameter(String, Object...). |
RequestSpecification |
formParameter(String parameterName,
Collection<?> parameterValues)
Specify a multi-value form parameter that'll be sent with the request e.g:
|
RequestSpecification |
formParameter(String parameterName,
Object... additionalParameterValues)
Specify a form parameter that'll be sent with the request.
|
RequestSpecification |
formParameters(Map parametersMap)
Specify the form parameters that'll be sent with the request.
|
RequestSpecification |
formParameters(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
Specify the form parameters that'll be sent with the request.
|
RequestSpecification |
formParams(Map parametersMap)
A slightly shorter version of
RequestSpecification.formParameters(java.util.Map). |
RequestSpecification |
formParams(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
A slightly shorter version of
RequestSpecification.formParameters(String, Object, Object...). |
Response |
get()
Perform a GET request to the statically configured path (by default
http://localhost:8080). |
Response |
get(String path,
Map pathParams)
Perform a GET request to a
path. |
Response |
get(String path,
Object... pathParams)
Perform a GET request to a
path. |
Response |
get(URI uri)
Perform a GET request to a
uri. |
Response |
get(URL url)
Perform a GET request to a
url. |
AuthenticationScheme |
getAuthenticationScheme() |
String |
getBasePath() |
String |
getBaseUri() |
<T> T |
getBody() |
RestAssuredConfig |
getConfig() |
Cookies |
getCookies() |
List<Filter> |
getDefinedFilters() |
Map<String,Object> |
getFormParams() |
Headers |
getHeaders() |
org.apache.http.client.HttpClient |
getHttpClient() |
groovy.lang.MetaClass |
getMetaClass() |
List<MultiPartSpecification> |
getMultiPartParams() |
Map<String,Object> |
getPathParams() |
int |
getPort() |
Object |
getProperty(String property) |
ProxySpecification |
getProxySpecification() |
Map<String,Object> |
getQueryParams() |
String |
getRequestContentType() |
Map<String,Object> |
getRequestParams() |
RequestSpecification |
given()
Syntactic sugar, e.g.
|
Response |
head()
Perform a HEAD request to the statically configured path (by default
http://localhost:8080). |
Response |
head(String path,
Map pathParams)
Perform a HEAD request to a
path. |
Response |
head(String path,
Object... pathParams)
Perform a HEAD request to a
path. |
Response |
head(URI uri)
Perform a HEAD request to a
uri. |
Response |
head(URL url)
Perform a HEAD request to a
url. |
RequestSpecification |
header(Header header)
Specify a
Header to send with the request. |
RequestSpecification |
header(String headerName,
Object headerValue,
Object... additionalHeaderValues)
Specify a header that'll be sent with the request e.g:
|
RequestSpecification |
headers(Headers headers)
Specify the headers that'll be sent with the request as
Headers, e.g: |
RequestSpecification |
headers(Map headers)
Specify the headers that'll be sent with the request as Map e.g:
|
RequestSpecification |
headers(String firstHeaderName,
Object firstHeaderValue,
Object... headerNameValuePairs)
Specify the headers that'll be sent with the request.
|
Object |
invokeFilterChain(Object path,
Object method,
Object assertionClosure) |
Object |
invokeMethod(String method,
Object arguments) |
RequestSpecification |
keystore(File pathToJks,
String password)
Use a keystore located on the file-system.
|
RequestSpecification |
keystore(String pathToJks,
String password)
The following documentation is taken from http://groovy.codehaus.org/modules/http-builder/doc/ssl.html:
|
RequestLogSpecification |
log()
Returns the
RequestLogSpecification that allows you to log different parts of the RequestSpecification. |
Object |
mergeMapsAndRetainOrder(Map<String,Object> map1,
Map<String,Object> map2) |
RequestSpecification |
multiPart(File file)
Specify a file to upload to the server using multi-part form data uploading.
|
RequestSpecification |
multiPart(MultiPartSpecification multiPartSpec)
Specify a multi-part specification.
|
RequestSpecification |
multiPart(String controlName,
File file)
Specify a file to upload to the server using multi-part form data uploading with a specific
control name.
|
RequestSpecification |
multiPart(String name,
File file,
String mimeType)
Specify a file to upload to the server using multi-part form data uploading with a specific
control name and mime-type.
|
RequestSpecification |
multiPart(String name,
NoParameterValue contentBody) |
RequestSpecification |
multiPart(String controlName,
Object object)
Specify an object that will be serialized to JSON and uploaded to the server using multi-part form data
uploading with a specific control name.
|
RequestSpecification |
multiPart(String controlName,
Object object,
String mimeType)
Specify an object that will be serialized and uploaded to the server using multi-part form data
uploading with a specific control name.
|
RequestSpecification |
multiPart(String name,
String contentBody)
Specify a string to send to the server using multi-part form data.
|
RequestSpecification |
multiPart(String name,
String fileName,
byte... bytes)
Specify a byte-array to upload to the server using multi-part form data.
|
RequestSpecification |
multiPart(String name,
String fileName,
byte[] bytes,
String mimeType)
Specify a byte-array to upload to the server using multi-part form data.
|
RequestSpecification |
multiPart(String name,
String fileName,
InputStream stream)
Specify an inputstream to upload to the server using multi-part form data.
|
RequestSpecification |
multiPart(String name,
String fileName,
InputStream stream,
String mimeType)
Specify an inputstream to upload to the server using multi-part form data.
|
RequestSpecification |
multiPart(String name,
String contentBody,
String mimeType)
Specify a string to send to the server using multi-part form data with a specific mime-type.
|
RequestSpecification |
noFilters()
Remove all applied filters
|
<T extends Filter> |
noFiltersOfType(Class<T> filterType)
Remove all applied filters
|
Response |
options()
Perform a OPTIONS request to the statically configured path (by default
http://localhost:8080). |
Response |
options(String path,
Map pathParams)
Perform a OPTIONS request to a
path. |
Response |
options(String path,
Object... pathParams)
Perform a OPTIONS request to a
path. |
Response |
options(URI uri)
Perform a OPTIONS request to a
uri. |
Response |
options(URL url)
Perform a OPTIONS request to a
url. |
RequestSpecification |
param(String parameterName,
Collection<?> parameterValues)
A slightly shorter version of
RequestSpecification.parameter(String, java.util.Collection). |
RequestSpecification |
param(String parameterName,
Object... parameterValues)
A slightly shorter version of
RequestSpecification.parameter(String, Object...). |
RequestSpecification |
parameter(String parameterName,
Collection<?> parameterValues)
Specify a multi-value parameter that'll be sent with the request e.g:
|
RequestSpecification |
parameter(String parameterName,
Object... parameterValues)
Specify a parameter that'll be sent with the request e.g:
|
RequestSpecification |
parameters(Map parametersMap)
Specify the parameters that'll be sent with the request as Map e.g:
|
RequestSpecification |
parameters(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
Specify the parameters that'll be sent with the request.
|
RequestSpecification |
params(Map parametersMap)
A slightly shorter version of
RequestSpecification.parameters(Map). |
RequestSpecification |
params(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
A slightly shorter version of
RequestSpecification.parameters(String, Object, Object...) |
Response |
patch()
Perform a PATCH request to the statically configured path (by default
http://localhost:8080). |
Response |
patch(String path,
Map pathParams)
Perform a PATCH request to a
path. |
Response |
patch(String path,
Object... pathParams)
Perform a PATCH request to a
path. |
Response |
patch(URI uri)
Perform a PATCH request to a
uri. |
Response |
patch(URL url)
Perform a PATCH request to a
url. |
RequestSpecification |
pathParam(String parameterName,
Object parameterValue)
A slightly shorter version of
RequestSpecification.pathParameter(String, Object). |
RequestSpecification |
pathParameter(String parameterName,
Object parameterValue)
Specify a path parameter.
|
RequestSpecification |
pathParameters(Map parameterNameValuePairs)
Specify multiple path parameter name-value pairs.
|
RequestSpecification |
pathParameters(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
Specify multiple path parameter name-value pairs.
|
RequestSpecification |
pathParams(Map parameterNameValuePairs)
A slightly shorter version of
RequestSpecification.pathParameters(java.util.Map). |
RequestSpecification |
pathParams(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
A slightly shorter version of
RequestSpecification.pathParameters(String, Object, Object...). |
RequestSpecification |
port(int port)
Specify the port of the URI.
|
Response |
post()
Perform a POST request to the statically configured path (by default
http://localhost:8080). |
Response |
post(String path,
Map pathParams)
Perform a POST request to a
path. |
Response |
post(String path,
Object... pathParams)
Perform a POST request to a
path. |
Response |
post(URI uri)
Perform a POST request to a
uri. |
Response |
post(URL url)
Perform a POST request to a
url. |
RequestSpecification |
proxy(int port)
Instruct REST Assured to connect to a proxy on the specified port on localhost.
|
RequestSpecification |
proxy(ProxySpecification proxySpecification)
Instruct REST Assured to connect to a proxy using a
ProxySpecification. |
RequestSpecification |
proxy(String host)
Instruct REST Assured to connect to a proxy on the specified host on port
8888. |
RequestSpecification |
proxy(String host,
int port)
Instruct REST Assured to connect to a proxy on the specified host and port.
|
RequestSpecification |
proxy(String host,
int port,
String scheme)
Instruct REST Assured to connect to a proxy on the specified port on localhost with a specific scheme.
|
RequestSpecification |
proxy(URI uri)
Instruct REST Assured to connect to a proxy using a URI.
|
Response |
put()
Perform a PUT request to the statically configured path (by default
http://localhost:8080). |
Response |
put(String path,
Map pathParams)
Perform a PUT request to a
path. |
Response |
put(String path,
Object... pathParams)
Perform a PUT request to a
path. |
Response |
put(URI uri)
Perform a PUT request to a
uri. |
Response |
put(URL url)
Perform a PUT request to a
url. |
RequestSpecification |
queryParam(String parameterName,
Collection<?> parameterValues)
A slightly shorter version of
RequestSpecification.queryParameter(String, java.util.Collection). |
RequestSpecification |
queryParam(String parameterName,
Object... parameterValues)
A slightly shorter version of
RequestSpecification.queryParameter(String, Object...). |
RequestSpecification |
queryParameter(String parameterName,
Collection<?> parameterValues)
Specify a multi-value query parameter that'll be sent with the request e.g:
|
RequestSpecification |
queryParameter(String parameterName,
Object... parameterValues)
Specify a query parameter that'll be sent with the request.
|
RequestSpecification |
queryParameters(Map parametersMap)
Specify the query parameters that'll be sent with the request.
|
RequestSpecification |
queryParameters(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
Specify the query parameters that'll be sent with the request.
|
RequestSpecification |
queryParams(Map parametersMap)
A slightly shorter version of
RequestSpecification.queryParameters(java.util.Map). |
RequestSpecification |
queryParams(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
A slightly shorter version of
RequestSpecification.queryParameters(String, Object, Object...). |
RedirectSpecification |
redirects()
Specify the redirect configuration for this request.
|
RequestSpecification |
relaxedHTTPSValidation()
Use relaxed HTTP validation.
|
RequestSpecification |
request()
Syntactic sugar, e.g.
|
ResponseSpecification |
response()
Returns the response specification so that you can setup the expectations on the response.
|
RestAssuredConfig |
restAssuredConfig() |
RequestSpecification |
sessionId(String sessionIdValue)
Set the session id for this request.
|
RequestSpecification |
sessionId(String sessionIdName,
String sessionIdValue)
Set the session id name and value for this request.
|
void |
setAuthenticationScheme(AuthenticationScheme value) |
void |
setMetaClass(groovy.lang.MetaClass mc) |
void |
setProperty(String property,
Object value) |
Object |
setRequestHeadersToHttpBuilder(HTTPBuilder http) |
void |
setResponseSpecification(ResponseSpecification responseSpecification) |
boolean |
shouldApplySSLConfig(Object http,
RestAssuredConfig cfg) |
RequestSpecification |
spec(RequestSpecification requestSpecificationToMerge)
Add request data from a pre-defined specification.
|
RequestSpecification |
specification(RequestSpecification requestSpecificationToMerge)
Add request data from a pre-defined specification.
|
RequestSpecification |
that()
Syntactic sugar, e.g.
|
ResponseSpecification |
then()
Returns the response specification so that you can setup the expectations on the response.
|
RequestSpecification |
trustStore(KeyStore trustStore)
Use the supplied truststore for HTTPS requests.
|
RequestSpecification |
urlEncodingEnabled(boolean isEnabled)
Specifies if Rest Assured should url encode the URL automatically.
|
RequestSpecification |
when()
Syntactic sugar, e.g.
|
RequestSpecification |
with()
Syntactic sugar, e.g.
|
public RequestSpecificationImpl(String baseURI, int requestPort, String basePath, AuthenticationScheme defaultAuthScheme, List<Filter> filters, Object defaultRequestContentType, RequestSpecification defaultSpec, boolean urlEncode, RestAssuredConfig restAssuredConfig, LogRepository logRepository, ProxySpecification proxySpecification)
public groovy.lang.MetaClass getMetaClass()
getMetaClass in interface groovy.lang.GroovyObjectpublic void setMetaClass(groovy.lang.MetaClass mc)
setMetaClass in interface groovy.lang.GroovyObjectpublic Object invokeMethod(String method, Object arguments)
invokeMethod in interface groovy.lang.GroovyObjectpublic Object getProperty(String property)
getProperty in interface groovy.lang.GroovyObjectpublic void setProperty(String property, Object value)
setProperty in interface groovy.lang.GroovyObjectpublic AuthenticationScheme getAuthenticationScheme()
getAuthenticationScheme in interface FilterableRequestSpecificationpublic void setAuthenticationScheme(AuthenticationScheme value)
public RequestSpecification when()
RequestSpecification
expect().body(containsString("OK")).when().get("/something");
is that same as:
expect().body(containsString("OK")).get("/something");
when in interface RequestSpecificationpublic RequestSpecification given()
RequestSpecification
given().param("name1", "value1").and().given().param("name2", "value2").when().get("/something");
is that same as:
given().param("name1", "value1").and().param("name2", "value2").when().get("/something");
given in interface RequestSpecificationpublic RequestSpecification that()
RequestSpecification
expect().that().body(containsString("OK")).when().get("/something");
is that same as:
expect().body(containsString("OK")).get("/something");
that in interface RequestSpecificationpublic ResponseSpecification response()
RequestSpecification
given().param("name", "value").then().response().body(equalTo("something")).when().get("/something");
response in interface RequestSpecificationpublic Response get(String path, Object... pathParams)
RequestSenderOptionspath. 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.get in interface RequestSenderOptions<Response>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 Response post(String path, Object... pathParams)
RequestSenderOptionspath. 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.post in interface RequestSenderOptions<Response>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 Response put(String path, Object... pathParams)
RequestSenderOptionspath. 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.put in interface RequestSenderOptions<Response>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 Response delete(String path, Object... pathParams)
RequestSenderOptionspath. 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.delete in interface RequestSenderOptions<Response>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 Response head(String path, Object... pathParams)
RequestSenderOptionspath. 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.head in interface RequestSenderOptions<Response>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 Response patch(String path, Object... pathParams)
RequestSenderOptionspath. 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.patch in interface RequestSenderOptions<Response>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 Response options(String path, Object... pathParams)
RequestSenderOptionspath. 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.options in interface RequestSenderOptions<Response>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 Response get(URI uri)
RequestSenderOptionsuri.get in interface RequestSenderOptions<Response>uri - The uri to send the request to.public Response post(URI uri)
RequestSenderOptionsuri.post in interface RequestSenderOptions<Response>uri - The uri to send the request to.public Response put(URI uri)
RequestSenderOptionsuri.put in interface RequestSenderOptions<Response>uri - The uri to send the request to.public Response delete(URI uri)
RequestSenderOptionsuri.delete in interface RequestSenderOptions<Response>uri - The uri to send the request to.public Response head(URI uri)
RequestSenderOptionsuri.head in interface RequestSenderOptions<Response>uri - The uri to send the request to.public Response patch(URI uri)
RequestSenderOptionsuri.patch in interface RequestSenderOptions<Response>uri - The uri to send the request to.public Response options(URI uri)
RequestSenderOptionsuri.options in interface RequestSenderOptions<Response>uri - The uri to send the request to.public Response get(URL url)
RequestSenderOptionsurl.get in interface RequestSenderOptions<Response>url - The url to send the request to.public Response post(URL url)
RequestSenderOptionsurl.post in interface RequestSenderOptions<Response>url - The url to send the request to.public Response put(URL url)
RequestSenderOptionsurl.put in interface RequestSenderOptions<Response>url - The url to send the request to.public Response delete(URL url)
RequestSenderOptionsurl.delete in interface RequestSenderOptions<Response>url - The url to send the request to.public Response head(URL url)
RequestSenderOptionsurl.head in interface RequestSenderOptions<Response>url - The url to send the request to.public Response patch(URL url)
RequestSenderOptionsurl.patch in interface RequestSenderOptions<Response>url - The url to send the request to.public Response options(URL url)
RequestSenderOptionsurl.options in interface RequestSenderOptions<Response>url - The url to send the request to.public Response get()
RequestSenderOptionshttp://localhost:8080).get in interface RequestSenderOptions<Response>public Response post()
RequestSenderOptionshttp://localhost:8080).post in interface RequestSenderOptions<Response>public Response put()
RequestSenderOptionshttp://localhost:8080).put in interface RequestSenderOptions<Response>public Response delete()
RequestSenderOptionshttp://localhost:8080).delete in interface RequestSenderOptions<Response>public Response head()
RequestSenderOptionshttp://localhost:8080).head in interface RequestSenderOptions<Response>public Response patch()
RequestSenderOptionshttp://localhost:8080).patch in interface RequestSenderOptions<Response>public Response options()
RequestSenderOptionshttp://localhost:8080).options in interface RequestSenderOptions<Response>public Response get(String path, Map pathParams)
RequestSenderOptionspath. 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.get in interface RequestSenderOptions<Response>path - The path to send the request to.pathParams - The path parameters.public Response post(String path, Map pathParams)
RequestSenderOptionspath. 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.post in interface RequestSenderOptions<Response>path - The path to send the request to.pathParams - The path parameters.public Response put(String path, Map pathParams)
RequestSenderOptionspath. 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.put in interface RequestSenderOptions<Response>path - The path to send the request to.pathParams - The path parameters.public Response delete(String path, Map pathParams)
RequestSenderOptionspath. 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.delete in interface RequestSenderOptions<Response>path - The path to send the request to.pathParams - The path parameters.public Response head(String path, Map pathParams)
RequestSenderOptionspath. 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.head in interface RequestSenderOptions<Response>path - The path to send the request to.pathParams - The path parameters.public Response patch(String path, Map pathParams)
RequestSenderOptionspath. 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.patch in interface RequestSenderOptions<Response>path - The path to send the request to.pathParams - The path parameters.public Response options(String path, Map pathParams)
RequestSenderOptionspath. 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.options in interface RequestSenderOptions<Response>path - The path to send the request to.pathParams - The path parameters.public RequestSpecification parameters(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
RequestSpecification
given().parameters("username", "John", "token", "1234").then().expect().body(equalTo("username, token")).when().get("/parameters");
This will send a GET request to "/parameters" with two parameters:
parameters in interface RequestSpecificationfirstParameterName - The name of the first parameterfirstParameterValue - The value of the first parameterparameterNameValuePairs - Additional parameters in name-value pairs.public RequestSpecification parameters(Map parametersMap)
RequestSpecification
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("username", "John");
parameters.put("token", "1234");
given().parameters(parameters).then().expect().body(equalTo("username, token")).when().get("/cookie");
This will send a GET request to "/cookie" with two parameters:
parameters in interface RequestSpecificationparametersMap - The Map containing the parameter names and their values to send with the request.public RequestSpecification params(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
RequestSpecificationRequestSpecification.parameters(String, Object, Object...)params in interface RequestSpecificationfirstParameterName - The name of the first parameterfirstParameterValue - The value of the first parameterparameterNameValuePairs - Additional parameters in name-value pairs.RequestSpecification.parameters(String, Object, Object...)public RequestSpecification params(Map parametersMap)
RequestSpecificationRequestSpecification.parameters(Map).params in interface RequestSpecificationparametersMap - The Map containing the parameter names and their values to send with the request.RequestSpecification.parameters(Map)public RequestSpecification param(String parameterName, Object... parameterValues)
RequestSpecificationRequestSpecification.parameter(String, Object...).param in interface RequestSpecificationparameterName - The parameter nameparameterValues - Parameter values, one to many if you want to specify multiple values for the same parameter.RequestSpecification.parameter(String, Object...)public RequestSpecification parameter(String parameterName, Collection<?> parameterValues)
RequestSpecification
given().parameter("cars", asList("Volvo", "Saab"))..;
This will set the parameter cars=Volvo and cars=Saab.
parameter in interface RequestSpecificationparameterName - The parameter nameparameterValues - The parameter valuespublic RequestSpecification param(String parameterName, Collection<?> parameterValues)
RequestSpecificationRequestSpecification.parameter(String, java.util.Collection).param in interface RequestSpecificationparameterName - The parameter nameparameterValues - The parameter valuespublic RequestSpecification queryParameter(String parameterName, Collection<?> parameterValues)
RequestSpecification
given().queryParameter("cars", asList("Volvo", "Saab"))..;
This will set the parameter cars=Volvo and cars=Saab.
Note that this method is the same as RequestSpecification.parameter(String, java.util.Collection)
for all http methods except for POST where RequestSpecification.parameter(String, java.util.Collection) adds a form parameter and
this method sets a query parameter.queryParameter in interface RequestSpecificationparameterName - The parameter nameparameterValues - The parameter valuespublic RequestSpecification queryParam(String parameterName, Collection<?> parameterValues)
RequestSpecificationRequestSpecification.queryParameter(String, java.util.Collection).queryParam in interface RequestSpecificationparameterName - The parameter nameparameterValues - The parameter valuesRequestSpecification.queryParam(String, java.util.Collection)public RequestSpecification parameter(String parameterName, Object... parameterValues)
RequestSpecification
given().parameter("username", "John").and().expect().body(equalTo("username")).when().get("/cookie");
This will set the parameter username=John in the GET request to "/cookie".
You can also specify several parameters like this:
given().parameter("username", "John").and().parameter("password", "1234").and().expect().body(equalTo("username")).when().get("/cookie");
parameter in interface RequestSpecificationparameterName - The parameter nameparameterValues - Zero to many parameter values for this parameter nameRequestSpecification.parameters(String, Object, Object...)public RequestSpecification queryParameters(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
RequestSpecificationRequestSpecification.parameters(String, Object, Object...)
for all http methods except for POST where RequestSpecification.parameters(String, Object, Object...) sets the form parameters and this method sets the
query parameters.queryParameters in interface RequestSpecificationfirstParameterName - The name of the first parameterfirstParameterValue - The value of the first parameterparameterNameValuePairs - The value of the first parameter followed by additional parameters in name-value pairs.public RequestSpecification queryParameters(Map parametersMap)
RequestSpecificationRequestSpecification.parameters(Map)
for all http methods except for POST where RequestSpecification.parameters(Map) sets the form parameters and this method sets the
query parameters.queryParameters in interface RequestSpecificationparametersMap - The Map containing the parameter names and their values to send with the request.public RequestSpecification queryParameter(String parameterName, Object... parameterValues)
RequestSpecificationRequestSpecification.parameter(String, Object...)
for all http methods except for POST where RequestSpecification.parameter(String, Object...) adds a form parameter and this method sets a
query parameter.queryParameter in interface RequestSpecificationparameterName - The parameter nameparameterValues - Zero to many parameter values, i.e. you can specify multiple values for the same parameterRequestSpecification.parameter(String, Object...)public RequestSpecification queryParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
RequestSpecificationRequestSpecification.queryParameters(String, Object, Object...).queryParams in interface RequestSpecificationfirstParameterName - The name of the first parameterfirstParameterValue - The value of the first parameterparameterNameValuePairs - The value of the first parameter followed by additional parameters in name-value pairs.RequestSpecification.queryParameters(String, Object, Object...)public RequestSpecification queryParams(Map parametersMap)
RequestSpecificationRequestSpecification.queryParameters(java.util.Map).queryParams in interface RequestSpecificationparametersMap - The Map containing the parameter names and their values to send with the request.RequestSpecification.queryParams(java.util.Map)public RequestSpecification queryParam(String parameterName, Object... parameterValues)
RequestSpecificationRequestSpecification.queryParameter(String, Object...).queryParam in interface RequestSpecificationparameterName - The parameter nameparameterValues - Zero to many parameter values. Use additional parameter values if you want to specify multiple values for the same parameterRequestSpecification.parameter(String, Object...)public RequestSpecification formParameter(String parameterName, Collection<?> parameterValues)
RequestSpecification
given().formParameter("cars", asList("Volvo", "Saab"))..;
This will set the parameter cars=Volvo and cars=Saab.
Note that this method is the same as RequestSpecification.parameter(String, java.util.Collection)
for all http methods except for PUT where RequestSpecification.parameter(String, java.util.Collection) adds a query parameter and
this method sets a form parameter.formParameter in interface RequestSpecificationparameterName - The parameter nameparameterValues - The parameter valuespublic RequestSpecification formParam(String parameterName, Collection<?> parameterValues)
RequestSpecificationRequestSpecification.formParameter(String, java.util.Collection).formParam in interface RequestSpecificationparameterName - The parameter nameparameterValues - The parameter valuesRequestSpecification.formParam(String, java.util.Collection)public RequestSpecification formParameters(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
RequestSpecificationRequestSpecification.parameters(String, Object, Object...)
for all http methods except for PUT where RequestSpecification.parameters(String, Object, Object...) sets the query parameters and this method sets the
form parameters.formParameters in interface RequestSpecificationfirstParameterName - The name of the first parameterfirstParameterValue - The value of the first parameterparameterNameValuePairs - The value of the first parameter followed by additional parameters in name-value pairs.public RequestSpecification formParameters(Map parametersMap)
RequestSpecificationRequestSpecification.parameters(Map)
for all http methods except for PUT where RequestSpecification.parameters(Map) sets the query parameters and this method sets the
form parameters.formParameters in interface RequestSpecificationparametersMap - The Map containing the parameter names and their values to send with the request.public RequestSpecification formParameter(String parameterName, Object... additionalParameterValues)
RequestSpecificationRequestSpecification.parameter(String, Object...)
for all http methods except for PUT where RequestSpecification.parameter(String, Object...) adds a query parameter and this method sets a
form parameter.formParameter in interface RequestSpecificationparameterName - The parameter nameadditionalParameterValues - Zero to many parameter values for this parameter.RequestSpecification.parameter(String, Object...)public RequestSpecification formParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
RequestSpecificationRequestSpecification.formParameters(String, Object, Object...).formParams in interface RequestSpecificationfirstParameterName - The name of the first parameterfirstParameterValue - The value of the first parameterparameterNameValuePairs - The value of the first parameter followed by additional parameters in name-value pairs.RequestSpecification.formParameters(String, Object, Object...)public RequestSpecification formParams(Map parametersMap)
RequestSpecificationRequestSpecification.formParameters(java.util.Map).formParams in interface RequestSpecificationparametersMap - The Map containing the parameter names and their values to send with the request.RequestSpecification.formParams(java.util.Map)public RequestSpecification formParam(String parameterName, Object... parameterValues)
RequestSpecificationRequestSpecification.formParameter(String, Object...).formParam in interface RequestSpecificationparameterName - The parameter nameparameterValues - Zero to many parameter values. You can specify multiple values for the same parameter.RequestSpecification.parameter(String, Object...)public RequestSpecification urlEncodingEnabled(boolean isEnabled)
RequestSpecificationurlEncodingEnabled in interface RequestSpecificationisEnabled - Specify whether or not URL encoding should be enabled or disabled.public RequestSpecification pathParameter(String parameterName, Object parameterValue)
RequestSpecification
expect().statusCode(200).when().get("/item/"+myItem.getItemNumber()+"/buy/"+2);
you can write:
given().
pathParameter("itemNumber", myItem.getItemNumber()).
pathParameter("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);
pathParameter in interface RequestSpecificationparameterName - The parameter nameparameterValue - The parameter valuepublic RequestSpecification pathParameters(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
RequestSpecification
expect().statusCode(200).when().get("/item/"+myItem.getItemNumber()+"/buy/"+2);
you can write:
given().
pathParameters("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);
pathParameters in interface RequestSpecificationfirstParameterName - The name of the first parameterfirstParameterValue - The value of the first parameterparameterNameValuePairs - Additional parameters in name-value pairs.public RequestSpecification pathParameters(Map parameterNameValuePairs)
RequestSpecification
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);
pathParameters in interface RequestSpecificationparameterNameValuePairs - A map containing the path parameters.public RequestSpecification pathParam(String parameterName, Object parameterValue)
RequestSpecificationRequestSpecification.pathParameter(String, Object).pathParam in interface RequestSpecificationparameterName - The parameter nameparameterValue - The parameter valueRequestSpecification.pathParameter(String, Object)public RequestSpecification pathParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
RequestSpecificationRequestSpecification.pathParameters(String, Object, Object...).pathParams in interface RequestSpecificationfirstParameterName - The name of the first parameterfirstParameterValue - The value of the first parameterparameterNameValuePairs - Additional parameters in name-value pairs.RequestSpecification.pathParameters(String, Object, Object...)public RequestSpecification pathParams(Map parameterNameValuePairs)
RequestSpecificationRequestSpecification.pathParameters(java.util.Map).pathParams in interface RequestSpecificationparameterNameValuePairs - A map containing the path parameters.RequestSpecification.pathParameters(java.util.Map)public RequestSpecification config(RestAssuredConfig config)
RequestSpecificationgiven().config(config().redirect(redirectConfig().followRedirects(true).and().maxRedirects(0))). ..
config() can be statically imported from RestAssuredConfig.config in interface RequestSpecificationconfig - The configuration to use for this request. If null no config will be used.public RequestSpecification keystore(String pathToJks, String password)
RequestSpecification
$ keytool -printcert -file EquifaxSecureGlobaleBusinessCA-1.crt Owner: CN=Equifax Secure Global eBusiness CA-1, O=Equifax Secure Inc., C=US Issuer: CN=Equifax Secure Global eBusiness CA-1, O=Equifax Secure Inc., C=US Serial number: 1 Valid from: Mon Jun 21 00:00:00 EDT 1999 until: Sun Jun 21 00:00:00 EDT 2020 Certificate fingerprints: MD5: 8F:5D:77:06:27:C4:98:3C:5B:93:78:E7:D7:7D:9B:CC SHA1: 7E:78:4A:10:1C:82:65:CC:2D:E1:F1:6D:47:B4:40:CA:D9:0A:19:45 Signature algorithm name: MD5withRSA Version: 3 ....Now, import that into a Java keystore file:
$ keytool -importcert -alias "equifax-ca" -file EquifaxSecureGlobaleBusinessCA-1.crt -keystore truststore_javanet.jks -storepass test1234 Owner: CN=Equifax Secure Global eBusiness CA-1, O=Equifax Secure Inc., C=US Issuer: CN=Equifax Secure Global eBusiness CA-1, O=Equifax Secure Inc., C=US Serial number: 1 Valid from: Mon Jun 21 00:00:00 EDT 1999 until: Sun Jun 21 00:00:00 EDT 2020 Certificate fingerprints: MD5: 8F:5D:77:06:27:C4:98:3C:5B:93:78:E7:D7:7D:9B:CC SHA1: 7E:78:4A:10:1C:82:65:CC:2D:E1:F1:6D:47:B4:40:CA:D9:0A:19:45 Signature algorithm name: MD5withRSA Version: 3 ... Trust this certificate? [no]: yes Certificate was added to keystoreNow you want to use this truststore in your client:
RestAssured.keystore("/truststore_javanet.jks", "test1234");
or
given().keystore("/truststore_javanet.jks", "test1234"). ..
Note that this is just a shortcut for:
given().config(RestAssured.config().sslConfig(sslConfig().keystore(pathToJks, password));
keystore in interface RequestSpecificationpathToJks - The path to the JKS. The path to the JKS. REST Assured will first look in the classpath and if not found it will look for the JKS in the local file-system.password - The store passpublic RequestSpecification keystore(File pathToJks, String password)
RequestSpecificationRequestSpecification.keystore(String, String) for more details.
Note that this is just a shortcut for:
given().config(RestAssured.config().sslConfig(sslConfig().keystore(pathToJks, password));
keystore in interface RequestSpecificationpathToJks - The path to JKS file on the file-systempassword - The password for the keystoreRequestSpecification.keystore(String, String)public RequestSpecification trustStore(KeyStore trustStore)
RequestSpecification
given().config(RestAssured.config().sslConfig(sslConfig().trustStore(truststore));
A trust store is a KeyStore that has been loaded with the password.
If you wish that REST Assured loads the KeyStore store and applies the password (thus making it a trust store) please see one of the
keystore methods such as RequestSpecification.keystore(String, String).
trustStore in interface RequestSpecificationtrustStore - The truststore.RequestSpecification.keystore(String, String)public RequestSpecification relaxedHTTPSValidation()
RequestSpecificationRequestSpecification.keystore(String, String) or trust store (see RequestSpecification.trustStore(java.security.KeyStore).
This is just a shortcut for:
given().config(RestAssured.config().sslConfig(sslConfig().relaxedHTTPSValidation())). ..;
relaxedHTTPSValidation in interface RequestSpecificationpublic RequestSpecification filter(Filter filter)
RequestSpecificationfilter in interface RequestSpecificationfilter - The filter to addpublic RequestSpecification filters(List<Filter> filters)
RequestSpecificationfilters in interface RequestSpecificationfilters - The filters to addpublic RequestSpecification filters(Filter filter, Filter... additionalFilter)
RequestSpecificationfilters in interface RequestSpecificationfilter - The filter to addadditionalFilter - Additional filters to addpublic RequestLogSpecification log()
RequestSpecificationRequestLogSpecification that allows you to log different parts of the RequestSpecification.
This is mainly useful for debug purposes when writing your tests. It's a shortcut for:
given().filter(new RequestLoggingFilter(..))). ..
log in interface RequestSpecificationpublic RequestSpecification and()
RequestSpecification
expect().body(containsString("OK")).and().body(containsString("something else")).when().get("/something");
is that same as:
expect().body(containsString("OK")).body(containsString("something else")).when().get("/something");
and in interface RequestSpecificationpublic RequestSpecification request()
RequestSpecification
given().request().param("name", "John").then().expect().body(containsString("OK")).when().get("/something");
is that same as:
given().param("name", "John").then().expect().body(containsString("OK")).when().get("/something");
request in interface RequestSpecificationpublic RequestSpecification with()
RequestSpecification
expect().body(containsString("OK")).and().with().request().parameters("param1", "value1").get("/something");
is that same as:
expect().body(containsString("OK")).and().request().parameters("param1", "value1").get("/something");
with in interface RequestSpecificationpublic ResponseSpecification then()
RequestSpecification
given().param("name", "value").then().body(equalTo("something")).when().get("/something");
then in interface RequestSpecificationpublic ResponseSpecification expect()
RequestSpecification
given().param("name", "value").and().expect().body(equalTo("something")).when().get("/something");
expect in interface RequestSpecificationpublic AuthenticationSpecification auth()
RequestSpecificationRequestSpecification.authentication().auth in interface RequestSpecificationRequestSpecification.authentication(),
AuthenticationSpecificationpublic AuthenticationSpecification authentication()
RequestSpecificationauthentication in interface RequestSpecificationAuthenticationSpecificationpublic RequestSpecification port(int port)
RequestSpecification
given().port(8081).and().expect().statusCode(200).when().get("/something");
will perform a GET request to http;//localhost:8081/something. It will override the default port of
REST assured for this request only.
Note that it's also possible to specify the port like this:
expect().statusCode(200).when().get("http://localhost:8081/something");
port in interface RequestSpecificationport - The port of URIpublic RequestSpecification body(String body)
RequestSpecificationExample of use:
given().body("{ \"message\" : \"hello world\"}").then().expect().body(equalTo("hello world")).when().post("/json");
This will POST a request containing JSON to "/json" and expect that the response body equals to "hello world".
Note that this method and RequestSpecification.content(String) are the same except for the syntactic difference.
body in interface RequestSpecificationbody - The body to send.public RequestSpecification content(String content)
RequestSpecificationExample of use:
given().content("{ \"message\" : \"hello world\"}").then().expect().content(equalTo("hello world")).when().post("/json");
This will POST a request containing JSON to "/json" and expect that the response content equals to "hello world".
Note that RequestSpecification.body(String) and this method are the same except for the syntactic difference.
content in interface RequestSpecificationcontent - The content to send.public RequestSpecification baseUri(String baseUri)
RequestSpecificationbaseUri in interface RequestSpecificationbaseUri - The uripublic RequestSpecification basePath(String basePath)
RequestSpecificationbasePath in interface RequestSpecificationbasePath - The base pathpublic RequestSpecification proxy(String host, int port)
RequestSpecificationproxy in interface RequestSpecificationhost - The hostname of the proxy to connect to (for example 127.0.0.1)port - The port of the proxy to connect to (for example 8888)public RequestSpecification proxy(String host)
RequestSpecification8888.proxy in interface RequestSpecificationhost - The hostname of the proxy to connect to (for example 127.0.0.1). Can also be a URI represented as a String.RequestSpecification.proxy(String, int)public RequestSpecification proxy(int port)
RequestSpecificationproxy in interface RequestSpecificationport - The port of the proxy to connect to (for example 8888)RequestSpecification.proxy(String, int)public RequestSpecification proxy(String host, int port, String scheme)
RequestSpecificationproxy in interface RequestSpecificationhost - The hostname of the proxy to connect to (for example 127.0.0.1)port - The port of the proxy to connect to (for example 8888)scheme - The http scheme (http or https)public RequestSpecification proxy(URI uri)
RequestSpecificationproxy in interface RequestSpecificationuri - The URI of the proxypublic RequestSpecification proxy(ProxySpecification proxySpecification)
RequestSpecificationProxySpecification.
For example:
given().
proxy(host("localhost").and().withPort(8888).and().withScheme("http")).
param("firstName", "John").
param("lastName", "Doe").
when().
get("/greetJSON").
then().
body("greeting.firstName", equalTo("John")).
body("greeting.lastName", equalTo("Doe"));
where host is statically imported from ProxySpecification.host(String).proxy in interface RequestSpecificationproxySpecification - The proxy specification to use.public RequestSpecification body(byte... body)
RequestSpecificationExample of use:
byte[] someBytes = ..
given().body(someBytes).then().expect().body(equalTo("hello world")).when().post("/json");
This will POST a request containing someBytes to "/json" and expect that the response body equals to "hello world".
Note that this method and RequestSpecification.content(byte[]) are the same except for the syntactic difference.
body in interface RequestSpecificationbody - The body to send.public RequestSpecification content(byte... content)
RequestSpecificationExample of use:
byte[] someBytes = ..
given().content(someBytes).then().expect().content(equalTo("hello world")).when().post("/json");
This will POST a request containing someBytes to "/json" and expect that the response content equals to "hello world".
Note that RequestSpecification.body(byte[]) and this method are the same except for the syntactic difference.
content in interface RequestSpecificationcontent - The content to send.public RequestSpecification body(Object object)
RequestSpecificationExample of use:
Message message = new Message();
message.setMessage("My beautiful message");
given().
contentType("application/json").
body(message).
expect().
content(equalTo("Response to a beautiful message")).
when().
post("/beautiful-message");
Since the content-type is "application/json" then REST Assured will automatically try to serialize the object using
Jackson or Gson if they are
available in the classpath. If any of these frameworks are not in the classpath then an exception is thrown.
Note that this method and RequestSpecification.content(Object) are the same except for the syntactic difference.
body in interface RequestSpecificationobject - The object to serialize and send with the requestpublic RequestSpecification content(Object object)
RequestSpecificationExample of use:
Message message = new Message();
message.setMessage("My beautiful message");
given().
contentType("application/json").
content(message).
expect().
content(equalTo("Response to a beautiful message")).
when().
post("/beautiful-message");
Since the content-type is "application/json" then REST Assured will automatically try to serialize the object using
Jackson or Gson if they are
available in the classpath. If any of these frameworks are not in the classpath then an exception is thrown.
Note that RequestSpecification.body(Object) and this method are the same except for the syntactic difference.
content in interface RequestSpecificationobject - The object to serialize and send with the requestpublic RequestSpecification body(Object object, ObjectMapper mapper)
RequestSpecificationExample of use:
Message message = new Message();
message.setMessage("My beautiful message");
given().
body(message, new MyObjectMapper()).
expect().
content(equalTo("Response to a beautiful message")).
when().
post("/beautiful-message");
Note that this method and RequestSpecification.content(Object, com.jayway.restassured.internal.mapper.ObjectMapperType) are the same except for the syntactic difference.
body in interface RequestSpecificationobject - The object to serialize and send with the requestmapper - The object mapperpublic RequestSpecification body(Object object, ObjectMapperType mapperType)
RequestSpecificationExample 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 method is the same as RequestSpecification.content(Object, ObjectMapperType) are the same except for the syntactic difference.
body in interface RequestSpecificationobject - The object to serialize and send with the requestmapperType - The object mapper type to be usedpublic RequestSpecification content(Object object, ObjectMapper mapper)
RequestSpecificationExample of use:
Message message = new Message();
message.setMessage("My beautiful message");
given().
content(message, new MyObjectMapper()).
expect().
content(equalTo("Response to a beautiful message")).
when().
post("/beautiful-message");
Note that RequestSpecification.body(Object, ObjectMapper) and this method are the same except for the syntactic difference.
content in interface RequestSpecificationobject - The object to serialize and send with the requestpublic RequestSpecification content(Object object, ObjectMapperType mapperType)
RequestSpecificationExample of use:
Message message = new Message();
message.setMessage("My beautiful message");
given().
content(message, ObjectMapperType.GSON).
expect().
content(equalTo("Response to a beautiful message")).
when().
post("/beautiful-message");
Note that RequestSpecification.body(Object, ObjectMapperType) and this method are the same except for the syntactic difference.
content in interface RequestSpecificationobject - The object to serialize and send with the requestmapperType - The object mapper type to usepublic RequestSpecification contentType(ContentType contentType)
RequestSpecificationcontentType in interface RequestSpecificationcontentType - The content type of the requestContentTypepublic RequestSpecification contentType(String contentType)
RequestSpecificationcontentType in interface RequestSpecificationcontentType - The content type of the requestContentTypepublic RequestSpecification headers(Map headers)
RequestSpecification
Map<String, String> headers = new HashMap<String, String>();
parameters.put("headerName1", "headerValue1");
parameters.put("headerName2", "headerValue2");
given().headers(headers).then().expect().body(equalTo("something")).when().get("/headers");
This will send a GET request to "/headers" with two headers:
headers in interface RequestSpecificationheaders - The Map containing the header names and their values to send with the request.public RequestSpecification headers(Headers headers)
RequestSpecificationHeaders, e.g:
Header first = new Header("headerName1", "headerValue1");
Header second = new Header("headerName2", "headerValue2");
Headers headers = new Header(first, second);
given().headers(headers).then().expect().body(equalTo("something")).when().get("/headers");
This will send a GET request to "/headers" with two headers:
headers in interface RequestSpecificationheaders - The headers to use in the requestpublic RequestSpecification header(String headerName, Object headerValue, Object... additionalHeaderValues)
RequestSpecification
given().header("username", "John").and().expect().body(equalTo("something")).when().get("/header");
This will set the header username=John in the GET request to "/header".
You can also specify several headers like this:
given().header("username", "John").and().header("zipCode", "12345").and().expect().body(equalTo("something")).when().get("/header");
If you specify additionalHeaderValues then the Header will be a multi-value header. This means that you'll create several headers with the
same name but with different values.header in interface RequestSpecificationheaderName - The header nameheaderValue - The header valueadditionalHeaderValues - Additional header values. This will actually create two headers with the same name but with different values.RequestSpecification.headers(String, Object, Object...)public RequestSpecification header(Header header)
RequestSpecificationHeader to send with the request.
Header someHeader = new Header("some_name", "some_value");
given().header(someHeader).and().expect().body(equalTo("x")).when().get("/header");
This will set the header some_name=some_value in the GET request to "/header".
header in interface RequestSpecificationheader - The header to add to the requestRequestSpecification.headers(com.jayway.restassured.response.Headers)public RequestSpecification headers(String firstHeaderName, Object firstHeaderValue, Object... headerNameValuePairs)
RequestSpecification
given().headers("headerName1", "headerValue1", "headerName2", "headerValue2").then().expect().body(equalTo("something")).when().get("/headers");
This will send a GET request to "/headers" with two headers:
headers in interface RequestSpecificationfirstHeaderName - The name of the first headerfirstHeaderValue - The value of the first headerheaderNameValuePairs - Additional headers in name-value pairs.public RequestSpecification cookies(String firstCookieName, Object firstCookieValue, Object... cookieNameValuePairs)
RequestSpecification
given().cookies("username", "John", "token", "1234").then().expect().body(equalTo("username, token")).when().get("/cookie");
This will send a GET request to "/cookie" with two cookies:
cookies in interface RequestSpecificationfirstCookieName - The name of the first cookiefirstCookieValue - The value of the first cookiecookieNameValuePairs - Additional cookies in name-value pairs.public RequestSpecification cookies(Map cookies)
RequestSpecification
Map<String, String> cookies = new HashMap<String, String>();
cookies.put("username", "John");
cookies.put("token", "1234");
given().cookies(cookies).then().expect().body(equalTo("username, token")).when().get("/cookie");
This will send a GET request to "/cookie" with two cookies:
cookies in interface RequestSpecificationcookies - The Map containing the cookie names and their values to set in the request.public RequestSpecification cookies(Cookies cookies)
RequestSpecificationCookies:
Cookie cookie1 = Cookie.Builder("username", "John").setComment("comment 1").build();
Cookie cookie2 = Cookie.Builder("token", 1234).setComment("comment 2").build();
Cookies cookies = new Cookies(cookie1, cookie2);
given().cookies(cookies).then().expect().body(equalTo("username, token")).when().get("/cookie");
This will send a GET request to "/cookie" with two cookies:
cookies in interface RequestSpecificationcookies - The cookies to set in the request.public RequestSpecification cookie(String cookieName, Object value, Object... additionalValues)
RequestSpecification
given().cookie("username", "John").and().expect().body(equalTo("username")).when().get("/cookie");
This will set the cookie username=John in the GET request to "/cookie".
You can also specify several cookies like this:
given().cookie("username", "John").and().cookie("password", "1234").and().expect().body(equalTo("username")).when().get("/cookie");
If you specify additionalValues then the Cookie will be a multi-value cookie. This means that you'll create several cookies with the
same name but with different values.cookie in interface RequestSpecificationcookieName - The cookie cookieNamevalue - The cookie valueadditionalValues - Additional cookies values. This will actually create two cookies with the same name but with different values.RequestSpecification.cookies(String, Object, Object...)public RequestSpecification cookie(Cookie cookie)
RequestSpecificationCookie to send with the request.
Cookie someCookie = new Cookie.Builder("some_cookie", "some_value").setSecured(true).build();
given().cookie(someCookie).and().expect().body(equalTo("x")).when().get("/cookie");
This will set the cookie someCookie in the GET request to "/cookie".
cookie in interface RequestSpecificationcookie - The cookie to add to the requestRequestSpecification.cookies(com.jayway.restassured.response.Cookies)public RequestSpecification cookie(String cookieName)
RequestSpecification
given().cookie("some_cookie").and().expect().body(equalTo("x")).when().get("/cookie");
This will set the cookie some_cookie in the GET request to "/cookie".
cookie in interface RequestSpecificationcookieName - The cookie cookieNameRequestSpecification.cookies(String, Object, Object...)public RedirectSpecification redirects()
RequestSpecificationgiven().redirects().max(12).and().redirects().follow(true).when(). ..
redirects in interface RequestSpecificationpublic RequestSpecification spec(RequestSpecification requestSpecificationToMerge)
RequestSpecification
RequestSpecification requestSpec = new RequestSpecBuilder().addParam("parameter1", "value1").build();
given().
spec(requestSpec).
param("parameter2", "value2").
when().
get("/something");
This is useful when you want to reuse an entire specification across multiple requests.
The specification passed to this method is merged with the current specification. Note that the supplied specification
can overwrite data in the current specification. The following settings are overwritten:
RequestSpecification.specification(RequestSpecification) but the name is a bit shorter.spec in interface RequestSpecificationrequestSpecificationToMerge - The specification to merge with.public RequestSpecification specification(RequestSpecification requestSpecificationToMerge)
RequestSpecification
RequestSpecification requestSpec = new RequestSpecBuilder().addParam("parameter1", "value1").build();
given().
spec(requestSpec).
param("parameter2", "value2").
when().
get("/something");
This is useful when you want to reuse an entire specification across multiple requests.
The specification passed to this method is merged with the current specification. Note that the supplied specification
can overwrite data in the current specification. The following settings are overwritten:
RequestSpecification.spec(RequestSpecification) but the name is a bit longer and thus more descriptive.specification in interface RequestSpecificationrequestSpecificationToMerge - The specification to merge with.public RequestSpecification sessionId(String sessionIdValue)
RequestSpecification
RestAssured.config = newConfig().sessionConfig(new SessionConfig().sessionIdName(<sessionIdName>));
or you can use the RequestSpecification.sessionId(String, String) method to set it for this request only.sessionId in interface RequestSpecificationsessionIdValue - The session id value.public RequestSpecification sessionId(String sessionIdName, String sessionIdValue)
RequestSpecification
RestAssured.config = newConfig().sessionConfig(new SessionConfig().sessionIdName(<sessionIdName>));
and then you can use the RequestSpecification.sessionId(String) method to set the session id value without specifying the name for each request.sessionId in interface RequestSpecificationsessionIdName - The session id namesessionIdValue - The session id value.public RequestSpecification multiPart(MultiPartSpecification multiPartSpec)
RequestSpecificationmultiPart in interface RequestSpecificationmultiPartSpec - Multipart specificationpublic RequestSpecification multiPart(String controlName, File file)
RequestSpecificationmultiPart in interface RequestSpecificationcontrolName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.file - The file to uploadpublic RequestSpecification multiPart(File file)
RequestSpecificationmultiPart in interface RequestSpecificationfile - The file to uploadpublic RequestSpecification multiPart(String name, File file, String mimeType)
RequestSpecificationmultiPart in interface RequestSpecificationname - Defines the control name of the body part. In HTML this is the attribute name of the input tag.file - The file to uploadmimeType - The mime-typepublic RequestSpecification multiPart(String controlName, Object object)
RequestSpecificationmultiPart in interface RequestSpecificationcontrolName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.object - The object to serialize to JSON or XML and send to the serverpublic RequestSpecification multiPart(String controlName, Object object, String mimeType)
RequestSpecificationmultiPart in interface RequestSpecificationcontrolName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.object - The object to serialize to JSON or XML and send to the servermimeType - The mime-typepublic RequestSpecification multiPart(String name, String fileName, byte... bytes)
RequestSpecificationmultiPart in interface RequestSpecificationname - 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 RequestSpecification multiPart(String name, String fileName, byte[] bytes, String mimeType)
RequestSpecificationmultiPart in interface RequestSpecificationname - 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 mime-typepublic RequestSpecification multiPart(String name, String fileName, InputStream stream)
RequestSpecificationmultiPart in interface RequestSpecificationname - 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 RequestSpecification multiPart(String name, String fileName, InputStream stream, String mimeType)
RequestSpecificationmultiPart in interface RequestSpecificationname - 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 mime-typepublic RequestSpecification multiPart(String name, String contentBody)
RequestSpecificationmultiPart in interface RequestSpecificationname - Defines the control name of the body part. In HTML this is the attribute name of the input tag.contentBody - The string to sendpublic RequestSpecification multiPart(String name, NoParameterValue contentBody)
public RequestSpecification multiPart(String name, String contentBody, String mimeType)
RequestSpecificationmultiPart in interface RequestSpecificationname - 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 Object invokeFilterChain(Object path, Object method, Object assertionClosure)
public boolean shouldApplySSLConfig(Object http, RestAssuredConfig cfg)
public Object applyRestAssuredConfig(HTTPBuilder http)
public Object applySessionConfig(SessionConfig sessionConfig)
public Object applyEncoderConfig(HTTPBuilder httpBuilder, EncoderConfig encoderConfig)
public Object applyHttpClientConfig(HttpClientConfig httpClientConfig)
public Object applyRedirectConfig(RedirectConfig redirectConfig)
public Object mergeMapsAndRetainOrder(Map<String,Object> map1, Map<String,Object> map2)
public Object setRequestHeadersToHttpBuilder(HTTPBuilder http)
public void setResponseSpecification(ResponseSpecification responseSpecification)
public String getBaseUri()
getBaseUri in interface FilterableRequestSpecificationpublic String getBasePath()
getBasePath in interface FilterableRequestSpecificationpublic int getPort()
getPort in interface FilterableRequestSpecificationpublic Map<String,Object> getFormParams()
getFormParams in interface FilterableRequestSpecificationpublic Map<String,Object> getPathParams()
getPathParams in interface FilterableRequestSpecificationpublic Map<String,Object> getRequestParams()
getRequestParams in interface FilterableRequestSpecificationpublic Map<String,Object> getQueryParams()
getQueryParams in interface FilterableRequestSpecificationpublic List<MultiPartSpecification> getMultiPartParams()
getMultiPartParams in interface FilterableRequestSpecificationpublic Headers getHeaders()
getHeaders in interface FilterableRequestSpecificationpublic Cookies getCookies()
getCookies in interface FilterableRequestSpecificationpublic <T> T getBody()
getBody in interface FilterableRequestSpecificationpublic List<Filter> getDefinedFilters()
getDefinedFilters in interface FilterableRequestSpecificationpublic RestAssuredConfig getConfig()
getConfig in interface FilterableRequestSpecificationpublic org.apache.http.client.HttpClient getHttpClient()
getHttpClient in interface FilterableRequestSpecificationAbstractHttpClient is used by REST Assured.public ProxySpecification getProxySpecification()
getProxySpecification in interface FilterableRequestSpecificationnull if undefined.public String getRequestContentType()
getRequestContentType in interface FilterableRequestSpecificationpublic RequestSpecification noFilters()
RequestSpecificationnoFilters in interface RequestSpecificationpublic <T extends Filter> RequestSpecification noFiltersOfType(Class<T> filterType)
RequestSpecificationnoFiltersOfType in interface RequestSpecificationpublic RestAssuredConfig restAssuredConfig()
Copyright © 2010–2014. All rights reserved.