com.jayway.restassured.internal
Class RequestSpecificationImpl

java.lang.Object
  extended by com.jayway.restassured.internal.RequestSpecificationImpl
All Implemented Interfaces:
FilterableRequestSpecification, RequestSender, RequestSpecification, groovy.lang.GroovyObject

public class RequestSpecificationImpl
extends Object
implements FilterableRequestSpecification, groovy.lang.GroovyObject


Constructor Summary
RequestSpecificationImpl(String baseURI, int requestPort, String basePath, AuthenticationScheme defaultAuthScheme, List<Filter> filters, KeystoreSpec keyStoreSpec, Object defaultRequestContentType, RequestSpecification defaultSpec, boolean urlEncode, RestAssuredConfig restAssuredConfig)
           
 
Method Summary
 RequestSpecification and()
          Syntactic sugar, e.g.
 Object applyEncoderConfig(HTTPBuilder httpBuilder, EncoderConfig encoderConfig)
           
 Object applyHttpClientConfig(HttpClientConfig httpClientConfig)
           
 Object applyRedirectConfig(RedirectConfig redirectConfig)
           
 Object applyRestAssuredConfig(HTTPBuilder http)
           
 Object applySessionConfig(SessionConfig sessionConfig)
           
 Object assembleBodyContent(Object httpMethod)
           
 AuthenticationSpecification auth()
          A slightly short version of RequestSpecification.authentication().
 AuthenticationSpecification authentication()
          If you need to specify some credentials when performing a request.
 RequestSpecification body(byte... body)
          Specify a byte array request body that'll be sent with the request.
 RequestSpecification body(Object object)
          Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request.
 RequestSpecification body(Object object, ObjectMapper mapper)
          Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request using a specific object mapper.
 RequestSpecification body(String body)
          Specify a String request body (such as e.g.
 RequestSpecification config(RestAssuredConfig config)
          Define a configuration for redirection settings and http client parameters.
 RequestSpecification content(byte... content)
          Specify a byte array request content that'll be sent with the request.
 RequestSpecification content(Object object)
          Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request.
 RequestSpecification content(Object object, ObjectMapper mapper)
          Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request using a specific object mapper.
 RequestSpecification content(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(String path, Map pathParams)
          Perform a DELETE request to a path.
 Response delete(String path, Object... pathParams)
          Perform a DELETE request to a path.
 ResponseSpecification expect()
          Returns the response specification so that you can setup the expectations on the response.
 RequestSpecification filter(Filter filter)
          Add a filter that will be used in the request.
 RequestSpecification filters(Filter filter, Filter... additionalFilter)
          Add filters that will be used in the request.
 RequestSpecification filters(List<Filter> filters)
          Add filters that will be used in the request.
 RequestSpecification formParam(String parameterName, Collection<?> parameterValues)
          A slightly shorter version of #formParameter(String, java.util.Collection.
 RequestSpecification formParam(String parameterName, Object... parameterValues)
          A slightly shorter version of RequestSpecification.formParameter(String, Object...).
 RequestSpecification formParameter(String parameterName, Collection<?> parameterValues)
          Specify a multi-value form parameter that'll be sent with the request e.g:
 RequestSpecification formParameter(String parameterName, Object... additionalParameterValues)
          Specify a form parameter that'll be sent with the request.
 RequestSpecification formParameters(Map parametersMap)
          Specify the form parameters that'll be sent with the request.
 RequestSpecification formParameters(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
          Specify the form parameters that'll be sent with the request.
 RequestSpecification formParams(Map parametersMap)
          A slightly shorter version of RequestSpecification.formParams(java.util.Map).
 RequestSpecification formParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
          A slightly shorter version of RequestSpecification.formParameters(String, Object, Object...).
 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.
 AuthenticationScheme getAuthenticationScheme()
           
 String getBasePath()
           
 String getBaseUri()
           
<T> T
getBody()
           
 RestAssuredConfig getConfig()
           
 Cookies getCookies()
           
 List<Filter> getDefinedFilters()
           
 Map<String,Object> getFormParams()
           
 Headers getHeaders()
           
 groovy.lang.MetaClass getMetaClass()
           
 Map<String,Object> getPathParams()
           
 int getPort()
           
 Object getProperty(String property)
           
 Map<String,Object> getQueryParams()
           
 String getRequestContentType()
           
 Map<String,Object> getRequestParams()
           
 RequestSpecification given()
          Syntactic sugar, e.g.
 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.
 RequestSpecification header(Header header)
          Specify a Header to send with the request.
 RequestSpecification header(String headerName, Object headerValue, Object... additionalHeaderValues)
          Specify a header that'll be sent with the request e.g:
 RequestSpecification headers(Headers headers)
          Specify the headers that'll be sent with the request as Headers, e.g:
 RequestSpecification headers(Map headers)
          Specify the headers that'll be sent with the request as Map e.g:
 RequestSpecification headers(String firstHeaderName, Object firstHeaderValue, Object... headerNameValuePairs)
          Specify the headers that'll be sent with the request.
 Object invokeFilterChain(Object path, Object method, Object assertionClosure)
           
 Object invokeMethod(String method, Object arguments)
           
 RequestSpecification keystore(File pathToJks, String password)
          Use a keystore located on the file-system.
 RequestSpecification keystore(String pathToJks, String password)
          The following documentation is taken from http://groovy.codehaus.org/modules/http-builder/doc/ssl.html:
 RequestLogSpecification log()
          Returns the RequestLogSpecification that allows you to log different parts of the RequestSpecification.
 RequestSpecification multiPart(File file)
          Specify a file to upload to the server using multi-part form data uploading.
 RequestSpecification multiPart(String controlName, File file)
          Specify a file to upload to the server using multi-part form data uploading with a specific control name.
 RequestSpecification multiPart(String name, File file, String mimeType)
          Specify a file to upload to the server using multi-part form data uploading with a specific control name and mime-type.
 RequestSpecification multiPart(String name, NoParameterValue contentBody)
           
 RequestSpecification multiPart(String controlName, Object object)
          Specify an object that will be serialized to JSON and uploaded to the server using multi-part form data uploading with a specific control name.
 RequestSpecification multiPart(String controlName, Object object, String mimeType)
          Specify an object that will be serialized and uploaded to the server using multi-part form data uploading with a specific control name.
 RequestSpecification multiPart(String name, String contentBody)
          Specify a string to send to the server using multi-part form data.
 RequestSpecification multiPart(String name, String fileName, byte... bytes)
          Specify a byte-array to upload to the server using multi-part form data.
 RequestSpecification multiPart(String name, String fileName, byte[] bytes, String mimeType)
          Specify a byte-array to upload to the server using multi-part form data.
 RequestSpecification multiPart(String name, String fileName, InputStream stream)
          Specify an inputstream to upload to the server using multi-part form data.
 RequestSpecification multiPart(String name, String fileName, InputStream stream, String mimeType)
          Specify an inputstream to upload to the server using multi-part form data.
 RequestSpecification multiPart(String name, String contentBody, String mimeType)
          Specify a string to send to the server using multi-part form data with a specific mime-type.
 RequestSpecification noFilters()
          Remove all applied filters
<T extends Filter>
RequestSpecification
noFiltersOfType(Class<T> filterType)
          Remove all applied filters
 RequestSpecification param(String parameterName, Collection<?> parameterValues)
          A slightly shorter version of #parameter(String, java.util.Collection }.
 RequestSpecification param(String parameterName, Object... parameterValues)
          A slightly shorter version of RequestSpecification.parameter(String, Object...).
 RequestSpecification parameter(String parameterName, Collection<?> parameterValues)
          Specify a multi-value parameter that'll be sent with the request e.g:
 RequestSpecification parameter(String parameterName, Object... parameterValues)
          Specify a parameter that'll be sent with the request e.g:
 RequestSpecification parameters(Map parametersMap)
          Specify the parameters that'll be sent with the request as Map e.g:
 RequestSpecification parameters(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
          Specify the parameters that'll be sent with the request.
 RequestSpecification params(Map parametersMap)
          A slightly shorter version of RequestSpecification.parameters(Map).
 RequestSpecification params(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
          A slightly shorter version of RequestSpecification.parameters(String, Object, Object...)
 RequestSpecification pathParam(String parameterName, Object parameterValue)
          A slightly shorter version of RequestSpecification.pathParameter(String, Object).
 RequestSpecification pathParameter(String parameterName, Object parameterValue)
          Specify a path parameter.
 RequestSpecification pathParameters(Map parameterNameValuePairs)
          Specify multiple path parameter name-value pairs.
 RequestSpecification pathParameters(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
          Specify multiple path parameter name-value pairs.
 RequestSpecification pathParams(Map parameterNameValuePairs)
          A slightly shorter version of RequestSpecification.pathParameters(java.util.Map).
 RequestSpecification pathParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
          A slightly shorter version of RequestSpecification.pathParameters(String, Object, Object...).
 RequestSpecification port(int port)
          Specify the port of the URI.
 Response post(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 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.
 RequestSpecification queryParam(String parameterName, Collection<?> parameterValues)
          A slightly shorter version of #queryParameter(String, java.util.Collection.
 RequestSpecification queryParam(String parameterName, Object... parameterValues)
          A slightly shorter version of RequestSpecification.queryParameter(String, Object...).
 RequestSpecification queryParameter(String parameterName, Collection<?> parameterValues)
          Specify a multi-value query parameter that'll be sent with the request e.g:
 RequestSpecification queryParameter(String parameterName, Object... parameterValues)
          Specify a query parameter that'll be sent with the request.
 RequestSpecification queryParameters(Map parametersMap)
          Specify the query parameters that'll be sent with the request.
 RequestSpecification queryParameters(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
          Specify the query parameters that'll be sent with the request.
 RequestSpecification queryParams(Map parametersMap)
          A slightly shorter version of RequestSpecification.queryParams(java.util.Map).
 RequestSpecification queryParams(String firstParameterName, Object firstParameterValue, Object... parameterNameValuePairs)
          A slightly shorter version of RequestSpecification.queryParameters(String, Object, Object...).
 RedirectSpecification redirects()
          Specify the redirect configuration for this request.
 RequestSpecification 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.
 void setAuthenticationScheme(AuthenticationScheme value)
           
 void setMetaClass(groovy.lang.MetaClass mc)
           
 void setProperty(String property, Object value)
           
 Object setRequestHeadersToHttpBuilder(HTTPBuilder http)
           
 void setResponseSpecification(ResponseSpecification responseSpecification)
           
 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestSpecificationImpl

public RequestSpecificationImpl(String baseURI,
                                int requestPort,
                                String basePath,
                                AuthenticationScheme defaultAuthScheme,
                                List<Filter> filters,
                                KeystoreSpec keyStoreSpec,
                                Object defaultRequestContentType,
                                RequestSpecification defaultSpec,
                                boolean urlEncode,
                                RestAssuredConfig restAssuredConfig)
Method Detail

getMetaClass

public groovy.lang.MetaClass getMetaClass()
Specified by:
getMetaClass in interface groovy.lang.GroovyObject

setMetaClass

public void setMetaClass(groovy.lang.MetaClass mc)
Specified by:
setMetaClass in interface groovy.lang.GroovyObject

invokeMethod

public Object invokeMethod(String method,
                           Object arguments)
Specified by:
invokeMethod in interface groovy.lang.GroovyObject

getProperty

public Object getProperty(String property)
Specified by:
getProperty in interface groovy.lang.GroovyObject

setProperty

public void setProperty(String property,
                        Object value)
Specified by:
setProperty in interface groovy.lang.GroovyObject

getAuthenticationScheme

public AuthenticationScheme getAuthenticationScheme()
Specified by:
getAuthenticationScheme in interface FilterableRequestSpecification
Returns:
The authentication scheme defined in the request specification

setAuthenticationScheme

public void setAuthenticationScheme(AuthenticationScheme value)

when

public RequestSpecification when()
Description copied from interface: RequestSpecification
Syntactic sugar, e.g.
 expect().body(containsString("OK")).when().get("/something");
 
is that same as:
 expect().body(containsString("OK")).get("/something");
 

Specified by:
when in interface RequestSpecification
Returns:
the request specification

given

public RequestSpecification given()
Description copied from interface: RequestSpecification
Syntactic sugar, e.g.
 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");
 

Specified by:
given in interface RequestSpecification
Returns:
the request specification

that

public RequestSpecification that()
Description copied from interface: RequestSpecification
Syntactic sugar, e.g.
 expect().that().body(containsString("OK")).when().get("/something");
 
is that same as:
 expect().body(containsString("OK")).get("/something");
 

Specified by:
that in interface RequestSpecification
Returns:
the request specification

response

public ResponseSpecification response()
Description copied from interface: RequestSpecification
Returns the response specification so that you can setup the expectations on the response. E.g.
 given().param("name", "value").then().response().body(equalTo("something")).when().get("/something");
 

Specified by:
response in interface RequestSpecification
Returns:
the response specification

get

public Response get(String path,
                    Object... pathParams)
Description copied from interface: RequestSender
Perform a GET request to a 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.

Specified by:
get in interface RequestSender
Parameters:
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);.
Returns:
The response of the request.

post

public Response post(String path,
                     Object... pathParams)
Description copied from interface: RequestSender
Perform a POST request to a 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.

Specified by:
post in interface RequestSender
Parameters:
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);.
Returns:
The response of the request.

put

public Response put(String path,
                    Object... pathParams)
Description copied from interface: RequestSender
Perform a PUT request to a 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.

Specified by:
put in interface RequestSender
Parameters:
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);.
Returns:
The response of the request.

delete

public Response delete(String path,
                       Object... pathParams)
Description copied from interface: RequestSender
Perform a DELETE request to a 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.

Specified by:
delete in interface RequestSender
Parameters:
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);.
Returns:
The response of the request.

head

public Response head(String path,
                     Object... pathParams)
Description copied from interface: RequestSender
Perform a HEAD request to a 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.

Specified by:
head in interface RequestSender
Parameters:
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);.
Returns:
The response of the request.

get

public Response get(String path,
                    Map pathParams)
Description copied from interface: RequestSender
Perform a GET request to a 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.

Specified by:
get in interface RequestSender
Parameters:
path - The path to send the request to.
pathParams - The path parameters.
Returns:
The response of the request.

post

public Response post(String path,
                     Map pathParams)
Description copied from interface: RequestSender
Perform a POST request to a 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.

Specified by:
post in interface RequestSender
Parameters:
path - The path to send the request to.
pathParams - The path parameters.
Returns:
The response of the request.

put

public Response put(String path,
                    Map pathParams)
Description copied from interface: RequestSender
Perform a PUT request to a 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.

Specified by:
put in interface RequestSender
Parameters:
path - The path to send the request to.
pathParams - The path parameters.
Returns:
The response of the request.

delete

public Response delete(String path,
                       Map pathParams)
Description copied from interface: RequestSender
Perform a DELETE request to a 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.

Specified by:
delete in interface RequestSender
Parameters:
path - The path to send the request to.
pathParams - The path parameters.
Returns:
The response of the request.

head

public Response head(String path,
                     Map pathParams)
Description copied from interface: RequestSender
Perform a HEAD request to a 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.

Specified by:
head in interface RequestSender
Parameters:
path - The path to send the request to.
pathParams - The path parameters.
Returns:
The response of the request.

parameters

public RequestSpecification parameters(String firstParameterName,
                                       Object firstParameterValue,
                                       Object... parameterNameValuePairs)
Description copied from interface: RequestSpecification
Specify the parameters that'll be sent with the request. This is done by specifying the parameters in name-value pairs, e.g:
 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:
  1. username=John
  2. token=1234
and expect that the response body is equal to "username, token".

Specified by:
parameters in interface RequestSpecification
Parameters:
firstParameterName - The name of the first parameter
firstParameterValue - The value of the first parameter
parameterNameValuePairs - Additional parameters in name-value pairs.
Returns:
The request specification

parameters

public RequestSpecification parameters(Map parametersMap)
Description copied from interface: RequestSpecification
Specify the parameters that'll be sent with the request as Map e.g:
 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:
  1. username=John
  2. token=1234
and expect that the response body is equal to "username, token".

Specified by:
parameters in interface RequestSpecification
Parameters:
parametersMap - The Map containing the parameter names and their values to send with the request.
Returns:
The request specification

params

public RequestSpecification params(String firstParameterName,
                                   Object firstParameterValue,
                                   Object... parameterNameValuePairs)
Description copied from interface: RequestSpecification
A slightly shorter version of RequestSpecification.parameters(String, Object, Object...)

Specified by:
params in interface RequestSpecification
Parameters:
firstParameterName - The name of the first parameter
firstParameterValue - The value of the first parameter
parameterNameValuePairs - Additional parameters in name-value pairs.
Returns:
The request specification
See Also:
RequestSpecification.parameters(String, Object, Object...)

params

public RequestSpecification params(Map parametersMap)
Description copied from interface: RequestSpecification
A slightly shorter version of RequestSpecification.parameters(Map).

Specified by:
params in interface RequestSpecification
Parameters:
parametersMap - The Map containing the parameter names and their values to send with the request.
Returns:
The request specification
See Also:
RequestSpecification.parameters(Map)

param

public RequestSpecification param(String parameterName,
                                  Object... parameterValues)
Description copied from interface: RequestSpecification
A slightly shorter version of RequestSpecification.parameter(String, Object...).

Specified by:
param in interface RequestSpecification
Parameters:
parameterName - The parameter name
parameterValues - Parameter values, one to many if you want to specify multiple values for the same parameter.
Returns:
The request specification
See Also:
RequestSpecification.parameter(String, Object...)

parameter

public RequestSpecification parameter(String parameterName,
                                      Collection<?> parameterValues)
Description copied from interface: RequestSpecification
Specify a multi-value parameter that'll be sent with the request e.g:

 given().parameter("cars", asList("Volvo", "Saab"))..;
 
This will set the parameter cars=Volvo and cars=Saab.

Specified by:
parameter in interface RequestSpecification
Parameters:
parameterName - The parameter name
parameterValues - The parameter values
Returns:
The request specification

param

public RequestSpecification param(String parameterName,
                                  Collection<?> parameterValues)
Description copied from interface: RequestSpecification
A slightly shorter version of #parameter(String, java.util.Collection }.

Specified by:
param in interface RequestSpecification
Parameters:
parameterName - The parameter name
parameterValues - The parameter values
Returns:
The request specification

queryParameter

public RequestSpecification queryParameter(String parameterName,
                                           Collection<?> parameterValues)
Description copied from interface: RequestSpecification
Specify a multi-value query parameter that'll be sent with the request e.g:

 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.

Specified by:
queryParameter in interface RequestSpecification
Parameters:
parameterName - The parameter name
parameterValues - The parameter values
Returns:
The request specification

queryParam

public RequestSpecification queryParam(String parameterName,
                                       Collection<?> parameterValues)
Description copied from interface: RequestSpecification
A slightly shorter version of #queryParameter(String, java.util.Collection.

Specified by:
queryParam in interface RequestSpecification
Parameters:
parameterName - The parameter name
parameterValues - The parameter values
Returns:
The request specification
See Also:
#queryParam(String, java.util.List)

parameter

public RequestSpecification parameter(String parameterName,
                                      Object... parameterValues)
Description copied from interface: RequestSpecification
Specify a parameter that'll be sent with the request e.g:

 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");
 

Specified by:
parameter in interface RequestSpecification
Parameters:
parameterName - The parameter name
parameterValues - Zero to many parameter values for this parameter name
Returns:
The request specification
See Also:
RequestSpecification.parameters(String, Object, Object...)

queryParameters

public RequestSpecification queryParameters(String firstParameterName,
                                            Object firstParameterValue,
                                            Object... parameterNameValuePairs)
Description copied from interface: RequestSpecification
Specify the query parameters that'll be sent with the request. Note that this method is the same as 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.

Specified by:
queryParameters in interface RequestSpecification
Parameters:
firstParameterName - The name of the first parameter
firstParameterValue - The value of the first parameter
parameterNameValuePairs - The value of the first parameter followed by additional parameters in name-value pairs.
Returns:
The request specification

queryParameters

public RequestSpecification queryParameters(Map parametersMap)
Description copied from interface: RequestSpecification
Specify the query parameters that'll be sent with the request. Note that this method is the same as 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.

Specified by:
queryParameters in interface RequestSpecification
Parameters:
parametersMap - The Map containing the parameter names and their values to send with the request.
Returns:
The request specification

queryParameter

public RequestSpecification queryParameter(String parameterName,
                                           Object... parameterValues)
Description copied from interface: RequestSpecification
Specify a query parameter that'll be sent with the request. Note that this method is the same as 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.

Specified by:
queryParameter in interface RequestSpecification
Parameters:
parameterName - The parameter name
parameterValues - Zero to many parameter values, i.e. you can specify multiple values for the same parameter
Returns:
The request specification
See Also:
RequestSpecification.parameter(String, Object...)

queryParams

public RequestSpecification queryParams(String firstParameterName,
                                        Object firstParameterValue,
                                        Object... parameterNameValuePairs)
Description copied from interface: RequestSpecification
A slightly shorter version of RequestSpecification.queryParameters(String, Object, Object...).

Specified by:
queryParams in interface RequestSpecification
Parameters:
firstParameterName - The name of the first parameter
firstParameterValue - The value of the first parameter
parameterNameValuePairs - The value of the first parameter followed by additional parameters in name-value pairs.
Returns:
The request specification
See Also:
RequestSpecification.queryParameters(String, Object, Object...)

queryParams

public RequestSpecification queryParams(Map parametersMap)
Description copied from interface: RequestSpecification
A slightly shorter version of RequestSpecification.queryParams(java.util.Map).

Specified by:
queryParams in interface RequestSpecification
Parameters:
parametersMap - The Map containing the parameter names and their values to send with the request.
Returns:
The request specification
See Also:
RequestSpecification.queryParams(java.util.Map)

queryParam

public RequestSpecification queryParam(String parameterName,
                                       Object... parameterValues)
Description copied from interface: RequestSpecification
A slightly shorter version of RequestSpecification.queryParameter(String, Object...).

Specified by:
queryParam in interface RequestSpecification
Parameters:
parameterName - The parameter name
parameterValues - Zero to many parameter values. Use additional parameter values if you want to specify multiple values for the same parameter
Returns:
The request specification
See Also:
RequestSpecification.parameter(String, Object...)

formParameter

public RequestSpecification formParameter(String parameterName,
                                          Collection<?> parameterValues)
Description copied from interface: RequestSpecification
Specify a multi-value form parameter that'll be sent with the request e.g:

 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.

Specified by:
formParameter in interface RequestSpecification
Parameters:
parameterName - The parameter name
parameterValues - The parameter values
Returns:
The request specification

formParam

public RequestSpecification formParam(String parameterName,
                                      Collection<?> parameterValues)
Description copied from interface: RequestSpecification
A slightly shorter version of #formParameter(String, java.util.Collection.

Specified by:
formParam in interface RequestSpecification
Parameters:
parameterName - The parameter name
parameterValues - The parameter values
Returns:
The request specification
See Also:
#formParam(String, java.util.List)

formParameters

public RequestSpecification formParameters(String firstParameterName,
                                           Object firstParameterValue,
                                           Object... parameterNameValuePairs)
Description copied from interface: RequestSpecification
Specify the form parameters that'll be sent with the request. Note that this method is the same as 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.

Specified by:
formParameters in interface RequestSpecification
Parameters:
firstParameterName - The name of the first parameter
firstParameterValue - The value of the first parameter
parameterNameValuePairs - The value of the first parameter followed by additional parameters in name-value pairs.
Returns:
The request specification

formParameters

public RequestSpecification formParameters(Map parametersMap)
Description copied from interface: RequestSpecification
Specify the form parameters that'll be sent with the request. Note that this method is the same as 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.

Specified by:
formParameters in interface RequestSpecification
Parameters:
parametersMap - The Map containing the parameter names and their values to send with the request.
Returns:
The request specification

formParameter

public RequestSpecification formParameter(String parameterName,
                                          Object... additionalParameterValues)
Description copied from interface: RequestSpecification
Specify a form parameter that'll be sent with the request. Note that this method is the same as 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.

Specified by:
formParameter in interface RequestSpecification
Parameters:
parameterName - The parameter name
additionalParameterValues - Zero to many parameter values for this parameter.
Returns:
The request specification
See Also:
RequestSpecification.parameter(String, Object...)

formParams

public RequestSpecification formParams(String firstParameterName,
                                       Object firstParameterValue,
                                       Object... parameterNameValuePairs)
Description copied from interface: RequestSpecification
A slightly shorter version of RequestSpecification.formParameters(String, Object, Object...).

Specified by:
formParams in interface RequestSpecification
Parameters:
firstParameterName - The name of the first parameter
firstParameterValue - The value of the first parameter
parameterNameValuePairs - The value of the first parameter followed by additional parameters in name-value pairs.
Returns:
The request specification
See Also:
RequestSpecification.formParameters(String, Object, Object...)

formParams

public RequestSpecification formParams(Map parametersMap)
Description copied from interface: RequestSpecification
A slightly shorter version of RequestSpecification.formParams(java.util.Map).

Specified by:
formParams in interface RequestSpecification
Parameters:
parametersMap - The Map containing the parameter names and their values to send with the request.
Returns:
The request specification
See Also:
RequestSpecification.formParams(java.util.Map)

formParam

public RequestSpecification formParam(String parameterName,
                                      Object... parameterValues)
Description copied from interface: RequestSpecification
A slightly shorter version of RequestSpecification.formParameter(String, Object...).

Specified by:
formParam in interface RequestSpecification
Parameters:
parameterName - The parameter name
parameterValues - Zero to many parameter values. You can specify multiple values for the same parameter.
Returns:
The request specification
See Also:
RequestSpecification.parameter(String, Object...)

urlEncodingEnabled

public RequestSpecification urlEncodingEnabled(boolean isEnabled)
Description copied from interface: RequestSpecification
Specifies if Rest Assured should url encode the URL automatically. Usually this is a recommended but in some cases e.g. the query parameters are already be encoded before you provide them to Rest Assured then it's useful to disable URL encoding.

Specified by:
urlEncodingEnabled in interface RequestSpecification
Parameters:
isEnabled - Specify whether or not URL encoding should be enabled or disabled.
Returns:
the request specification

pathParameter

public RequestSpecification pathParameter(String parameterName,
                                          Object parameterValue)
Description copied from interface: RequestSpecification
Specify a path parameter. Path parameters are used to improve readability of the request path. E.g. instead of writing:
 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);
 

Specified by:
pathParameter in interface RequestSpecification
Parameters:
parameterName - The parameter name
parameterValue - The parameter value
Returns:
The request specification

pathParameters

public RequestSpecification pathParameters(String firstParameterName,
                                           Object firstParameterValue,
                                           Object... parameterNameValuePairs)
Description copied from interface: RequestSpecification
Specify multiple path parameter name-value pairs. Path parameters are used to improve readability of the request path. E.g. instead of writing:
 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);
 

Specified by:
pathParameters in interface RequestSpecification
Parameters:
firstParameterName - The name of the first parameter
firstParameterValue - The value of the first parameter
parameterNameValuePairs - Additional parameters in name-value pairs.
Returns:
The request specification

pathParameters

public RequestSpecification pathParameters(Map parameterNameValuePairs)
Description copied from interface: RequestSpecification
Specify multiple path parameter name-value pairs. Path parameters are used to improve readability of the request path. E.g. instead of writing:
 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);
 

