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,
RequestSpecification defaultSpec,
boolean urlEncode,
RestAssuredConfig restAssuredConfig,
LogRepository logRepository,
ProxySpecification proxySpecification) |
| Modifier and Type | Method and Description |
|---|---|
RequestSpecification |
accept(ContentType contentType)
Specify the accept header of the request.
|
RequestSpecification |
accept(String mediaTypes)
Specify the accept header of the request.
|
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) |
void |
assertCorrectNumberOfPathParams() |
AuthenticationSpecification |
auth()
Specify authentication credentials when performing a request.
|
AuthenticationSpecification |
authentication()
If you need to specify some credentials when performing a request.
|
RequestSpecification |
basePath(String basePath)
Set the basePath property of 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(File body)
Specify file content that'll be sent with the request.
|
RequestSpecification |
body(InputStream body)
Specify file content 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.
|
void |
buildUnnamedPathParameterTuples(Object... unnamedPathParameterValues) |
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(File content)
Specify file content that'll be sent with the request.
|
RequestSpecification |
content(InputStream content)
Specify file 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)
Specify a multi-value form parameter that'll be sent with the request e.g:
|
RequestSpecification |
formParam(String parameterName,
Object... parameterValues)
Specify a form parameter that'll be sent with the request.
|
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)
Specify the form parameters that'll be sent with the request.
|
RequestSpecification |
formParams(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
Specify the form parameters that'll be sent with the request.
|
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() |
String |
getContentType() |
Cookies |
getCookies() |
List<Filter> |
getDefinedFilters() |
String |
getDerivedPath() |
static String |
getDerivedPath(String uri) |
Map<String,String> |
getFormParams() |
Headers |
getHeaders() |
org.apache.http.client.HttpClient |
getHttpClient() |
groovy.lang.MetaClass |
getMetaClass() |
String |
getMethod() |
List<MultiPartSpecification> |
getMultiPartParams() |
Map<String,String> |
getNamedPathParams() |
List<String> |
getPathParamPlaceholders()
Returns a list of all path param placeholders that are currently undefined in the request.
|
Map<String,String> |
getPathParams() |
static List |
getPlaceholders(String uri) |
int |
getPort() |
Object |
getProperty(String property) |
ProxySpecification |
getProxySpecification() |
Map<String,String> |
getQueryParams() |
Map<String,String> |
getRedundantNamedPathParams() |
List<String> |
getRedundantUnnamedPathParamValues() |
String |
getRequestContentType() |
Map<String,String> |
getRequestParams() |
List<String> |
getUndefinedPathParamPlaceholders()
Returns a list of all path param placeholders that are currently undefined in the request.
|
Map<String,String> |
getUnnamedPathParams()
Return the unnamed path parameters defined in the request specification as a map.
|
List<String> |
getUnnamedPathParamValues() |
String |
getURI() |
String |
getURI(String uri) |
String |
getUserDefinedPath()
Returns the original request path as it was before any path parameters were applied.
|
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 |
invokeMethod(String method,
Object arguments) |
RequestSpecification |
keyStore(File pathToJks,
String password)
Use a keystore located on the file-system.
|
RequestSpecification |
keyStore(KeyStore keyStore)
Use the supplied keystore for HTTPS requests.
|
RequestSpecification |
keyStore(String pathToJks,
String password)
The following documentation is taken from https://github.com/jgritman/httpbuilder/wiki/SSL:
|
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 controlName,
File file,
String mimeType)
Specify a file to upload to the server using multi-part form data uploading with a specific
control name and 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 controlName,
String filename,
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,
String mimeType)
Specify a string to send to the server using multi-part form data with a specific mime-type.
|
Object |
newFilterContext(Object assertionClosure,
Object filters,
Object properties) |
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)
Specify a multi-value parameter that'll be sent with the request e.g:
|
RequestSpecification |
param(String parameterName,
Object... parameterValues)
Specify a parameter that'll be sent with the request e.g:
|
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)
Specify the parameters that'll be sent with the request as Map e.g:
|
RequestSpecification |
params(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
Specify the parameters that'll be sent with the request.
|
String |
partiallyApplyPathParams(String path,
boolean encodePath,
List<String> unnamedPathParams) |
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. |
FilterableRequestSpecification |
path(String path)
Set the request path of the request specification.
|
RequestSpecification |
pathParam(String parameterName,
Object parameterValue)
Specify a path parameter.
|
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)
Specify multiple path parameter name-value pairs.
|
RequestSpecification |
pathParams(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
Specify multiple path parameter name-value pairs.
|
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)
Specify a multi-value query parameter that'll be sent with the request e.g:
|
RequestSpecification |
queryParam(String parameterName,
Object... parameterValues)
Specify a query parameter that'll be sent with the request.
|
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)
Specify the query parameters that'll be sent with the request.
|
RequestSpecification |
queryParams(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
Specify the query parameters that'll be sent with the request.
|
RedirectSpecification |
redirects()
Specify the redirect configuration for this request.
|
RequestSpecification |
relaxedHTTPSValidation()
Use relaxed HTTP validation with SSLContext protocol SSL.
|
RequestSpecification |
relaxedHTTPSValidation(String protocol)
Use relaxed HTTP validation with the given SSLContext protocol.
|
FilterableRequestSpecification |
removeCookie(Cookie cookie)
Remove a cookie
|
FilterableRequestSpecification |
removeCookie(String cookieName)
Remove a cookie with the given name.
|
FilterableRequestSpecification |
removeCookies()
Removed all defined cookies
|
FilterableRequestSpecification |
removeFormParam(String parameterName)
Remove a form parameter from the request.
|
FilterableRequestSpecification |
removeHeader(String headerName)
Remove a header with the given name.
|
FilterableRequestSpecification |
removeHeaders()
Removes all defined headers
|
FilterableRequestSpecification |
removeNamedPathParam(String parameterName)
Remove a named path parameter from the request.
|
FilterableRequestSpecification |
removeParam(String parameterName)
Remove a request parameter from the request.
|
FilterableRequestSpecification |
removePathParam(String parameterName)
Remove a path parameter from the request.
|
FilterableRequestSpecification |
removeQueryParam(String parameterName)
Remove a query parameter from the request.
|
FilterableRequestSpecification |
removeUnnamedPathParam(String parameterName)
Remove an unnamed path parameter from the request.
|
void |
removeUnnamedPathParamAtIndex(int indexOfParamName) |
FilterableRequestSpecification |
removeUnnamedPathParamByValue(String parameterValue)
Remove the first unnamed path parameter from the request based on its value.
|
FilterableRequestSpecification |
replaceCookie(Cookie cookie)
Replace a cookie, if it doesn't exist then it will be added.
|
FilterableRequestSpecification |
replaceCookie(String cookieName,
String value)
Replace a cookie with the given name.
|
FilterableRequestSpecification |
replaceCookies(Cookies cookies)
Replace all defined cookies
|
FilterableRequestSpecification |
replaceHeader(String headerName,
String newValue)
Replace a header with the new value.
|
FilterableRequestSpecification |
replaceHeaders(Headers headers)
Replace all defined headers
|
RequestSpecification |
request()
Syntactic sugar, e.g.
|
Response |
request(Method method)
Perform a request to the pre-configured path (by default
http://localhost:8080). |
Response |
request(Method method,
String path,
Object... pathParams)
Perform a HTTP request to a
path. |
Response |
request(Method method,
URI uri)
Perform a request to a
uri. |
Response |
request(Method method,
URL url)
Perform a request to a
url. |
Response |
request(String method)
Perform a custom HTTP request to the pre-configured path (by default
http://localhost:8080). |
Response |
request(String method,
String path,
Object... pathParams)
Perform a custom HTTP request to a
path. |
Response |
request(String method,
URI uri)
Perform a custom HTTP request to a
uri. |
Response |
request(String method,
URL url)
Perform a custom HTTP request to a
url. |
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 |
setMethod(String method) |
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(File path,
String password)
Use a trust store located on the file-system.
|
RequestSpecification |
trustStore(KeyStore trustStore)
Use the supplied truststore for HTTPS requests.
|
RequestSpecification |
trustStore(String path,
String password)
Apply a trust store.
|
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, 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 request(Method method)
RequestSenderOptionshttp://localhost:8080).request in interface RequestSenderOptions<Response>method - The HTTP method to usepublic Response request(String method)
RequestSenderOptionshttp://localhost:8080).request in interface RequestSenderOptions<Response>method - The HTTP method to usepublic Response request(Method method, 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.request in interface RequestSenderOptions<Response>method - The HTTP method to usepath - The path to send the request to.pathParams - The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do request(Method.TRACE,"/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);.public Response request(String method, 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.request in interface RequestSenderOptions<Response>method - The HTTP method to usepath - The path to send the request to.pathParams - The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do request("method","/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);.public Response request(Method method, URI uri)
RequestSenderOptionsuri.request in interface RequestSenderOptions<Response>method - The HTTP method to useuri - The uri to send the request to.public Response request(Method method, URL url)
RequestSenderOptionsurl.request in interface RequestSenderOptions<Response>method - The HTTP method to useurl - The url to send the request to.public Response request(String method, URI uri)
RequestSenderOptionsuri.request in interface RequestSenderOptions<Response>method - The HTTP method to useuri - The uri to send the request to.public Response request(String method, URL url)
RequestSenderOptionsurl.request in interface RequestSenderOptions<Response>method - The HTTP method to useurl - The url to send the request to.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)
RequestSpecification
given().params("username", "John", "token", "1234").when().get("/parameters").then().assertThat().body(equalTo("username, token"));
This will send a GET request to "/parameters" with two parameters:
params in interface RequestSpecificationfirstParameterName - The name of the first parameterfirstParameterValue - The value of the first parameterparameterNameValuePairs - Additional parameters in name-value pairs.public RequestSpecification params(Map parametersMap)
RequestSpecification
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("username", "John");
parameters.put("token", "1234");
given().params(parameters).when().get("/cookie").then().assertThat().body(equalTo("username, token"));
This will send a GET request to "/cookie" with two parameters:
params in interface RequestSpecificationparametersMap - The Map containing the parameter names and their values to send with the request.public RequestSpecification param(String parameterName, Object... parameterValues)
RequestSpecification
given().param("username", "John").when().get("/cookie").then().assertThat().body(equalTo("username"));
This will set the parameter username=John in the GET request to "/cookie".
You can also specify several parameters like this:
given().param("username", "John").and().param("password", "1234").when().get("/cookie").then().assertThat().body(equalTo("username"));
param in interface RequestSpecificationparameterName - The parameter nameparameterValues - Parameter values, one to many if you want to specify multiple values for the same parameter.RequestSpecification.param(String, Object...)public FilterableRequestSpecification removeParam(String parameterName)
FilterableRequestSpecificationremoveParam in interface FilterableRequestSpecificationparameterName - The parameter keyFilterableRequestSpecification without the parameterpublic 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)
RequestSpecification
given().param("cars", asList("Volvo", "Saab"))..;
This will set the parameter cars=Volvo and cars=Saab.
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)
RequestSpecification
given().queryParam("cars", asList("Volvo", "Saab"))..;
This will set the parameter cars=Volvo and cars=Saab.
Note that this method is the same as RequestSpecification.param(String, java.util.Collection)
for all http methods except for POST where RequestSpecification.param(String, java.util.Collection) adds a form parameter and
this method sets a query parameter.queryParam in interface RequestSpecificationparameterName - The parameter nameparameterValues - The parameter valuespublic FilterableRequestSpecification removeQueryParam(String parameterName)
FilterableRequestSpecificationremoveQueryParam in interface FilterableRequestSpecificationparameterName - The parameter keyFilterableRequestSpecification without the parameterpublic FilterableRequestSpecification removeHeader(String headerName)
FilterableRequestSpecificationremoveHeader in interface FilterableRequestSpecificationheaderName - The header nameFilterableRequestSpecification without the specified headerpublic FilterableRequestSpecification removeCookie(String cookieName)
FilterableRequestSpecificationremoveCookie in interface FilterableRequestSpecificationcookieName - The cookie nameFilterableRequestSpecification without the specified cookiepublic FilterableRequestSpecification removeCookie(Cookie cookie)
FilterableRequestSpecificationremoveCookie in interface FilterableRequestSpecificationcookie - The cookieFilterableRequestSpecification without the specified cookiepublic FilterableRequestSpecification replaceHeader(String headerName, String newValue)
FilterableRequestSpecificationreplaceHeader in interface FilterableRequestSpecificationheaderName - The header name to replaceFilterableRequestSpecification with the replaced headerpublic FilterableRequestSpecification replaceCookie(String cookieName, String value)
FilterableRequestSpecificationreplaceCookie in interface FilterableRequestSpecificationcookieName - The cookie nameFilterableRequestSpecification with the replaced cookiepublic FilterableRequestSpecification replaceCookie(Cookie cookie)
FilterableRequestSpecificationreplaceCookie in interface FilterableRequestSpecificationcookie - The cookieFilterableRequestSpecification with the replaced cookiepublic FilterableRequestSpecification replaceHeaders(Headers headers)
FilterableRequestSpecificationreplaceHeaders in interface FilterableRequestSpecificationheaders - The new headersFilterableRequestSpecification with the replaced headerspublic FilterableRequestSpecification replaceCookies(Cookies cookies)
FilterableRequestSpecificationreplaceCookies in interface FilterableRequestSpecificationcookies - The new cookiesFilterableRequestSpecification with the replaced cookiespublic FilterableRequestSpecification removeHeaders()
FilterableRequestSpecificationremoveHeaders in interface FilterableRequestSpecificationFilterableRequestSpecification withoutpublic FilterableRequestSpecification removeCookies()
FilterableRequestSpecificationremoveCookies in interface FilterableRequestSpecificationFilterableRequestSpecification with the replaced cookiespublic 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 parameterpublic RequestSpecification queryParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
RequestSpecificationRequestSpecification.params(String, Object, Object...)
for all http methods except for POST where RequestSpecification.params(String, Object, Object...) sets the form parameters and this method sets the
query parameters.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.params(Map)
for all http methods except for POST where RequestSpecification.params(Map) sets the form parameters and this method sets the
query parameters.queryParams in interface RequestSpecificationparametersMap - The Map containing the parameter names and their values to send with the request.public RequestSpecification queryParam(String parameterName, Object... parameterValues)
RequestSpecificationRequestSpecification.param(String, Object...)
for all http methods except for POST where RequestSpecification.param(String, Object...) adds a form parameter and this method sets a
query parameter.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.param(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)
RequestSpecification
given().formParam("cars", asList("Volvo", "Saab"))..;
This will set the parameter cars=Volvo and cars=Saab.
Note that this method is the same as RequestSpecification.param(String, java.util.Collection)
for all http methods except for PUT where RequestSpecification.param(String, java.util.Collection) adds a query parameter and
this method sets a form parameter.formParam in interface RequestSpecificationparameterName - The parameter nameparameterValues - The parameter valuesRequestSpecification.formParam(String, java.util.Collection)public FilterableRequestSpecification removeFormParam(String parameterName)
FilterableRequestSpecificationremoveFormParam in interface FilterableRequestSpecificationparameterName - The parameter keyFilterableRequestSpecification without the parameterpublic 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.params(String, Object, Object...)
for all http methods except for PUT where RequestSpecification.params(String, Object, Object...) sets the query parameters and this method sets the
form parameters.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.parameters(Map)
for all http methods except for PUT where RequestSpecification.params(Map) sets the query parameters and this method sets the
form parameters.formParams in interface RequestSpecificationparametersMap - The Map containing the form parameter names and their values to send with the request.RequestSpecification.formParams(java.util.Map)public RequestSpecification formParam(String parameterName, Object... parameterValues)
RequestSpecificationRequestSpecification.parameter(String, Object...)
for all http methods except for PUT where RequestSpecification.param(String, Object...) adds a query parameter and this method sets a
form parameter.formParam in interface RequestSpecificationparameterName - The parameter nameparameterValues - Zero to many parameter values. You can specify multiple values for the same parameter.RequestSpecification.param(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)
RequestSpecification
when().
get("/item/"+myItem.getItemNumber()+"/buy/"+2).
then().
statusCode(200);
you can write:
given().
pathParameter("itemNumber", myItem.getItemNumber()).
pathParameter("amount", 2).
when().
get("/item/{itemNumber}/buy/{amount}").
then().
statusCode(200);
which improves readability and allows the path to be reusable in many tests. Another alternative is to use:
when().get("/item/{itemNumber}/buy/{amount}", myItem.getItemNumber(), 2).then().statusCode(200).;
pathParam in interface RequestSpecificationparameterName - The parameter nameparameterValue - The parameter valuepublic RequestSpecification pathParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
RequestSpecification
when().
get("/item/"+myItem.getItemNumber()+"/buy/"+2).
then().
statusCode(200).
you can write:
given().
pathParams("itemNumber", myItem.getItemNumber(), "amount", 2).
when().
get("/item/{itemNumber}/buy/{amount}").
then().
statusCode(200);
which improves readability and allows the path to be reusable in many tests. Another alternative is to use:
when().get("/item/{itemNumber}/buy/{amount}", myItem.getItemNumber(), 2).then().statusCode(200);
pathParams in interface RequestSpecificationfirstParameterName - The name of the first parameterfirstParameterValue - The value of the first parameterparameterNameValuePairs - Additional parameters in name-value pairs.public RequestSpecification pathParams(Map parameterNameValuePairs)
RequestSpecification
when().
get("/item/"+myItem.getItemNumber()+"/buy/"+2).
then().
statusCode(200);
you can write:
Map<String,Object> pathParams = new HashMap<String,Object>();
pathParams.add("itemNumber",myItem.getItemNumber());
pathParams.add("amount",2);
given().
pathParams(pathParams).
when().
get("/item/{itemNumber}/buy/{amount}").
then().
statusCode(200);
which improves readability and allows the path to be reusable in many tests. Another alternative is to use:
when().get("/item/{itemNumber}/buy/{amount}", myItem.getItemNumber(), 2).then().statusCode(200);
pathParams in interface RequestSpecificationparameterNameValuePairs - A map containing the path parameters.RequestSpecification.pathParameters(java.util.Map)public FilterableRequestSpecification removePathParam(String parameterName)
FilterableRequestSpecificationremovePathParam in interface FilterableRequestSpecificationparameterName - The parameter keyFilterableRequestSpecification without the parameterpublic FilterableRequestSpecification removeNamedPathParam(String parameterName)
FilterableRequestSpecificationremoveNamedPathParam in interface FilterableRequestSpecificationparameterName - The parameter keyFilterableRequestSpecification without the parameterpublic FilterableRequestSpecification removeUnnamedPathParam(String parameterName)
FilterableRequestSpecificationremoveUnnamedPathParam in interface FilterableRequestSpecificationparameterName - The parameter keyFilterableRequestSpecification without the parameterpublic FilterableRequestSpecification removeUnnamedPathParamByValue(String parameterValue)
FilterableRequestSpecificationremoveUnnamedPathParamByValue in interface FilterableRequestSpecificationparameterValue - The parameter keyFilterableRequestSpecification without the parameterpublic 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(String path, String password)
RequestSpecification
given().trustStore("/truststore_javanet.jks", "test1234"). ..
Note that this is just a shortcut for:
given().config(RestAssured.config().sslConfig(sslConfig().trustStore(pathToJks, password));
trustStore in interface RequestSpecificationpath - The path to the trust store. 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 trustStore(File path, String password)
RequestSpecificationRequestSpecification.trustStore(String, String) for more details.
Note that this is just a shortcut for:
given().config(RestAssured.config().sslConfig(sslConfig().trustStore(pathToJks, password));
trustStore in interface RequestSpecificationpath - The path to trust storefile 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));
trustStore in interface RequestSpecificationtrustStore - The truststore.RequestSpecification.keyStore(String, String)public RequestSpecification keyStore(KeyStore keyStore)
RequestSpecification
given().config(RestAssured.config().sslConfig(sslConfig().keyStore(keyStore));
keyStore in interface RequestSpecificationkeyStore - The keyStore.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 relaxedHTTPSValidation(String protocol)
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(<protocol>))). ..;
relaxedHTTPSValidation in interface RequestSpecificationprotocol - The standard name of the requested protocol. See the SSLContext section in the Java Cryptography Architecture Standard Algorithm Name Documentation for information about standard protocol names.public 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()
RequestSpecificationauth in interface RequestSpecificationAuthenticationSpecificationpublic 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\"}").when().post("/json").then().assertThat().body(equalTo("hello world"));
This will POST a request containing JSON to "/json" and expect that the response body equals to "hello world".
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 body(File body)
RequestSpecificationExample of use:
File myFile = ..
given().body(myFile).when().post("/json").then().content(equalTo("hello world"));
This will POST a request containing myFile to "/json" and expect that the response content equals to "hello world".
body in interface RequestSpecificationbody - The content to send.public RequestSpecification body(InputStream body)
RequestSpecificationExample of use:
InputStream myInputStream = ..
given().body(myInputStream).when().post("/json").then().content(equalTo("hello world"));
This will POST a request containing myInputStream to "/json" and expect that the response content equals to "hello world".
body in interface RequestSpecificationbody - The content 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 content(File content)
RequestSpecificationExample of use:
File myFile = ..
given().content(myFile).when().post("/json").then().content(equalTo("hello world"));
This will POST a request containing myFile to "/json" and expect that the response content equals to "hello world".
Note that RequestSpecification.body(File) and this method are the same except for the syntactic difference.
content in interface RequestSpecificationcontent - The content to send.public RequestSpecification content(InputStream content)
RequestSpecificationExample of use:
InputStream myInputStream = ..
given().content(myInputStream).when().post("/json").then().content(equalTo("hello world"));
This will POST a request containing myInputStream to "/json" and expect that the response content equals to "hello world".
Note that RequestSpecification.body(java.io.InputStream) 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).
when().
post("/beautiful-message").
then().
body(equalTo("Response to a 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.
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()).
when().
post("/beautiful-message").
then().
body(equalTo("Response to a beautiful message")).
Note that this method and RequestSpecification.content(Object, 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).
when().
post("/beautiful-message").
when().
body(equalTo("Response to a beautiful message")).
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 accept(ContentType contentType)
RequestSpecification
header("Accept", contentType);
accept in interface RequestSpecificationcontentType - The content type whose accept header ContentType.getAcceptHeader() will be used as Accept header in the request.ContentType,
RequestSpecification.header(String, Object, Object...)public RequestSpecification accept(String mediaTypes)
RequestSpecification
header("Accept", contentType);
accept in interface RequestSpecificationmediaTypes - The media type(s) that will be used as Accept header in the request.ContentType,
RequestSpecification.header(String, Object, Object...)public 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(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(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 controlName, File file, 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.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 controlName, String filename, 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.filename - The name of the content you're uploadingobject - 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 newFilterContext(Object assertionClosure, Object filters, Object properties)
public void assertCorrectNumberOfPathParams()
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 buildUnnamedPathParameterTuples(Object... unnamedPathParameterValues)
public String partiallyApplyPathParams(String path, boolean encodePath, List<String> unnamedPathParams)
public void setResponseSpecification(ResponseSpecification responseSpecification)
public String getBaseUri()
getBaseUri in interface FilterableRequestSpecificationpublic String getBasePath()
getBasePath in interface FilterableRequestSpecificationpublic String getDerivedPath()
getDerivedPath in interface FilterableRequestSpecificationpublic String getUserDefinedPath()
FilterableRequestSpecification
get("/something/{x}", x);
Then this method would return "/something/{x}".getUserDefinedPath in interface FilterableRequestSpecificationpublic String getMethod()
getMethod in interface FilterableRequestSpecificationpublic String getURI()
getURI in interface FilterableRequestSpecificationpublic int getPort()
getPort in interface FilterableRequestSpecificationpublic Map<String,String> getFormParams()
getFormParams in interface FilterableRequestSpecificationpublic Map<String,String> getPathParams()
getPathParams in interface FilterableRequestSpecificationpublic Map<String,String> getNamedPathParams()
getNamedPathParams in interface FilterableRequestSpecificationpublic Map<String,String> getUnnamedPathParams()
FilterableRequestSpecification
get("/{x}/{y}", "one", "two");
then this method will return { "x" : "one, "y" : "two" }. But if the request is missing the an unnamed path param for "y":
get("/{x}/{y}", "one");
then this method will return { "x" : "one" }.
If the request is defined like this:
get("/{x}/{y}", "one", "two", "three");
then this method will return { "x" : "one, "y" : "two" }.
If all you want is a list of the supplied unnamed path parameter (values) use FilterableRequestSpecification.getUnnamedPathParamValues().getUnnamedPathParams in interface FilterableRequestSpecificationpublic List<String> getUnnamedPathParamValues()
getUnnamedPathParamValues in interface FilterableRequestSpecificationFilterableRequestSpecification.getUnnamedPathParams()public Map<String,String> getRequestParams()
getRequestParams in interface FilterableRequestSpecificationpublic Map<String,String> 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 FilterableRequestSpecification path(String path)
FilterableRequestSpecification
get("/x");
You can change to path to "/y" instead using this method. This will result in a request that looks like this:
get("/y");
path in interface FilterableRequestSpecificationpath - The pathpublic List<String> getUndefinedPathParamPlaceholders()
FilterableRequestSpecification
get("/{x}/{y}");
Calling getPathParamPlaceholder() will return a list with "x" and "y". Note that if you have a path like this:
get("/{x}/{x}");
the list will include "x" twice. Also note that this function will only return those placeholders that are not yet defined.
I.e. calling this method when the request is defined like this:
get("/{x}/{y}", "something");
will only return a list of "y". Use FilterableRequestSpecification.getPathParamPlaceholders() to get ALL placeholders.getUndefinedPathParamPlaceholders in interface FilterableRequestSpecificationFilterableRequestSpecification.getPathParamPlaceholders()public List<String> getPathParamPlaceholders()
FilterableRequestSpecification
get("/{x}/{y}");
Calling getPathParamPlaceholders() will return a list with "x" and "y". Note that if you have a path like this:
get("/{x}/{x}");
the list will include "x" twice. Note that this function will return all placeholders as they were when the user issued the request.
I.e. calling this method when the request is defined like this:
get("/{x}/{y}", "something");
will return a list of "x" and "y". Use FilterableRequestSpecification.getUndefinedPathParamPlaceholders() to get a list of only the placeholders that are
currently undefined ("y" in this case).getPathParamPlaceholders in interface FilterableRequestSpecificationFilterableRequestSpecification.getUndefinedPathParamPlaceholders()public String getRequestContentType()
public String getContentType()
getContentType in interface FilterableRequestSpecificationpublic RequestSpecification noFilters()
RequestSpecificationnoFilters in interface RequestSpecificationpublic <T extends Filter> RequestSpecification noFiltersOfType(Class<T> filterType)
RequestSpecificationnoFiltersOfType in interface RequestSpecificationpublic RestAssuredConfig restAssuredConfig()
public void removeUnnamedPathParamAtIndex(int indexOfParamName)
public void setMethod(String method)
Copyright © 2010–2017. All rights reserved.