|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jayway.restassured.builder.RequestSpecBuilder
public class RequestSpecBuilder
You can use the builder to construct a request specification. The specification can be used as e.g.
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
RequestSpecification requestSpec = new RequestSpecBuilder().addParam("parameter1", "value1").build();
given(responseSpec, requestSpec).post("/something");
or
RequestSpecification requestSpec = new RequestSpecBuilder().addParameter("parameter1", "value1").build();
given().
spec(requestSpec).
expect().
body("x.y.z", equalTo("something")).
when().
get("/something");
| Constructor Summary | |
|---|---|
RequestSpecBuilder()
|
|
| Method Summary | |
|---|---|
RequestSpecBuilder |
addCookie(Cookie cookie)
Add a detailed cookie |
RequestSpecBuilder |
addCookie(String name)
Add a cookie without value to be sent with the request. |
RequestSpecBuilder |
addCookie(String key,
Object value,
Object... cookieNameValuePairs)
Add a cookie to be sent with the request. |
RequestSpecBuilder |
addCookies(Cookies cookies)
Specify multiple detailed cookies that'll be sent with the request. |
RequestSpecBuilder |
addCookies(Map<String,?> cookies)
Add cookies to be sent with the request as Map e.g: |
RequestSpecBuilder |
addFilter(Filter filter)
Add a filter that will be used in the request. |
RequestSpecBuilder |
addFilters(List<Filter> filters)
Add filters that will be used in the request. |
RequestSpecBuilder |
addFormParam(String parameterName,
Collection<?> parameterValues)
A slightly shorter version of #addFormParameter(String, java.util.Collection. |
RequestSpecBuilder |
addFormParam(String parameterName,
Object... parameterValues)
A slightly shorter version of addFormParameter(String, Object...). |
RequestSpecBuilder |
addFormParameter(String parameterName,
Collection<?> parameterValues)
Add a form parameter to be sent with the request. |
RequestSpecBuilder |
addFormParameter(String parameterName,
Object... parameterValues)
Add a form parameter to be sent with the request. |
RequestSpecBuilder |
addFormParameters(Map<String,?> parametersMap)
Add query parameters to be sent with the request as a Map. |
RequestSpecBuilder |
addFormParams(Map<String,?> parametersMap)
A slightly shorter version of addFormParameters(Map). |
RequestSpecBuilder |
addHeader(String headerName,
String headerValue)
Add a header to be sent with the request e.g: |
RequestSpecBuilder |
addHeaders(Map<String,String> headers)
Add headers to be sent with the request as Map. |
RequestSpecBuilder |
addMultiPart(File file)
Specify a file to upload to the server using multi-part form data uploading. |
RequestSpecBuilder |
addMultiPart(String controlName,
File file)
Specify a file to upload to the server using multi-part form data uploading with a specific control name. |
RequestSpecBuilder |
addMultiPart(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 content-type. |
RequestSpecBuilder |
addMultiPart(String controlName,
String contentBody)
Specify a string to send to the server using multi-part form data. |
RequestSpecBuilder |
addMultiPart(String controlName,
String fileName,
byte[] bytes)
Specify a byte-array to upload to the server using multi-part form data. |
RequestSpecBuilder |
addMultiPart(String controlName,
String fileName,
byte[] bytes,
String mimeType)
Specify a byte-array to upload to the server using multi-part form data. |
RequestSpecBuilder |
addMultiPart(String controlName,
String fileName,
InputStream stream)
Specify an inputstream to upload to the server using multi-part form data. |
RequestSpecBuilder |
addMultiPart(String controlName,
String fileName,
InputStream stream,
String mimeType)
Specify an inputstream to upload to the server using multi-part form data. |
RequestSpecBuilder |
addMultiPart(String controlName,
String contentBody,
String mimeType)
Specify a string to send to the server using multi-part form data with a specific mime-type. |
RequestSpecBuilder |
addParam(String parameterName,
Collection<?> parameterValues)
A slightly shorter version of #addParameter(String, java.util.Collection. |
RequestSpecBuilder |
addParam(String parameterName,
Object... parameterValues)
A slightly shorter version of addParameter(String, Object...). |
RequestSpecBuilder |
addParameter(String parameterName,
Collection<?> parameterValues)
Add a multi-value parameter to be sent with the request. |
RequestSpecBuilder |
addParameter(String parameterName,
Object... parameterValues)
Add a parameter to be sent with the request. |
RequestSpecBuilder |
addParameters(Map<String,?> parametersMap)
Add parameters to be sent with the request as Map. |
RequestSpecBuilder |
addParams(Map<String,?> parametersMap)
A slightly shorter version of addParameters(Map). |
RequestSpecBuilder |
addPathParam(String parameterName,
Object parameterValue)
A slightly shorter version of addPathParameter(String, Object). |
RequestSpecBuilder |
addPathParameter(String parameterName,
Object parameterValue)
Specify a path parameter. |
RequestSpecBuilder |
addPathParameters(Map<String,?> parameterNameValuePairs)
Specify multiple path parameter name-value pairs. |
RequestSpecBuilder |
addPathParameters(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
Specify multiple path parameter name-value pairs. |
RequestSpecBuilder |
addPathParams(Map<String,?> parameterNameValuePairs)
A slightly shorter version of addPathParameters(java.util.Map). |
RequestSpecBuilder |
addPathParams(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
A slightly shorter version of addPathParameters(String, Object, Object...). |
RequestSpecBuilder |
addQueryParam(String parameterName,
Collection<?> parameterValues)
A slightly shorter version of addQueryParameter(String, java.util.Collection). |
RequestSpecBuilder |
addQueryParam(String parameterName,
Object... parameterValues)
A slightly shorter version of addQueryParameter(String, Object...). |
RequestSpecBuilder |
addQueryParameter(String parameterName,
Collection<?> parameterValues)
Add a query parameter to be sent with the request. |
RequestSpecBuilder |
addQueryParameter(String parameterName,
Object... parameterValues)
Add a query parameter to be sent with the request. |
RequestSpecBuilder |
addQueryParameters(Map<String,?> parametersMap)
Add query parameters to be sent with the request as a Map. |
RequestSpecBuilder |
addQueryParams(Map<String,?> parametersMap)
A slightly shorter version of addQueryParameters(Map). |
RequestSpecBuilder |
addRequestSpecification(RequestSpecification specification)
Merge this builder with settings from another specification. |
RequestSpecification |
build()
Build the request specification. |
RequestSpecBuilder |
setAuth(AuthenticationScheme auth)
A slightly short version of setAuthentication(com.jayway.restassured.authentication.AuthenticationScheme) )}. |
RequestSpecBuilder |
setAuthentication(AuthenticationScheme auth)
If you need to specify some credentials when performing a request. |
RequestSpecBuilder |
setBody(byte[] body)
Specify a byte array request body to be sent with the request. |
RequestSpecBuilder |
setBody(String body)
Specify a String request body (such as e.g. |
RequestSpecBuilder |
setConfig(RestAssuredConfig config)
Define a configuration for redirection settings and http client parameters. |
RequestSpecBuilder |
setContent(byte[] content)
Specify a byte array request content to be sent with the request. |
RequestSpecBuilder |
setContent(String content)
Specify a String request content (such as e.g. |
RequestSpecBuilder |
setContentType(ContentType contentType)
Specify the content type of the request. |
RequestSpecBuilder |
setContentType(String contentType)
Specify the content type of the request as string. |
RequestSpecBuilder |
setKeystore(String pathToJks,
String password)
The following documentation is taken from http://groovy.codehaus.org/modules/http-builder/doc/ssl.html: |
RequestSpecBuilder |
setPort(int port)
Specify the port. |
RequestSpecBuilder |
setSessionId(String sessionIdValue)
Set the session id for this request. |
RequestSpecBuilder |
setSessionId(String sessionIdName,
String sessionIdValue)
Set the session id name and value for this request. |
RequestSpecBuilder |
setUrlEncodingEnabled(boolean isEnabled)
Specifies if Rest Assured should url encode the URL automatically. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public RequestSpecBuilder()
| Method Detail |
|---|
public RequestSpecBuilder setBody(String body)
Note that setBody(String) and setContent(String) are the same except for the syntactic difference.
body - The body to send.
public RequestSpecBuilder setBody(byte[] body)
Note that setBody(byte[]) and setContent(byte[]) are the same except for the syntactic difference.
body - The body to send.
public RequestSpecBuilder setContent(String content)
Note that setBody(String) and setContent(String) are the same except for the syntactic difference.
content - The content to send.
public RequestSpecBuilder setContent(byte[] content)
Note that setBody(byte[]) and setContent(byte[]) are the same except for the syntactic difference.
content - The content to send.
public RequestSpecBuilder addCookies(Map<String,?> cookies)
cookies - The Map containing the cookie names and their values to set in the request.
public RequestSpecBuilder addCookie(Cookie cookie)
cookie - The cookie to add.
public RequestSpecBuilder addCookie(String key,
Object value,
Object... cookieNameValuePairs)
key - The cookie keyvalue - The cookie valuecookieNameValuePairs - Additional cookies values. This will actually create two cookies with the same name but with different values.
public RequestSpecBuilder addCookie(String name)
name - The cookie name
public RequestSpecBuilder addCookies(Cookies cookies)
cookies - The cookies to set in the request.
RequestSpecification.cookies(com.jayway.restassured.response.Cookies)public RequestSpecBuilder addFilter(Filter filter)
filter - The filter to add
public RequestSpecBuilder addFilters(List<Filter> filters)
filters - The filters to add
public RequestSpecBuilder addParameters(Map<String,?> parametersMap)
parametersMap - The Map containing the parameter names and their values to send with the request.
public RequestSpecBuilder addParameter(String parameterName,
Object... parameterValues)
parameterName - The parameter nameparameterValues - Zero to many parameter values for this parameter name.
public RequestSpecBuilder addParameter(String parameterName,
Collection<?> parameterValues)
parameterName - The parameter keyparameterValues - The parameter values
public RequestSpecBuilder addParams(Map<String,?> parametersMap)
addParameters(Map).
parametersMap - The Map containing the parameter names and their values to send with the request.
public RequestSpecBuilder addParam(String parameterName,
Object... parameterValues)
addParameter(String, Object...).
parameterValues - Zero to many parameter values for this parameter name.
addParameter(String, Object...)
public RequestSpecBuilder addParam(String parameterName,
Collection<?> parameterValues)
#addParameter(String, java.util.Collection.
parameterName - The parameter keyparameterValues - The parameter values
addParameter(String, Object...)public RequestSpecBuilder addQueryParameters(Map<String,?> parametersMap)
addParameters(java.util.Map)
for all HTTP methods except POST where this method can be used to differentiate between form and query params.
parametersMap - The Map containing the parameter names and their values to send with the request.
public RequestSpecBuilder addQueryParameter(String parameterName,
Object... parameterValues)
addParameter(String, Object...) )}
for all HTTP methods except POST where this method can be used to differentiate between form and query params.
parameterName - The parameter keyparameterValues - Zero to many parameter values for this parameter name.
public RequestSpecBuilder addQueryParameter(String parameterName,
Collection<?> parameterValues)
addParameter(String, java.util.Collection)
for all HTTP methods except POST where this method can be used to differentiate between form and query params.
parameterName - The parameter keyparameterValues - The parameter values
public RequestSpecBuilder addQueryParam(String parameterName,
Collection<?> parameterValues)
addQueryParameter(String, java.util.Collection).
parameterName - The parameter keyparameterValues - The parameter values
addQueryParam(String, Object...)public RequestSpecBuilder addQueryParams(Map<String,?> parametersMap)
addQueryParameters(Map).
parametersMap - The Map containing the parameter names and their values to send with the request.
addQueryParameters(java.util.Map)
public RequestSpecBuilder addQueryParam(String parameterName,
Object... parameterValues)
addQueryParameter(String, Object...).
parameterName - The parameter keyparameterValues - Zero to many parameter values for this parameter name.
addQueryParameter(String, Object...)public RequestSpecBuilder addFormParameters(Map<String,?> parametersMap)
addParameters(java.util.Map)
for all HTTP methods except POST where this method can be used to differentiate between form and query params.
parametersMap - The Map containing the parameter names and their values to send with the request.
public RequestSpecBuilder addFormParameter(String parameterName,
Object... parameterValues)
addParameter(String, Object...) )}
for all HTTP methods except PUT where this method can be used to differentiate between form and query params.
parameterName - The parameter keyparameterValues - Zero to many parameter values for this parameter name.
public RequestSpecBuilder addFormParameter(String parameterName,
Collection<?> parameterValues)
#addParameter(String, java.util.Collection
for all HTTP methods except PUT where this method can be used to differentiate between form and query params.
parameterName - The parameter keyparameterValues - The parameter values
public RequestSpecBuilder addFormParam(String parameterName,
Collection<?> parameterValues)
#addFormParameter(String, java.util.Collection.
parameterName - The parameter keyparameterValues - The parameter values
addFormParam(String, Object...)public RequestSpecBuilder addFormParams(Map<String,?> parametersMap)
addFormParameters(Map).
parametersMap - The Map containing the parameter names and their values to send with the request.
addFormParameters(java.util.Map)
public RequestSpecBuilder addFormParam(String parameterName,
Object... parameterValues)
addFormParameter(String, Object...).
parameterName - The parameter nameparameterValues - Zero to many parameter values for this parameter name.
addFormParam(String, Object...)
public RequestSpecBuilder addPathParameter(String parameterName,
Object parameterValue)
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);
parameterName - The parameter keyparameterValue - The parameter value
public RequestSpecBuilder addPathParameters(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
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);
firstParameterName - The name of the first parameterfirstParameterValue - The value of the first parameterparameterNameValuePairs - Additional parameters in name-value pairs.
public RequestSpecBuilder addPathParameters(Map<String,?> parameterNameValuePairs)
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);
parameterNameValuePairs - A map containing the path parameters.
public RequestSpecBuilder addPathParam(String parameterName,
Object parameterValue)
addPathParameter(String, Object).
parameterName - The parameter keyparameterValue - The parameter value
addPathParameter(String, Object)
public RequestSpecBuilder addPathParams(String firstParameterName,
Object firstParameterValue,
Object... parameterNameValuePairs)
addPathParameters(String, Object, Object...).
firstParameterName - The name of the first parameterfirstParameterValue - The value of the first parameterparameterNameValuePairs - Additional parameters in name-value pairs.
addPathParameters(String, Object, Object...)public RequestSpecBuilder addPathParams(Map<String,?> parameterNameValuePairs)
addPathParameters(java.util.Map).
parameterNameValuePairs - A map containing the path parameters.
addPathParameters(java.util.Map)
public RequestSpecBuilder setKeystore(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.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.jks", "test1234");
or
given().keystore("/truststore.jks", "test1234"). ..
pathToJks - The path to the JKSpassword - The store passpublic RequestSpecBuilder addHeaders(Map<String,String> headers)
headers - The Map containing the header names and their values to send with the request.
public RequestSpecBuilder addHeader(String headerName,
String headerValue)
headerName - The header nameheaderValue - The header value
public RequestSpecBuilder setContentType(ContentType contentType)
contentType - The content type of the request
ContentTypepublic RequestSpecBuilder setContentType(String contentType)
contentType - The content type of the request
public RequestSpecBuilder addMultiPart(File file)
file - The file to upload
public RequestSpecBuilder addMultiPart(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.
public RequestSpecBuilder addMultiPart(String controlName,
File file,
String mimeType)
file - The file to uploadcontrolName - Defines the control name of the body part. In HTML this is the attribute name of the input tag.mimeType - The content-type
public RequestSpecBuilder addMultiPart(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 send
public RequestSpecBuilder addMultiPart(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 content-type
public RequestSpecBuilder addMultiPart(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 send
public RequestSpecBuilder addMultiPart(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 content-type
public RequestSpecBuilder addMultiPart(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 send
public RequestSpecBuilder addMultiPart(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-type
public RequestSpecBuilder setAuthentication(AuthenticationScheme auth)
public RequestSpecBuilder setAuth(AuthenticationScheme auth)
setAuthentication(com.jayway.restassured.authentication.AuthenticationScheme) )}.
setAuthentication(com.jayway.restassured.authentication.AuthenticationScheme)public RequestSpecBuilder setPort(int port)
port - The port of URI
public RequestSpecBuilder setUrlEncodingEnabled(boolean isEnabled)
isEnabled - Specify whether or not URL encoding should be enabled or disabled.
public RequestSpecBuilder setSessionId(String sessionIdValue)
RestAssured.config = newConfig().sessionConfig(new SessionConfig().sessionIdName(<sessionIdName>));
or you can use the setSessionId(String, String) method to set it for this request only.
sessionIdValue - The session id value.
public RequestSpecBuilder setSessionId(String sessionIdName,
String sessionIdValue)
RestAssured.config = newConfig().sessionConfig(new SessionConfig().sessionIdName(<sessionIdName>));
and then you can use the setSessionId(String) method to set the session id value without specifying the name for each request.
sessionIdName - The session id namesessionIdValue - The session id value.
public RequestSpecBuilder addRequestSpecification(RequestSpecification specification)
specification - The specification to add
public RequestSpecBuilder setConfig(RestAssuredConfig config)
config - The configuration to use for this request. If null no config will be used.
public RequestSpecification build()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||