Specified by:
pathParameters in interface RequestSpecification
Parameters:
parameterNameValuePairs - A map containing the path parameters.
Returns:
The request specification

pathParam

public RequestSpecification pathParam(String parameterName,
                                      Object parameterValue)
Description copied from interface: RequestSpecification
A slightly shorter version of RequestSpecification.pathParameter(String, Object).

Specified by:
pathParam in interface RequestSpecification
Parameters:
parameterName - The parameter name
parameterValue - The parameter value
Returns:
The request specification
See Also:
RequestSpecification.pathParameter(String, Object)

pathParams

public RequestSpecification pathParams(String firstParameterName,
                                       Object firstParameterValue,
                                       Object... parameterNameValuePairs)
Description copied from interface: RequestSpecification
A slightly shorter version of RequestSpecification.pathParameters(String, Object, Object...).

Specified by:
pathParams in interface RequestSpecification
Parameters:
firstParameterName - The name of the first parameter
firstParameterValue - The value of the first parameter
parameterNameValuePairs - Additional parameters in name-value pairs.
Returns:
The request specification
See Also:
RequestSpecification.pathParameters(String, Object, Object...)

pathParams

public RequestSpecification pathParams(Map parameterNameValuePairs)
Description copied from interface: RequestSpecification
A slightly shorter version of RequestSpecification.pathParameters(java.util.Map).

