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.GroovyObject
public void setMetaClass(groovy.lang.MetaClass mc)
setMetaClass
in interface groovy.lang.GroovyObject
public Object invokeMethod(String method, Object arguments)
invokeMethod
in interface groovy.lang.GroovyObject
public Object getProperty(String property)
getProperty
in interface groovy.lang.GroovyObject
public void setProperty(String property, Object value)
setProperty
in interface groovy.lang.GroovyObject
public AuthenticationScheme getAuthenticationScheme()
getAuthenticationScheme
in interface QueryableRequestSpecification
public 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 RequestSpecification
public 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 RequestSpecification
public RequestSpecification that()
RequestSpecification
expect().that().body(containsString("OK")).when().get("/something");is that same as:
expect().body(containsString("OK")).get("/something");
that
in interface RequestSpecification
public ResponseSpecification response()
RequestSpecification
given().param("name", "value").then().response().body(equalTo("something")).when().get("/something");
response
in interface RequestSpecification
public Response get(String path, Object... pathParams)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.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)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.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)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.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)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.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)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.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)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.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)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.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)
RequestSenderOptions
uri
.get
in interface RequestSenderOptions<Response>
uri
- The uri to send the request to.public Response post(URI uri)
RequestSenderOptions
uri
.post
in interface RequestSenderOptions<Response>
uri
- The uri to send the request to.public Response put(URI uri)
RequestSenderOptions
uri
.put
in interface RequestSenderOptions<Response>
uri
- The uri to send the request to.public Response delete(URI uri)
RequestSenderOptions
uri
.delete
in interface RequestSenderOptions<Response>
uri
- The uri to send the request to.public Response head(URI uri)
RequestSenderOptions
uri
.head
in interface RequestSenderOptions<Response>
uri
- The uri to send the request to.public Response patch(URI uri)
RequestSenderOptions
uri
.patch
in interface RequestSenderOptions<Response>
uri
- The uri to send the request to.public Response options(URI uri)
RequestSenderOptions
uri
.options
in interface RequestSenderOptions<Response>
uri
- The uri to send the request to.public Response get(URL url)
RequestSenderOptions
url
.get
in interface RequestSenderOptions<Response>
url
- The url to send the request to.public Response post(URL url)
RequestSenderOptions
url
.post
in interface RequestSenderOptions<Response>
url
- The url to send the request to.public Response put(URL url)
RequestSenderOptions
url
.put
in interface RequestSenderOptions<Response>
url
- The url to send the request to.public Response delete(URL url)
RequestSenderOptions
url
.delete
in interface RequestSenderOptions<Response>
url
- The url to send the request to.public Response head(URL url)
RequestSenderOptions
url
.head
in interface RequestSenderOptions<Response>
url
- The url to send the request to.public Response patch(URL url)
RequestSenderOptions
url
.patch
in interface RequestSenderOptions<Response>
url
- The url to send the request to.public Response options(URL url)
RequestSenderOptions
url
.options
in interface RequestSenderOptions<Response>
url
- The url to send the request to.public Response get()
RequestSenderOptions
http://localhost:8080
).get
in interface RequestSenderOptions<Response>
public Response post()
RequestSenderOptions
http://localhost:8080
).post
in interface RequestSenderOptions<Response>
public Response put()
RequestSenderOptions
http://localhost:8080
).put
in interface RequestSenderOptions<Response>
public Response delete()
RequestSenderOptions
http://localhost:8080
).delete
in interface RequestSenderOptions<Response>
public Response head()
RequestSenderOptions
http://localhost:8080
).head
in interface RequestSenderOptions<Response>
public Response patch()
RequestSenderOptions
http://localhost:8080
).patch
in interface RequestSenderOptions<Response>
public Response options()
RequestSenderOptions
http://localhost:8080
).options
in interface RequestSenderOptions<Response>
public Response request(Method method)
RequestSenderOptions
http://localhost:8080
).request
in interface RequestSenderOptions<Response>
method
- The HTTP method to usepublic Response request(String method)
RequestSenderOptions
http://localhost:8080
).request
in interface RequestSenderOptions<Response>
method
- The HTTP method to usepublic Response request(Method method, String path, Object... pathParams)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.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)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.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)
RequestSenderOptions
uri
.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)
RequestSenderOptions
url
.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)
RequestSenderOptions
uri
.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)
RequestSenderOptions
url
.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)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.get
in interface RequestSenderOptions<Response>
path
- The path to send the request to.pathParams
- The path parameters.public Response post(String path, Map pathParams)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.post
in interface RequestSenderOptions<Response>
path
- The path to send the request to.pathParams
- The path parameters.public Response put(String path, Map pathParams)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.put
in interface RequestSenderOptions<Response>
path
- The path to send the request to.pathParams
- The path parameters.public Response delete(String path, Map pathParams)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.delete
in interface RequestSenderOptions<Response>
path
- The path to send the request to.pathParams
- The path parameters.public Response head(String path, Map pathParams)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.head
in interface RequestSenderOptions<Response>
path
- The path to send the request to.pathParams
- The path parameters.public Response patch(String path, Map pathParams)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.patch
in interface RequestSenderOptions<Response>
path
- The path to send the request to.pathParams
- The path parameters.public Response options(String path, Map pathParams)
RequestSenderOptions
path
. Normally the path doesn't have to be fully-qualified e.g. you don't need to
specify the path as http://localhost:8080/path. In this case it's enough to use /path.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 RequestSpecification
firstParameterName
- 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 RequestSpecification
parametersMap
- 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 RequestSpecification
firstParameterName
- 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 RequestSpecification
parametersMap
- 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 RequestSpecification
parameterName
- 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)
FilterableRequestSpecification
removeParam
in interface FilterableRequestSpecification
parameterName
- 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 RequestSpecification
parameterName
- 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 RequestSpecification
parameterName
- 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 RequestSpecification
parameterName
- 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 RequestSpecification
parameterName
- The parameter nameparameterValues
- The parameter valuespublic FilterableRequestSpecification removeQueryParam(String parameterName)
FilterableRequestSpecification
removeQueryParam
in interface FilterableRequestSpecification
parameterName
- The parameter keyFilterableRequestSpecification
without the parameterpublic FilterableRequestSpecification removeHeader(String headerName)
FilterableRequestSpecification
removeHeader
in interface FilterableRequestSpecification
headerName
- The header nameFilterableRequestSpecification
without the specified headerpublic FilterableRequestSpecification removeCookie(String cookieName)
FilterableRequestSpecification
removeCookie
in interface FilterableRequestSpecification
cookieName
- The cookie nameFilterableRequestSpecification
without the specified cookiepublic FilterableRequestSpecification removeCookie(Cookie cookie)
FilterableRequestSpecification
removeCookie
in interface FilterableRequestSpecification
cookie
- The cookieFilterableRequestSpecification
without the specified cookiepublic FilterableRequestSpecification replaceHeader(String headerName, String newValue)
FilterableRequestSpecification
replaceHeader
in interface FilterableRequestSpecification
headerName
- The header name to replaceFilterableRequestSpecification
with the replaced headerpublic FilterableRequestSpecification replaceCookie(String cookieName, String value)
FilterableRequestSpecification
replaceCookie
in interface FilterableRequestSpecification
cookieName
- The cookie nameFilterableRequestSpecification
with the replaced cookiepublic FilterableRequestSpecification replaceCookie(Cookie cookie)
FilterableRequestSpecification
replaceCookie
in interface FilterableRequestSpecification
cookie
- The cookieFilterableRequestSpecification
with the replaced cookiepublic FilterableRequestSpecification replaceHeaders(Headers headers)
FilterableRequestSpecification
replaceHeaders
in interface FilterableRequestSpecification
headers
- The new headersFilterableRequestSpecification
with the replaced headerspublic FilterableRequestSpecification replaceCookies(Cookies cookies)
FilterableRequestSpecification
replaceCookies
in interface FilterableRequestSpecification
cookies
- The new cookiesFilterableRequestSpecification
with the replaced cookiespublic FilterableRequestSpecification removeHeaders()
FilterableRequestSpecification
removeHeaders
in interface FilterableRequestSpecification
FilterableRequestSpecification
withoutpublic FilterableRequestSpecification removeCookies()
FilterableRequestSpecification
removeCookies
in interface FilterableRequestSpecification
FilterableRequestSpecification
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 RequestSpecification
parameterName
- 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)
RequestSpecification
RequestSpecification.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 RequestSpecification
firstParameterName
- 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)
RequestSpecification
RequestSpecification.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 RequestSpecification
parametersMap
- The Map containing the parameter names and their values to send with the request.public RequestSpecification queryParameter(String parameterName, Object... parameterValues)
RequestSpecification
RequestSpecification.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 RequestSpecification
parameterName
- 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)
RequestSpecification
RequestSpecification.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 RequestSpecification
firstParameterName
- 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)
RequestSpecification
RequestSpecification.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 RequestSpecification
parametersMap
- The Map containing the parameter names and their values to send with the request.public RequestSpecification queryParam(String parameterName, Object... parameterValues)
RequestSpecification
RequestSpecification.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 RequestSpecification
parameterName
- 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 RequestSpecification
parameterName
- 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 RequestSpecification
parameterName
- The parameter nameparameterValues
- The parameter valuesRequestSpecification.formParam(String, java.util.Collection)
public FilterableRequestSpecification removeFormParam(String parameterName)
FilterableRequestSpecification
removeFormParam
in interface FilterableRequestSpecification
parameterName
- The parameter keyFilterableRequestSpecification
without the parameterpublic RequestSpecification formParameters(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
RequestSpecification
RequestSpecification.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 RequestSpecification
firstParameterName
- 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)
RequestSpecification
RequestSpecification.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 RequestSpecification
parametersMap
- The Map containing the parameter names and their values to send with the request.public RequestSpecification formParameter(String parameterName, Object... additionalParameterValues)
RequestSpecification
RequestSpecification.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 RequestSpecification
parameterName
- The parameter nameadditionalParameterValues
- Zero to many parameter values for this parameter.RequestSpecification.parameter(String, Object...)
public RequestSpecification formParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
RequestSpecification
RequestSpecification.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 RequestSpecification
firstParameterName
- 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)
RequestSpecification
RequestSpecification.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 RequestSpecification
parametersMap
- 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)
RequestSpecification
RequestSpecification.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 RequestSpecification
parameterName
- 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)
RequestSpecification
urlEncodingEnabled
in interface RequestSpecification
isEnabled
- 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 RequestSpecification
parameterName
- 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 RequestSpecification
firstParameterName
- 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 RequestSpecification
parameterNameValuePairs
- 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 RequestSpecification
parameterName
- 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 RequestSpecification
firstParameterName
- 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 RequestSpecification
parameterNameValuePairs
- A map containing the path parameters.RequestSpecification.pathParameters(java.util.Map)
public FilterableRequestSpecification removePathParam(String parameterName)
FilterableRequestSpecification
removePathParam
in interface FilterableRequestSpecification
parameterName
- The parameter keyFilterableRequestSpecification
without the parameterpublic FilterableRequestSpecification removeNamedPathParam(String parameterName)
FilterableRequestSpecification
removeNamedPathParam
in interface FilterableRequestSpecification
parameterName
- The parameter keyFilterableRequestSpecification
without the parameterpublic FilterableRequestSpecification removeUnnamedPathParam(String parameterName)
FilterableRequestSpecification
removeUnnamedPathParam
in interface FilterableRequestSpecification
parameterName
- The parameter keyFilterableRequestSpecification
without the parameterpublic FilterableRequestSpecification removeUnnamedPathParamByValue(String parameterValue)
FilterableRequestSpecification
removeUnnamedPathParamByValue
in interface FilterableRequestSpecification
parameterValue
- The parameter keyFilterableRequestSpecification
without the parameterpublic RequestSpecification config(RestAssuredConfig config)
RequestSpecification
given().config(config().redirect(redirectConfig().followRedirects(true).and().maxRedirects(0))). ..
config()
can be statically imported from RestAssuredConfig
.config
in interface RequestSpecification
config
- 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 RequestSpecification
pathToJks
- 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)
RequestSpecification
RequestSpecification.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 RequestSpecification
pathToJks
- 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 RequestSpecification
path
- 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)
RequestSpecification
RequestSpecification.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 RequestSpecification
path
- 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 RequestSpecification
trustStore
- The truststore.RequestSpecification.keyStore(String, String)
public RequestSpecification keyStore(KeyStore keyStore)
RequestSpecification
given().config(RestAssured.config().sslConfig(sslConfig().keyStore(keyStore));
keyStore
in interface RequestSpecification
keyStore
- The keyStore.RequestSpecification.keyStore(String, String)
public RequestSpecification relaxedHTTPSValidation()
RequestSpecification
RequestSpecification.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 RequestSpecification
public RequestSpecification relaxedHTTPSValidation(String protocol)
RequestSpecification
RequestSpecification.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 RequestSpecification
protocol
- 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)
RequestSpecification
filter
in interface RequestSpecification
filter
- The filter to addpublic RequestSpecification filters(List<Filter> filters)
RequestSpecification
filters
in interface RequestSpecification
filters
- The filters to addpublic RequestSpecification filters(Filter filter, Filter... additionalFilter)
RequestSpecification
filters
in interface RequestSpecification
filter
- The filter to addadditionalFilter
- Additional filters to addpublic RequestLogSpecification log()
RequestSpecification
RequestLogSpecification
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 RequestSpecification
public 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 RequestSpecification
public 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 RequestSpecification
public 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 RequestSpecification
public ResponseSpecification then()
RequestSpecification
given().param("name", "value").then().body(equalTo("something")).when().get("/something");
then
in interface RequestSpecification
public ResponseSpecification expect()
RequestSpecification
given().param("name", "value").and().expect().body(equalTo("something")).when().get("/something");
expect
in interface RequestSpecification
public AuthenticationSpecification auth()
RequestSpecification
auth
in interface RequestSpecification
AuthenticationSpecification
public AuthenticationSpecification authentication()
RequestSpecification
authentication
in interface RequestSpecification
AuthenticationSpecification
public 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 RequestSpecification
port
- The port of URIpublic RequestSpecification body(String body)
RequestSpecification
Example 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 RequestSpecification
body
- The body to send.public RequestSpecification content(String content)
RequestSpecification
Example 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 RequestSpecification
content
- The content to send.public RequestSpecification baseUri(String baseUri)
RequestSpecification
baseUri
in interface RequestSpecification
baseUri
- The uripublic RequestSpecification basePath(String basePath)
RequestSpecification
basePath
in interface RequestSpecification
basePath
- The base pathpublic RequestSpecification proxy(String host, int port)
RequestSpecification
proxy
in interface RequestSpecification
host
- 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)
RequestSpecification
8888
.proxy
in interface RequestSpecification
host
- 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)
RequestSpecification
proxy
in interface RequestSpecification
port
- The port of the proxy to connect to (for example 8888
)RequestSpecification.proxy(String, int)
public RequestSpecification proxy(String host, int port, String scheme)
RequestSpecification
proxy
in interface RequestSpecification
host
- 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)
RequestSpecification
proxy
in interface RequestSpecification
uri
- The URI of the proxypublic RequestSpecification proxy(ProxySpecification proxySpecification)
RequestSpecification
ProxySpecification
.
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 RequestSpecification
proxySpecification
- The proxy specification to use.public RequestSpecification body(byte... body)
RequestSpecification
Example 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 RequestSpecification
body
- The body to send.public RequestSpecification body(File body)
RequestSpecification
Example 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 RequestSpecification
body
- The content to send.public RequestSpecification body(InputStream body)
RequestSpecification
Example 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 RequestSpecification
body
- The content to send.public RequestSpecification content(byte... content)
RequestSpecification
Example 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 RequestSpecification
content
- The content to send.public RequestSpecification content(File content)
RequestSpecification
Example 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 RequestSpecification
content
- The content to send.public RequestSpecification content(InputStream content)
RequestSpecification
Example 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 RequestSpecification
content
- The content to send.public RequestSpecification body(Object object)
RequestSpecification
Example 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 RequestSpecification
object
- The object to serialize and send with the requestpublic RequestSpecification content(Object object)
RequestSpecification
Example 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 RequestSpecification
object
- The object to serialize and send with the requestpublic RequestSpecification body(Object object, ObjectMapper mapper)
RequestSpecification
Example 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 RequestSpecification
object
- The object to serialize and send with the requestmapper
- The object mapperpublic RequestSpecification body(Object object, ObjectMapperType mapperType)
RequestSpecification
Example 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 RequestSpecification
object
- The object to serialize and send with the requestmapperType
- The object mapper type to be usedpublic RequestSpecification content(Object object, ObjectMapper mapper)
RequestSpecification
Example 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 RequestSpecification
object
- The object to serialize and send with the requestpublic RequestSpecification content(Object object, ObjectMapperType mapperType)
RequestSpecification
Example 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 RequestSpecification
object
- The object to serialize and send with the requestmapperType
- The object mapper type to usepublic RequestSpecification contentType(ContentType contentType)
RequestSpecification
contentType
in interface RequestSpecification
contentType
- The content type of the requestContentType
public RequestSpecification contentType(String contentType)
RequestSpecification
contentType
in interface RequestSpecification
contentType
- The content type of the requestContentType
public RequestSpecification accept(ContentType contentType)
RequestSpecification
header("Accept", contentType);
accept
in interface RequestSpecification
contentType
- 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 RequestSpecification
mediaTypes
- 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 RequestSpecification
headers
- The Map containing the header names and their values to send with the request.public RequestSpecification headers(Headers headers)
RequestSpecification
Headers
, 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 RequestSpecification
headers
- 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 RequestSpecification
headerName
- 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)
RequestSpecification
Header
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 RequestSpecification
header
- 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 RequestSpecification
firstHeaderName
- 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 RequestSpecification
firstCookieName
- 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 RequestSpecification
cookies
- The Map containing the cookie names and their values to set in the request.public RequestSpecification cookies(Cookies cookies)
RequestSpecification
Cookies
:
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 RequestSpecification
cookies
- 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 RequestSpecification
cookieName
- 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)
RequestSpecification
Cookie
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 RequestSpecification
cookie
- 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 RequestSpecification
cookieName
- The cookie cookieNameRequestSpecification.cookies(String, Object, Object...)
public RedirectSpecification redirects()
RequestSpecification
given().redirects().max(12).and().redirects().follow(true).when(). ..
redirects
in interface RequestSpecification
public 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 RequestSpecification
requestSpecificationToMerge
- 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 RequestSpecification
requestSpecificationToMerge
- 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 RequestSpecification
sessionIdValue
- 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 RequestSpecification
sessionIdName
- The session id namesessionIdValue
- The session id value.public RequestSpecification multiPart(MultiPartSpecification multiPartSpec)
RequestSpecification
multiPart
in interface RequestSpecification
multiPartSpec
- Multipart specificationpublic RequestSpecification multiPart(String controlName, File file)
RequestSpecification
multiPart
in interface RequestSpecification
controlName
- 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)
RequestSpecification
multiPart
in interface RequestSpecification
file
- The file to uploadpublic RequestSpecification multiPart(String controlName, File file, String mimeType)
RequestSpecification
multiPart
in interface RequestSpecification
controlName
- 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)
RequestSpecification
multiPart
in interface RequestSpecification
controlName
- 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)
RequestSpecification
multiPart
in interface RequestSpecification
controlName
- 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)
RequestSpecification
multiPart
in interface RequestSpecification
controlName
- 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)
RequestSpecification
multiPart
in interface RequestSpecification
name
- 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)
RequestSpecification
multiPart
in interface RequestSpecification
name
- 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)
RequestSpecification
multiPart
in interface RequestSpecification
name
- 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)
RequestSpecification
multiPart
in interface RequestSpecification
name
- 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)
RequestSpecification
multiPart
in interface RequestSpecification
name
- 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)
RequestSpecification
multiPart
in interface RequestSpecification
name
- 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 QueryableRequestSpecification
public String getBasePath()
getBasePath
in interface QueryableRequestSpecification
public String getDerivedPath()
getDerivedPath
in interface QueryableRequestSpecification
public String getUserDefinedPath()
QueryableRequestSpecification
get("/something/{x}", x);Then this method would return
"/something/{x}"
.getUserDefinedPath
in interface QueryableRequestSpecification
public String getMethod()
getMethod
in interface QueryableRequestSpecification
public String getURI()
getURI
in interface QueryableRequestSpecification
public int getPort()
getPort
in interface QueryableRequestSpecification
public Map<String,String> getFormParams()
getFormParams
in interface QueryableRequestSpecification
public Map<String,String> getPathParams()
getPathParams
in interface QueryableRequestSpecification
public Map<String,String> getNamedPathParams()
getNamedPathParams
in interface QueryableRequestSpecification
public Map<String,String> getUnnamedPathParams()
QueryableRequestSpecification
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 QueryableRequestSpecification.getUnnamedPathParamValues()
.getUnnamedPathParams
in interface QueryableRequestSpecification
public List<String> getUnnamedPathParamValues()
getUnnamedPathParamValues
in interface QueryableRequestSpecification
QueryableRequestSpecification.getUnnamedPathParams()
public Map<String,String> getRequestParams()
getRequestParams
in interface QueryableRequestSpecification
public Map<String,String> getQueryParams()
getQueryParams
in interface QueryableRequestSpecification
public List<MultiPartSpecification> getMultiPartParams()
getMultiPartParams
in interface QueryableRequestSpecification
public Headers getHeaders()
getHeaders
in interface QueryableRequestSpecification
public Cookies getCookies()
getCookies
in interface QueryableRequestSpecification
public <T> T getBody()
getBody
in interface QueryableRequestSpecification
public List<Filter> getDefinedFilters()
getDefinedFilters
in interface QueryableRequestSpecification
public RestAssuredConfig getConfig()
getConfig
in interface QueryableRequestSpecification
public org.apache.http.client.HttpClient getHttpClient()
getHttpClient
in interface QueryableRequestSpecification
AbstractHttpClient
is used by REST Assured.public ProxySpecification getProxySpecification()
getProxySpecification
in interface QueryableRequestSpecification
null
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 FilterableRequestSpecification
path
- The pathpublic List<String> getUndefinedPathParamPlaceholders()
QueryableRequestSpecification
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
QueryableRequestSpecification.getPathParamPlaceholders()
to get ALL placeholders.getUndefinedPathParamPlaceholders
in interface QueryableRequestSpecification
QueryableRequestSpecification.getPathParamPlaceholders()
public List<String> getPathParamPlaceholders()
QueryableRequestSpecification
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
QueryableRequestSpecification.getUndefinedPathParamPlaceholders()
to get a list of only the placeholders that are
currently undefined ("y" in this case).getPathParamPlaceholders
in interface QueryableRequestSpecification
QueryableRequestSpecification.getUndefinedPathParamPlaceholders()
public String getRequestContentType()
public String getContentType()
getContentType
in interface QueryableRequestSpecification
public RequestSpecification noFilters()
RequestSpecification
noFilters
in interface RequestSpecification
public <T extends Filter> RequestSpecification noFiltersOfType(Class<T> filterType)
RequestSpecification
noFiltersOfType
in interface RequestSpecification
public RestAssuredConfig restAssuredConfig()
public void removeUnnamedPathParamAtIndex(int indexOfParamName)
public void setMethod(String method)
Copyright © 2010–2019. All rights reserved.