public interface RequestSpecification extends RequestSender
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.
|
AuthenticationSpecification |
auth()
Specify authentication 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.
|
RequestSpecification |
config(RestAssuredConfig config)
Define a REST Assured configuration.
|
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<String,?> 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.
|
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 |
formParams(Map<String,?> 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.
|
RequestSpecification |
given()
Syntactic sugar, e.g.
|
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<String,?> 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.
|
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 . |
RequestSpecification |
multiPart(File file)
Specify a file to upload to the server using multi-part form data uploading.
|
RequestSpecification |
multiPart(MultiPartSpecification multiPartSpecification)
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 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 controlName,
String contentBody)
Specify a string to send to the server using multi-part form data.
|
RequestSpecification |
multiPart(String controlName,
String fileName,
byte[] bytes)
Specify a byte-array to upload to the server using multi-part form data.
|
RequestSpecification |
multiPart(String controlName,
String fileName,
byte[] bytes,
String mimeType)
Specify a byte-array to upload to the server using multi-part form data.
|
RequestSpecification |
multiPart(String controlName,
String fileName,
InputStream stream)
Specify an inputstream to upload to the server using multi-part form data.
|
RequestSpecification |
multiPart(String controlName,
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 controlName,
String contentBody,
String mimeType)
Specify a string to send to the server using multi-part form data with a specific mime-type.
|
RequestSpecification |
noFilters()
Remove all applied filters
|
<T extends Filter> |
noFiltersOfType(Class<T> filterType)
Remove all applied filters
|
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 |
params(Map<String,?> 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.
|
RequestSpecification |
pathParam(String parameterName,
Object parameterValue)
Specify a path parameter.
|
RequestSpecification |
pathParams(Map<String,?> 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.
|
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.
|
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 |
queryParams(Map<String,?> 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.
|
RequestSpecification |
request()
Syntactic sugar, e.g.
|
ResponseSpecification |
response()
Returns the response specification so that you can setup the expectations on the response.
|
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.
|
RequestSpecification |
spec(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.
|
delete, delete, delete, delete, delete, get, get, get, get, get, head, head, head, head, head, options, options, options, options, options, patch, patch, patch, patch, patch, post, post, post, post, post, put, put, put, put, put, request, request, request, request, request, request, request, request
RequestSpecification body(String body)
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
- The body to send.RequestSpecification body(byte[] body)
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".
body
- The body to send.RequestSpecification body(File body)
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
- The content to send.RequestSpecification body(InputStream body)
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
- The content to send.RequestSpecification body(Object object)
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.
object
- The object to serialize and send with the requestRequestSpecification body(Object object, ObjectMapper mapper)
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")).
object
- The object to serialize and send with the requestmapper
- The object mapperRequestSpecification body(Object object, ObjectMapperType mapperType)
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")).
object
- The object to serialize and send with the requestmapperType
- The object mapper type to be usedRedirectSpecification redirects()
given().redirects().max(12).and().redirects().follow(true).when(). ..
RequestSpecification cookies(String firstCookieName, Object firstCookieValue, Object... cookieNameValuePairs)
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:
firstCookieName
- The name of the first cookiefirstCookieValue
- The value of the first cookiecookieNameValuePairs
- Additional cookies in name-value pairs.RequestSpecification cookies(Map<String,?> cookies)
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
- The Map containing the cookie names and their values to set in the request.RequestSpecification cookies(Cookies cookies)
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
- The cookies to set in the request.RequestSpecification cookie(String cookieName, Object value, Object... additionalValues)
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.cookieName
- The cookie cookieNamevalue
- The cookie valueadditionalValues
- Additional cookies values. This will actually create two cookies with the same name but with different values.cookies(String, Object, Object...)
RequestSpecification cookie(String cookieName)
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".
cookieName
- The cookie cookieNamecookies(String, Object, Object...)
RequestSpecification cookie(Cookie cookie)
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
- The cookie to add to the requestcookies(Cookies)
RequestSpecification params(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
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:
firstParameterName
- The name of the first parameterfirstParameterValue
- The value of the first parameterparameterNameValuePairs
- Additional parameters in name-value pairs.RequestSpecification params(Map<String,?> parametersMap)
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:
parametersMap
- The Map containing the parameter names and their values to send with the request.RequestSpecification param(String parameterName, Object... parameterValues)
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"));
parameterName
- The parameter nameparameterValues
- Parameter values, one to many if you want to specify multiple values for the same parameter.param(String, Object...)
RequestSpecification param(String parameterName, Collection<?> parameterValues)
given().param("cars", asList("Volvo", "Saab"))..;This will set the parameter
cars=Volvo
and cars=Saab
.
parameterName
- The parameter nameparameterValues
- The parameter valuesRequestSpecification queryParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
params(String, Object, Object...)
for all http methods except for POST where params(String, Object, Object...)
sets the form parameters and this method sets the
query parameters.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 queryParams(Map<String,?> parametersMap)
params(Map)
for all http methods except for POST where params(Map)
sets the form parameters and this method sets the
query parameters.parametersMap
- The Map containing the parameter names and their values to send with the request.RequestSpecification queryParam(String parameterName, Object... parameterValues)
param(String, Object...)
for all http methods except for POST where param(String, Object...)
adds a form parameter and this method sets a
query parameter.parameterName
- The parameter nameparameterValues
- Zero to many parameter values. Use additional parameter values if you want to specify multiple values for the same parameterparam(String, Object...)
RequestSpecification queryParam(String parameterName, Collection<?> parameterValues)
given().queryParam("cars", asList("Volvo", "Saab"))..;This will set the parameter
cars=Volvo
and cars=Saab
.
Note that this method is the same as param(String, java.util.Collection)
for all http methods except for POST where param(String, java.util.Collection)
adds a form parameter and
this method sets a query parameter.parameterName
- The parameter nameparameterValues
- The parameter valuesRequestSpecification formParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
params(String, Object, Object...)
for all http methods except for PUT where params(String, Object, Object...)
sets the query parameters and this method sets the
form parameters.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 formParams(Map<String,?> parametersMap)
params(Map)
for all http methods except for PUT where params(Map)
sets the query parameters and this method sets the
form parameters.parametersMap
- The Map containing the form parameter names and their values to send with the request.formParams(java.util.Map)
RequestSpecification formParam(String parameterName, Object... parameterValues)
param(String, Object...)
for all http methods except for PUT where param(String, Object...)
adds a query parameter and this method sets a
form parameter.parameterName
- The parameter nameparameterValues
- Zero to many parameter values. You can specify multiple values for the same parameter.param(String, Object...)
RequestSpecification formParam(String parameterName, Collection<?> parameterValues)
given().formParam("cars", asList("Volvo", "Saab"))..;This will set the parameter
cars=Volvo
and cars=Saab
.
Note that this method is the same as param(String, java.util.Collection)
for all http methods except for PUT where param(String, java.util.Collection)
adds a query parameter and
this method sets a form parameter.parameterName
- The parameter nameparameterValues
- The parameter valuesformParam(String, java.util.Collection)
RequestSpecification pathParam(String parameterName, Object parameterValue)
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).;
parameterName
- The parameter nameparameterValue
- The parameter valueRequestSpecification pathParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
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);
firstParameterName
- The name of the first parameterfirstParameterValue
- The value of the first parameterparameterNameValuePairs
- Additional parameters in name-value pairs.RequestSpecification pathParams(Map<String,?> parameterNameValuePairs)
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);
parameterNameValuePairs
- A map containing the path parameters.RequestSpecification config(RestAssuredConfig config)
given().config(config().redirect(redirectConfig().followRedirects(true).and().maxRedirects(0))). ..
config()
can be statically imported from RestAssuredConfig
.config
- The configuration to use for this request. If null
no config will be used.RequestSpecification keyStore(String pathToJks, String password)
$ 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));
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 passRequestSpecification keyStore(File pathToJks, String password)
keyStore(String, String)
for more details.
Note that this is just a shortcut for:
given().config(RestAssured.config().sslConfig(sslConfig().keyStore(pathToJks, password));
pathToJks
- The path to JKS file on the file-systempassword
- The password for the keystorekeyStore(String, String)
RequestSpecification trustStore(String path, String password)
given().trustStore("/truststore_javanet.jks", "test1234"). ..
Note that this is just a shortcut for:
given().config(RestAssured.config().sslConfig(sslConfig().trustStore(pathToJks, password));
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 passRequestSpecification trustStore(File path, String password)
trustStore(String, String)
for more details.
Note that this is just a shortcut for:
given().config(RestAssured.config().sslConfig(sslConfig().trustStore(pathToJks, password));
path
- The path to trust storefile on the file-systempassword
- The password for the keystorekeyStore(String, String)
RequestSpecification trustStore(KeyStore trustStore)
given().config(RestAssured.config().sslConfig(sslConfig().trustStore(truststore));
trustStore
- The truststore.keyStore(String, String)
RequestSpecification keyStore(KeyStore keyStore)
given().config(RestAssured.config().sslConfig(sslConfig().keyStore(keyStore));
keyStore
- The keyStore.keyStore(String, String)
RequestSpecification relaxedHTTPSValidation()
keyStore(String, String)
or trust store (see trustStore(java.security.KeyStore)
.
This is just a shortcut for:
given().config(RestAssured.config().sslConfig(sslConfig().relaxedHTTPSValidation())). ..;
RequestSpecification relaxedHTTPSValidation(String protocol)
keyStore(String, String)
or trust store (see trustStore(java.security.KeyStore)
.
This is just a shortcut for:
given().config(RestAssured.config().sslConfig(sslConfig().relaxedHTTPSValidation(<protocol>))). ..;
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.RequestSpecification headers(String firstHeaderName, Object firstHeaderValue, Object... headerNameValuePairs)
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:
firstHeaderName
- The name of the first headerfirstHeaderValue
- The value of the first headerheaderNameValuePairs
- Additional headers in name-value pairs.RequestSpecification headers(Map<String,?> headers)
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
- The Map containing the header names and their values to send with the request.RequestSpecification headers(Headers headers)
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
- The headers to use in the requestRequestSpecification header(String headerName, Object headerValue, Object... additionalHeaderValues)
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.headerName
- The header nameheaderValue
- The header valueadditionalHeaderValues
- Additional header values. This will actually create two headers with the same name but with different values.headers(String, Object, Object...)
RequestSpecification header(Header header)
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
- The header to add to the requestheaders(Headers)
RequestSpecification contentType(ContentType contentType)
contentType
- The content type of the requestContentType
RequestSpecification contentType(String contentType)
contentType
- The content type of the requestContentType
RequestSpecification accept(ContentType contentType)
header("Accept", contentType);
contentType
- The content type whose accept header ContentType.getAcceptHeader()
will be used as Accept header in the request.ContentType
,
header(String, Object, Object...)
RequestSpecification accept(String mediaTypes)
header("Accept", contentType);
mediaTypes
- The media type(s) that will be used as Accept header in the request.ContentType
,
header(String, Object, Object...)
RequestSpecification multiPart(MultiPartSpecification multiPartSpecification)
multiPartSpecification
- Multipart specificationRequestSpecification multiPart(File file)
file
- The file to uploadRequestSpecification multiPart(String controlName, File file)
file
- The file to uploadcontrolName
- Defines the control name of the body part. In HTML this is the attribute name of the input tag.RequestSpecification multiPart(String controlName, File file, String mimeType)
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-typeRequestSpecification multiPart(String controlName, Object object)
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 serverRequestSpecification multiPart(String controlName, Object object, String mimeType)
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-typeRequestSpecification multiPart(String controlName, String filename, Object object, String mimeType)
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-typeRequestSpecification multiPart(String controlName, String fileName, byte[] bytes)
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 uploadingbytes
- The bytes you want to sendRequestSpecification multiPart(String controlName, String fileName, byte[] bytes, String mimeType)
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 uploadingbytes
- The bytes you want to sendmimeType
- The mime-typeRequestSpecification multiPart(String controlName, String fileName, InputStream stream)
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 uploadingstream
- The stream you want to sendRequestSpecification multiPart(String controlName, String fileName, InputStream stream, String mimeType)
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 uploadingstream
- The stream you want to sendmimeType
- The mime-typeRequestSpecification multiPart(String controlName, String contentBody)
controlName
- Defines the control name of the body part. In HTML this is the attribute name of the input tag.contentBody
- The string to sendRequestSpecification multiPart(String controlName, String contentBody, String mimeType)
controlName
- 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-typeAuthenticationSpecification auth()
AuthenticationSpecification
RequestSpecification port(int port)
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
- The port of URIRequestSpecification spec(RequestSpecification requestSpecificationToMerge)
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:
requestSpecificationToMerge
- The specification to merge with.RequestSpecification sessionId(String sessionIdValue)
RestAssured.config = newConfig().sessionConfig(new SessionConfig().sessionIdName(<sessionIdName>));or you can use the
sessionId(String, String)
method to set it for this request only.sessionIdValue
- The session id value.RequestSpecification sessionId(String sessionIdName, String sessionIdValue)
RestAssured.config = newConfig().sessionConfig(new SessionConfig().sessionIdName(<sessionIdName>));and then you can use the
sessionId(String)
method to set the session id value without specifying the name for each request.sessionIdName
- The session id namesessionIdValue
- The session id value.RequestSpecification urlEncodingEnabled(boolean isEnabled)
isEnabled
- Specify whether or not URL encoding should be enabled or disabled.RequestSpecification filter(Filter filter)
filter
- The filter to addRequestSpecification filters(List<Filter> filters)
filters
- The filters to addRequestSpecification filters(Filter filter, Filter... additionalFilter)
filter
- The filter to addadditionalFilter
- Additional filters to addRequestSpecification noFilters()
<T extends Filter> RequestSpecification noFiltersOfType(Class<T> filterType)
RequestLogSpecification log()
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(..))). ..
ResponseSpecification response()
given().param("name", "value").then().response().body(equalTo("something")).when().get("/something");
RequestSpecification and()
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");
RequestSpecification with()
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");
ResponseSpecification then()
given().param("name", "value").then().body(equalTo("something")).when().get("/something");
ResponseSpecification expect()
given().param("name", "value").and().expect().body(equalTo("something")).when().get("/something");
RequestSpecification when()
expect().body(containsString("OK")).when().get("/something");is that same as:
expect().body(containsString("OK")).get("/something");
RequestSpecification given()
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");
RequestSpecification that()
expect().that().body(containsString("OK")).when().get("/something");is that same as:
expect().body(containsString("OK")).get("/something");
RequestSpecification request()
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");
RequestSpecification baseUri(String baseUri)
baseUri
- The uriRequestSpecification basePath(String basePath)
basePath
- The base pathRequestSpecification proxy(String host, int port)
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
)RequestSpecification proxy(String host)
8888
.host
- The hostname of the proxy to connect to (for example 127.0.0.1
). Can also be a URI represented as a String.proxy(String, int)
RequestSpecification proxy(int port)
port
- The port of the proxy to connect to (for example 8888
)proxy(String, int)
RequestSpecification proxy(String host, int port, String scheme)
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)RequestSpecification proxy(URI uri)
uri
- The URI of the proxyRequestSpecification proxy(ProxySpecification proxySpecification)
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)
.proxySpecification
- The proxy specification to use.Copyright © 2010–2019. All rights reserved.