Specified by:
pathParams in interface RequestSpecification
Parameters:
parameterNameValuePairs - A map containing the path parameters.
Returns:
The request specification
See Also:
RequestSpecification.pathParameters(java.util.Map)

config

public RequestSpecification config(RestAssuredConfig config)
Description copied from interface: RequestSpecification
Define a configuration for redirection settings and http client parameters. E.g.
 given().config(config().redirect(redirectConfig().followRedirects(true).and().maxRedirects(0))). ..
 
config() can be statically imported from RestAssuredConfig.

Specified by:
config in interface RequestSpecification
Parameters:
config - The configuration to use for this request. If null no config will be used.
Returns:
The request specification

keystore

public RequestSpecification keystore(File pathToJks,
                                     String password)
Description copied from interface: RequestSpecification
Use a keystore located on the file-system. See RequestSpecification.keystore(String, String) for more details.

Specified by:
keystore in interface RequestSpecification
Parameters:
pathToJks - The path to JKS file on the file-system
password - The password for the keystore
Returns:
The request specification
See Also:
RequestSpecification.keystore(String, String)

keystore

public RequestSpecification keystore(String pathToJks,
                                     String password)
Description copied from interface: RequestSpecification
The following documentation is taken from http://groovy.codehaus.org/modules/http-builder/doc/ssl.html:

SSL Configuration

SSL should, for the most part, "just work." There are a few situations where it is not completely intuitive. You can follow the example below, or see HttpClient's SSLSocketFactory documentation for more information.

SSLPeerUnverifiedException

If you can't connect to an SSL website, it is likely because the certificate chain is not trusted. This is an Apache HttpClient issue, but explained here for convenience. To correct the untrusted certificate, you need to import a certificate into an SSL truststore. First, export a certificate from the website using your browser. For example, if you go to https://dev.java.net in Firefox, you will probably get a warning in your browser. Choose "Add Exception," "Get Certificate," "View," "Details tab." Choose a certificate in the chain and export it as a PEM file. You can view the details of the exported certificate like so:
 $ 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.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 keystore
 
Now you want to use this truststore in your client:
 RestAssured.keystore("/truststore.jks", "test1234");
 
or
 given().keystore("/truststore.jks", "test1234"). ..
 

Specified by:
keystore in interface RequestSpecification
Parameters:
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 pass
Returns:
The request specification

filter

public RequestSpecification filter(Filter filter)
Description copied from interface: RequestSpecification
Add a filter that will be used in the request.

Specified by:
filter in interface RequestSpecification
Parameters:
filter - The filter to add
Returns:
the request specification

filters

public RequestSpecification filters(List<Filter> filters)
Description copied from interface: RequestSpecification
Add filters that will be used in the request.

Specified by:
filters in interface RequestSpecification
Parameters:
filters - The filters to add
Returns:
the request specification

filters

public RequestSpecification filters(Filter filter,
                                    Filter... additionalFilter)
Description copied from interface: RequestSpecification
Add filters that will be used in the request.

Specified by:
filters in interface RequestSpecification
Parameters:
filter - The filter to add
additionalFilter - Additional filters to add
Returns:
the request specification

log

public RequestLogSpecification log()
Description copied from interface: RequestSpecification
Returns the 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(..))). ..
 

Specified by:
log in interface RequestSpecification
Returns:
the request log specification

and

public RequestSpecification and()
Description copied from interface: RequestSpecification
Syntactic sugar, e.g.
 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");
 

Specified by:
and in interface RequestSpecification
Returns:
the request specification

request

public RequestSpecification request()
Description copied from interface: RequestSpecification
Syntactic sugar, e.g.
 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");
 

Specified by:
request in interface RequestSpecification
Returns:
the request specification

with

public RequestSpecification with()
Description copied from interface: RequestSpecification
Syntactic sugar, e.g.
 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");
 

Specified by:
with in interface RequestSpecification
Returns:
the request specification

then

public ResponseSpecification then()
Description copied from interface: RequestSpecification
Returns the response specification so that you can setup the expectations on the response. E.g.
 given().param("name", "value").then().body(equalTo("something")).when().get("/something");
 

Specified by:
then in interface RequestSpecification
Returns:
the response specification

expect

public ResponseSpecification expect()
Description copied from interface: RequestSpecification
Returns the response specification so that you can setup the expectations on the response. E.g.
 given().param("name", "value").and().expect().body(equalTo("something")).when().get("/something");
 

Specified by:
expect in interface RequestSpecification
Returns:
the response specification

auth

public AuthenticationSpecification auth()
Description copied from interface: RequestSpecification
A slightly short version of RequestSpecification.authentication().

Specified by:
auth in interface RequestSpecification
Returns:
The authentication specification
See Also:
RequestSpecification.authentication(), AuthenticationSpecification

authentication

public AuthenticationSpecification authentication()
Description copied from interface: RequestSpecification
If you need to specify some credentials when performing a request.

Specified by:
authentication in interface RequestSpecification
Returns:
The authentication specification
See Also:
AuthenticationSpecification

port

public RequestSpecification port(int port)
Description copied from interface: RequestSpecification
Specify the port of the URI. E.g.

 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");
 

Specified by:
port in interface RequestSpecification
Parameters:
port - The port of URI
Returns:
The request specification

body

public RequestSpecification body(String body)
Description copied from interface: RequestSpecification
Specify a String request body (such as e.g. JSON or XML) that'll be sent with the request. This works for the POST and PUT methods only. Trying to do this for the other http methods will cause an exception to be thrown.

Example of use:

 given().body("{ \"message\" : \"hello world\"}").then().expect().body(equalTo("hello world")).when().post("/json");
 
This will POST a request containing JSON to "/json" and expect that the response body equals to "hello world".

Note that RequestSpecification.body(String) and RequestSpecification.content(String) are the same except for the syntactic difference.

Specified by:
body in interface RequestSpecification
Parameters:
body - The body to send.
Returns:
The request specification

content

public RequestSpecification content(String content)
Description copied from interface: RequestSpecification
Specify a String request content (such as e.g. JSON or XML) that'll be sent with the request. This works for the POST and PUT methods only. Trying to do this for the other http methods will cause an exception to be thrown.

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 RequestSpecification.content(String) are the same except for the syntactic difference.

Specified by:
content in interface RequestSpecification
Parameters:
content - The content to send.
Returns:
The request specification

body

public RequestSpecification body(byte... body)
Description copied from interface: RequestSpecification
Specify a byte array request body that'll be sent with the request. This only works for the POST http method. Trying to do this for the other http methods will cause an exception to be thrown.

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 RequestSpecification.body(byte[]) and RequestSpecification.content(byte[]) are the same except for the syntactic difference.

Specified by:
body in interface RequestSpecification
Parameters:
body - The body to send.
Returns:
The request specification

content

public RequestSpecification content(byte... content)
Description copied from interface: RequestSpecification
Specify a byte array request content that'll be sent with the request. This only works for the POST http method. Trying to do this for the other http methods will cause an exception to be thrown.

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 RequestSpecification.content(byte[]) are the same except for the syntactic difference.

Specified by:
content in interface RequestSpecification
Parameters:
content - The content to send.
Returns:
The request specification

body

public RequestSpecification body(Object object)
Description copied from interface: RequestSpecification
Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request. If the object is a primitive or Number the object will be converted to a String and put in the request body. This works for the POST and PUT methods only. Trying to do this for the other http methods will cause an exception to be thrown.

Example of use:

 Message message = new Message();
 message.setMessage("My beautiful message");

 given().
         contentType("application/json").
         body(message).
 expect().
         content(equalTo("Response to a beautiful message")).
 when().
         post("/beautiful-message");
 

Since the content-type is "application/json" then REST Assured will automatically try to serialize the object using Jackson or Gson if they are available in the classpath. If any of these frameworks are not in the classpath then an exception is thrown.
If the content-type is "application/xml" then REST Assured will automatically try to serialize the object using JAXB if it's available in the classpath. Otherwise an exception will be thrown.
If no request content-type is specified then REST Assured determine the parser in the following order:
  1. Jackson
  2. Gson
  3. JAXB

Note that RequestSpecification.body(Object) and RequestSpecification.content(Object) are the same except for the syntactic difference.

Specified by:
body in interface RequestSpecification
Parameters:
object - The object to serialize and send with the request
Returns:
The request specification

content

public RequestSpecification content(Object object)
Description copied from interface: RequestSpecification
Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request. If the object is a primitive or Number the object will be converted to a String and put in the request body. This works for the POST and PUT methods only. Trying to do this for the other http methods will cause an exception to be thrown.

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.
If the content-type is "application/xml" then REST Assured will automatically try to serialize the object using JAXB if it's available in the classpath. Otherwise an exception will be thrown.
If no request content-type is specified then REST Assured determine the parser in the following order:
  1. Jackson
  2. Gson
  3. JAXB

Note that RequestSpecification.body(Object) and RequestSpecification.content(Object) are the same except for the syntactic difference.

Specified by:
content in interface RequestSpecification
Parameters:
object - The object to serialize and send with the request
Returns:
The request specification

body

public RequestSpecification body(Object object,
                                 ObjectMapper mapper)
Description copied from interface: RequestSpecification
Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request using a specific object mapper. This works for the POST and PUT methods only. Trying to do this for the other http methods will cause an exception to be thrown.

Example of use:

 Message message = new Message();
 message.setMessage("My beautiful message");

 given().
         body(message, ObjectMapper.GSON).
 expect().
         content(equalTo("Response to a beautiful message")).
 when().
         post("/beautiful-message");
 

Note that RequestSpecification.body(Object, ObjectMapper) and RequestSpecification.content(Object, ObjectMapper) are the same except for the syntactic difference.

Specified by:
body in interface RequestSpecification
Parameters:
object - The object to serialize and send with the request
Returns:
The request specification

content

public RequestSpecification content(Object object,
                                    ObjectMapper mapper)
Description copied from interface: RequestSpecification
Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request using a specific object mapper. This works for the POST and PUT methods only. Trying to do this for the other http methods will cause an exception to be thrown.

Example of use:

 Message message = new Message();
 message.setMessage("My beautiful message");

 given().
         content(message, ObjectMapper.GSON).
 expect().
         content(equalTo("Response to a beautiful message")).
 when().
         post("/beautiful-message");
 

Note that RequestSpecification.body(Object, ObjectMapper) and RequestSpecification.content(Object, ObjectMapper) are the same except for the syntactic difference.

Specified by:
content in interface RequestSpecification
Parameters:
object - The object to serialize and send with the request
Returns:
The request specification

contentType

public RequestSpecification contentType(ContentType contentType)
Description copied from interface: RequestSpecification
Specify the content type of the request.

Specified by:
contentType in interface RequestSpecification
Parameters:
contentType - The content type of the request
Returns:
The request specification
See Also:
ContentType

contentType

public RequestSpecification contentType(String contentType)
Description copied from interface: RequestSpecification
Specify the content type of the request.

Specified by:
contentType in interface RequestSpecification
Parameters:
contentType - The content type of the request
Returns:
The request specification
See Also:
ContentType

headers

public RequestSpecification headers(Map headers)
Description copied from interface: RequestSpecification
Specify the headers that'll be sent with the request as Map e.g:
 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:
  1. headerName1=headerValue1
  2. headerName2=headerValue2
and expect that the response body is equal to "something".

Specified by:
headers in interface RequestSpecification
Parameters:
headers - The Map containing the header names and their values to send with the request.
Returns:
The request specification

headers

public RequestSpecification headers(Headers headers)
Description copied from interface: RequestSpecification
Specify the headers that'll be sent with the request as 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:
  1. headerName1=headerValue1
  2. headerName2=headerValue2
and expect that the response body is equal to "something".

Specified by:
headers in interface RequestSpecification
Parameters:
headers - The headers to use in the request
Returns:
The request specification

header

public RequestSpecification header(String headerName,
                                   Object headerValue,
                                   Object... additionalHeaderValues)
Description copied from interface: RequestSpecification
Specify a header that'll be sent with the request e.g:

 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.

Specified by:
header in interface RequestSpecification
Parameters:
headerName - The header name
headerValue - The header value
additionalHeaderValues - Additional header values. This will actually create two headers with the same name but with different values.
Returns:
The request specification
See Also:
RequestSpecification.headers(String, Object, Object...)

header

public RequestSpecification header(Header header)
Description copied from interface: RequestSpecification
Specify a 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".

Specified by:
header in interface RequestSpecification
Parameters:
header - The header to add to the request
Returns:
The request specification
See Also:
RequestSpecification.headers(com.jayway.restassured.response.Headers)

headers

public RequestSpecification headers(String firstHeaderName,
                                    Object firstHeaderValue,
                                    Object... headerNameValuePairs)
Description copied from interface: RequestSpecification
Specify the headers that'll be sent with the request. This is done by specifying the headers in name-value pairs, e.g:
 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:
  1. headerName1=headerValue1
  2. headerName2=headerValue2
and expect that the response body is equal to "something".

Specified by:
headers in interface RequestSpecification
Parameters:
firstHeaderName - The name of the first header
firstHeaderValue - The value of the first header
headerNameValuePairs - Additional headers in name-value pairs.
Returns:
The request specification

cookies

public RequestSpecification cookies(String firstCookieName,
                                    Object firstCookieValue,
                                    Object... cookieNameValuePairs)
Description copied from interface: RequestSpecification
Specify the cookies that'll be sent with the request. This is done by specifying the cookies in name-value pairs, e.g:
 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:
  1. username=John
  2. token=1234
and expect that the response body is equal to "username, token".

Specified by:
cookies in interface RequestSpecification
Parameters:
firstCookieName - The name of the first cookie
firstCookieValue - The value of the first cookie
cookieNameValuePairs - Additional cookies in name-value pairs.
Returns:
The request specification

cookies

public RequestSpecification cookies(Map cookies)
Description copied from interface: RequestSpecification
Specify the cookies that'll be sent with the request as Map e.g:
 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:
  1. username=John
  2. token=1234
and expect that the response body is equal to "username, token".

Specified by:
cookies in interface RequestSpecification
Parameters:
cookies - The Map containing the cookie names and their values to set in the request.
Returns:
The request specification

cookies

public RequestSpecification cookies(Cookies cookies)
Description copied from interface: RequestSpecification
Specify the cookies that'll be sent with the request as 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:
  1. username=John
  2. token=1234
and expect that the response body is equal to "username, token".

Specified by:
cookies in interface RequestSpecification
Parameters:
cookies - The cookies to set in the request.
Returns:
The request specification

cookie

public RequestSpecification cookie(String cookieName,
                                   Object value,
                                   Object... additionalValues)
Description copied from interface: RequestSpecification
Specify a cookie that'll be sent with the request e.g:

 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.

Specified by:
cookie in interface RequestSpecification
Parameters:
cookieName - The cookie cookieName
value - The cookie value
additionalValues - Additional cookies values. This will actually create two cookies with the same name but with different values.
Returns:
The request specification
See Also:
RequestSpecification.cookies(String, Object, Object...)

cookie

public RequestSpecification cookie(Cookie cookie)
Description copied from interface: RequestSpecification
Specify a 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".

Specified by:
cookie in interface RequestSpecification
Parameters:
cookie - The cookie to add to the request
Returns:
The request specification
See Also:
RequestSpecification.cookies(com.jayway.restassured.response.Cookies)

cookie

public RequestSpecification cookie(String cookieName)
Description copied from interface: RequestSpecification
Specify a cookie with no value that'll be sent with the request e.g:

 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".

Specified by:
cookie in interface RequestSpecification
Parameters:
cookieName - The cookie cookieName
Returns:
The request specification
See Also:
RequestSpecification.cookies(String, Object, Object...)

redirects

public RedirectSpecification redirects()
Description copied from interface: RequestSpecification
Specify the redirect configuration for this request. E.g.
  given().redirects().max(12).and().redirects().follow(true).when(). ..
 

Specified by:
redirects in interface RequestSpecification
Returns:
The redirect specification

spec

public RequestSpecification spec(RequestSpecification requestSpecificationToMerge)
Description copied from interface: RequestSpecification
Add request data from a pre-defined specification. E.g.
 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:

The following settings are merged: This method is the same as RequestSpecification.specification(RequestSpecification) but the name is a bit shorter.

Specified by:
spec in interface RequestSpecification
Parameters:
requestSpecificationToMerge - The specification to merge with.
Returns:
the request specification

specification

public RequestSpecification specification(RequestSpecification requestSpecificationToMerge)
Description copied from interface: RequestSpecification
Add request data from a pre-defined specification. E.g.
 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:

The following settings are merged: This method is the same as RequestSpecification.specification(RequestSpecification) but the name is a bit shorter.

Specified by:
specification in interface RequestSpecification
Parameters:
requestSpecificationToMerge - The specification to merge with.
Returns:
the request specification

sessionId

public RequestSpecification sessionId(String sessionIdValue)
Description copied from interface: RequestSpecification
Set the session id for this request. It will use the configured session id name from the configuration (by default this is "JSESSIONID"). You can configure the session id name by using:
     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.

Specified by:
sessionId in interface RequestSpecification
Parameters:
sessionIdValue - The session id value.
Returns:
The request specification

sessionId

public RequestSpecification sessionId(String sessionIdName,
                                      String sessionIdValue)
Description copied from interface: RequestSpecification
Set the session id name and value for this request. It'll override the default session id name from the configuration (by default this is "JSESSIONID"). You can configure the default session id name by using:
     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.

Specified by:
sessionId in interface RequestSpecification
Parameters:
sessionIdName - The session id name
sessionIdValue - The session id value.
Returns:
The request specification

multiPart

public RequestSpecification multiPart(String controlName,
                                      File file)
Description copied from interface: RequestSpecification
Specify a file to upload to the server using multi-part form data uploading with a specific control name. It will use the mime-type application/octet-stream. If this is not what you want please use an overloaded method.

Specified by:
multiPart in interface RequestSpecification
Parameters:
controlName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
file - The file to upload
Returns:
The request specification

multiPart

public RequestSpecification multiPart(File file)
Description copied from interface: RequestSpecification
Specify a file to upload to the server using multi-part form data uploading. It will assume that the control name is file and the mime-type is application/octet-stream. If this is not what you want please use an overloaded method.

Specified by:
multiPart in interface RequestSpecification
Parameters:
file - The file to upload
Returns:
The request specification

multiPart

public RequestSpecification multiPart(String name,
                                      File file,
                                      String mimeType)
Description copied from interface: RequestSpecification
Specify a file to upload to the server using multi-part form data uploading with a specific control name and mime-type.

Specified by:
multiPart in interface RequestSpecification
Parameters:
name - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
file - The file to upload
mimeType - The mime-type
Returns:
The request specification

multiPart

public RequestSpecification multiPart(String controlName,
                                      Object object)
Description copied from interface: RequestSpecification
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. It will use mime-type application/json. If this is not what you want please use an overloaded method.

Specified by:
multiPart in interface RequestSpecification
Parameters:
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 server
Returns:
The request specification

multiPart

public RequestSpecification multiPart(String controlName,
                                      Object object,
                                      String mimeType)
Description copied from interface: RequestSpecification
Specify an object that will be serialized and uploaded to the server using multi-part form data uploading with a specific control name.

Specified by:
multiPart in interface RequestSpecification
Parameters:
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 server
mimeType - The mime-type
Returns:
The request specification

multiPart

public RequestSpecification multiPart(String name,
                                      String fileName,
                                      byte... bytes)
Description copied from interface: RequestSpecification
Specify a byte-array to upload to the server using multi-part form data. It will use the mime-type application/octet-stream. If this is not what you want please use an overloaded method.

Specified by:
multiPart in interface RequestSpecification
Parameters:
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 uploading
bytes - The bytes you want to send
Returns:
The request specification

multiPart

public RequestSpecification multiPart(String name,
                                      String fileName,
                                      byte[] bytes,
                                      String mimeType)
Description copied from interface: RequestSpecification
Specify a byte-array to upload to the server using multi-part form data.

Specified by:
multiPart in interface RequestSpecification
Parameters:
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 uploading
bytes - The bytes you want to send
mimeType - The mime-type
Returns:
The request specification

multiPart

public RequestSpecification multiPart(String name,
                                      String fileName,
                                      InputStream stream)
Description copied from interface: RequestSpecification
Specify an inputstream to upload to the server using multi-part form data. It will use the mime-type application/octet-stream. If this is not what you want please use an overloaded method.

Specified by:
multiPart in interface RequestSpecification
Parameters:
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 uploading
stream - The stream you want to send
Returns:
The request specification

multiPart

public RequestSpecification multiPart(String name,
                                      String fileName,
                                      InputStream stream,
                                      String mimeType)
Description copied from interface: RequestSpecification
Specify an inputstream to upload to the server using multi-part form data.

Specified by:
multiPart in interface RequestSpecification
Parameters:
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 uploading
stream - The stream you want to send
mimeType - The mime-type
Returns:
The request specification

multiPart

public RequestSpecification multiPart(String name,
                                      String contentBody)
Description copied from interface: RequestSpecification
Specify a string to send to the server using multi-part form data. It will use the mime-type text/plain. If this is not what you want please use an overloaded method.

Specified by:
multiPart in interface RequestSpecification
Parameters:
name - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
contentBody - The string to send
Returns:
The request specification

multiPart

public RequestSpecification multiPart(String name,
                                      NoParameterValue contentBody)

multiPart

public RequestSpecification multiPart(String name,
                                      String contentBody,
                                      String mimeType)
Description copied from interface: RequestSpecification
Specify a string to send to the server using multi-part form data with a specific mime-type.

Specified by:
multiPart in interface RequestSpecification
Parameters:
name - Defines the control name of the body part. In HTML this is the attribute name of the input tag.
contentBody - The string to send
mimeType - The mime-type
Returns:
The request specification

invokeFilterChain

public Object invokeFilterChain(Object path,
                                Object method,
                                Object assertionClosure)

applyRestAssuredConfig

public Object applyRestAssuredConfig(HTTPBuilder http)

applySessionConfig

public Object applySessionConfig(SessionConfig sessionConfig)

applyEncoderConfig

public Object applyEncoderConfig(HTTPBuilder httpBuilder,
                                 EncoderConfig encoderConfig)

applyHttpClientConfig

public Object applyHttpClientConfig(HttpClientConfig httpClientConfig)

applyRedirectConfig

public Object applyRedirectConfig(RedirectConfig redirectConfig)

assembleBodyContent

public Object assembleBodyContent(Object httpMethod)

setRequestHeadersToHttpBuilder

public Object setRequestHeadersToHttpBuilder(HTTPBuilder http)

setResponseSpecification

public void setResponseSpecification(ResponseSpecification responseSpecification)

getBaseUri

public String getBaseUri()
Specified by:
getBaseUri in interface FilterableRequestSpecification
Returns:
The base URI defined in the request specification

getBasePath

public String getBasePath()
Specified by:
getBasePath in interface FilterableRequestSpecification
Returns:
The base path defined in the request specification

getPort

public int getPort()
Specified by:
getPort in interface FilterableRequestSpecification
Returns:
The port defined in the request specification

getFormParams

public Map<String,Object> getFormParams()
Specified by:
getFormParams in interface FilterableRequestSpecification
Returns:
The form parameters defined in the request specification

getPathParams

public Map<String,Object> getPathParams()
Specified by:
getPathParams in interface FilterableRequestSpecification
Returns:
The (named) path parameters defined in the request specification

getRequestParams

public Map<String,Object> getRequestParams()
Specified by:
getRequestParams in interface FilterableRequestSpecification
Returns:
The request parameters defined in the request specification

getQueryParams

public Map<String,Object> getQueryParams()
Specified by:
getQueryParams in interface FilterableRequestSpecification
Returns:
The query parameters defined in the request specification

getHeaders

public Headers getHeaders()
Specified by:
getHeaders in interface FilterableRequestSpecification
Returns:
The headers defined in the request specification

getCookies

public Cookies getCookies()
Specified by:
getCookies in interface FilterableRequestSpecification
Returns:
The cookies defined in the request specification

getBody

public <T> T getBody()
Specified by:
getBody in interface FilterableRequestSpecification
Returns:
The request body

getDefinedFilters

public List<Filter> getDefinedFilters()
Specified by:
getDefinedFilters in interface FilterableRequestSpecification
Returns:
The filters (unmodifiable)

getConfig

public RestAssuredConfig getConfig()
Specified by:
getConfig in interface FilterableRequestSpecification
Returns:
The Rest Assured configurations

getRequestContentType

public String getRequestContentType()
Specified by:
getRequestContentType in interface FilterableRequestSpecification
Returns:
The request content type defined in the request specification

noFilters

public RequestSpecification noFilters()
Description copied from interface: RequestSpecification
Remove all applied filters

Specified by:
noFilters in interface RequestSpecification
Returns:
the request specification

noFiltersOfType

public <T extends Filter> RequestSpecification noFiltersOfType(Class<T> filterType)
Description copied from interface: RequestSpecification
Remove all applied filters

Specified by:
noFiltersOfType in interface RequestSpecification
Returns:
the request specification


Copyright © 2010-2012. All Rights Reserved.