All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jayway.restassured.specification.RequestSpecification Maven / Gradle / Ivy

There is a newer version: 2.9.0
Show newest version
/*
 * Copyright 2010 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jayway.restassured.specification;

import com.jayway.restassured.filter.Filter;
import groovyx.net.http.ContentType;

import java.util.List;
import java.util.Map;

/**
 * Allows you to specify how the request will look like.
 */
public interface RequestSpecification extends RequestSender {

    /**
     * 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 {@link #body(String)} and {@link #content(String)} are the same except for the syntactic difference. *

* * @param body The body to send. * @return The request specification */ RequestSpecification body(String body); /** * 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 {@link #body(byte[])} and {@link #content(byte[])} are the same except for the syntactic difference. *

* * @param body The body to send. * @return The request specification */ RequestSpecification body(byte[] body); /** * 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 {@link #body(String)} and {@link #content(String)} are the same except for the syntactic difference. *

* * @param content The content to send. * @return The request specification */ RequestSpecification content(String content); /** * 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 {@link #body(byte[])} and {@link #content(byte[])} are the same except for the syntactic difference. *

* * @param content The content to send. * @return The request specification */ RequestSpecification content(byte[] content); /** * 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. *
  3. token=1234
  4. *
* and expect that the response body is equal to "username, token". * * @param cookieName The name of the first cookie * @param cookieNameValuePairs The value of the first cookie followed by additional cookies in name-value pairs. * @return The request specification */ RequestSpecification cookies(String cookieName, String...cookieNameValuePairs); /** * 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. *
  3. token=1234
  4. *
* and expect that the response body is equal to "username, token". * * @param cookies The Map containing the cookie names and their values to set in the request. * @return The request specification */ RequestSpecification cookies(Map cookies); /** * 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");
     * 
*

* * @see #cookies(String, String...) * @param cookieName The cookie cookieName * @param value The cookie value * @return The request specification */ RequestSpecification cookie(String cookieName, String value); /** * 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". *

* * @see #cookies(String, String...) * @param cookieName The cookie cookieName * @return The request specification */ RequestSpecification cookie(String cookieName); /** * 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. *
  3. token=1234
  4. *
* and expect that the response body is equal to "username, token". * * @param parameterName The name of the first parameter * @param parameterNameValuePairs The value of the first parameter followed by additional parameters in name-value pairs. * @return The request specification */ RequestSpecification parameters(String parameterName, String...parameterNameValuePairs); /** * 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. *
  3. token=1234
  4. *
* and expect that the response body is equal to "username, token". * * @param parametersMap The Map containing the parameter names and their values to send with the request. * @return The request specification */ RequestSpecification parameters(Map parametersMap); /** * 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");
     * 
*

* * @see #parameters(String, String...) * @param parameterName The parameter key * @param parameterValue The parameter value * @param additionalParameterValues Additional parameter values if you want to specify multiple values for the same parameter * @return The request specification */ RequestSpecification parameter(String parameterName, String parameterValue, String... additionalParameterValues); /** * 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. *

* * @param parameterName The parameter key * @param parameterValues The parameter values * @return The request specification */ RequestSpecification parameter(String parameterName, List parameterValues); /** * A slightly shorter version of {@link #parameters(String, String...)}. * * @see #parameters(String, String...) * @param parameterName The name of the first parameter * @param parameterNameValuePairs The value of the first parameter followed by additional parameters in name-value pairs. * @return The request specification */ RequestSpecification params(String parameterName, String...parameterNameValuePairs); /** * A slightly shorter version of {@link #parameters(Map)}. * * @see #parameters(Map) * @param parametersMap The Map containing the parameter names and their values to send with the request. * @return The request specification */ RequestSpecification params(Map parametersMap); /** * A slightly shorter version of {@link #parameter(String, String, String...) }. * * @see #parameter(String, String, String...) * @param parameterName The parameter key * @param parameterValue The parameter value * @param additionalParameterValues Additional parameter values if you want to specify multiple values for the same parameter * @return The request specification */ RequestSpecification param(String parameterName, String parameterValue, String... additionalParameterValues); /** * A slightly shorter version of {@link #parameter(String, java.util.List)} }. * * @param parameterName The parameter key * @param parameterValues The parameter values * @return The request specification */ RequestSpecification param(String parameterName, List parameterValues); /** * Specify the query parameters that'll be sent with the request. Note that this method is the same as {@link #parameters(String, String...)} * for all http methods except for POST where {@link #parameters(String, String...)} sets the form parameters and this method sets the * query parameters. * * @param parameterName The name of the first parameter * @param parameterNameValuePairs The value of the first parameter followed by additional parameters in name-value pairs. * @return The request specification */ RequestSpecification queryParameters(String parameterName, String...parameterNameValuePairs); /** * Specify the query parameters that'll be sent with the request. Note that this method is the same as {@link #parameters(Map)} * for all http methods except for POST where {@link #parameters(Map)} sets the form parameters and this method sets the * query parameters. * * @param parametersMap The Map containing the parameter names and their values to send with the request. * @return The request specification */ RequestSpecification queryParameters(Map parametersMap); /** * Specify a query parameter that'll be sent with the request. Note that this method is the same as {@link #parameter(String, String, String...)} * for all http methods except for POST where {@link #parameter(String, String, String...)} adds a form parameter and this method sets a * query parameter. * * @see #parameter(String, String, String...) * @param parameterName The parameter key * @param parameterValue The parameter value * @param additionalParameterValues Additional parameter values if you want to specify multiple values for the same parameter * @return The request specification */ RequestSpecification queryParameter(String parameterName, String parameterValue, String... additionalParameterValues); /** * 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 {@link #parameter(String, java.util.List)} * for all http methods except for POST where {@link #parameter(String, java.util.List)} adds a form parameter and * this method sets a query parameter. * * @param parameterName The parameter key * @param parameterValues The parameter values * @return The request specification */ RequestSpecification queryParameter(String parameterName, List parameterValues); /** * A slightly shorter version of {@link #queryParameters(String, String...)}. * * @see #queryParameters(String, String...) * @param parameterName The name of the first parameter * @param parameterNameValuePairs The value of the first parameter followed by additional parameters in name-value pairs. * @return The request specification */ RequestSpecification queryParams(String parameterName, String...parameterNameValuePairs); /** * A slightly shorter version of {@link #queryParams(java.util.Map)}. * * @see #queryParams(java.util.Map) * @param parametersMap The Map containing the parameter names and their values to send with the request. * @return The request specification */ RequestSpecification queryParams(Map parametersMap); /** * A slightly shorter version of {@link #queryParameter(String, String, String...)}. * * @see #parameter(String, String, String...) * @param parameterName The parameter key * @param parameterValue The parameter value * @param additionalParameterValues Additional parameter values if you want to specify multiple values for the same parameter * @return The request specification */ RequestSpecification queryParam(String parameterName, String parameterValue, String... additionalParameterValues); /** * A slightly shorter version of {@link #queryParameter(String, java.util.List)}. * * @see #queryParam(String, java.util.List) * @param parameterName The parameter key * @param parameterValues The parameter values * @return The request specification */ RequestSpecification queryParam(String parameterName, List parameterValues); /** * Specify the form parameters that'll be sent with the request. Note that this method is the same as {@link #parameters(String, String...)} * for all http methods except for PUT where {@link #parameters(String, String...)} sets the query parameters and this method sets the * form parameters. * * @param parameterName The name of the first parameter * @param parameterNameValuePairs The value of the first parameter followed by additional parameters in name-value pairs. * @return The request specification */ RequestSpecification formParameters(String parameterName, String...parameterNameValuePairs); /** * Specify the form parameters that'll be sent with the request. Note that this method is the same as {@link #parameters(Map)} * for all http methods except for PUT where {@link #parameters(Map)} sets the query parameters and this method sets the * form parameters. * * @param parametersMap The Map containing the parameter names and their values to send with the request. * @return The request specification */ RequestSpecification formParameters(Map parametersMap); /** * Specify a form parameter that'll be sent with the request. Note that this method is the same as {@link #parameter(String, String, String...)} * for all http methods except for PUT where {@link #parameter(String, String, String...)} adds a query parameter and this method sets a * form parameter. * * @see #parameter(String, String, String...) * @param parameterName The parameter key * @param parameterValue The parameter value * @param additionalParameterValues Additional parameter values if you want to specify multiple values for the same parameter * @return The request specification */ RequestSpecification formParameter(String parameterName, String parameterValue, String... additionalParameterValues); /** * 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 {@link #parameter(String, java.util.List)} * for all http methods except for PUT where {@link #parameter(String, java.util.List)} adds a query parameter and * this method sets a form parameter. * * @param parameterName The parameter key * @param parameterValues The parameter values * @return The request specification */ RequestSpecification formParameter(String parameterName, List parameterValues); /** * A slightly shorter version of {@link #formParameters(String, String...)}. * * @see #formParameters(String, String...) * @param parameterName The name of the first parameter * @param parameterNameValuePairs The value of the first parameter followed by additional parameters in name-value pairs. * @return The request specification */ RequestSpecification formParams(String parameterName, String...parameterNameValuePairs); /** * A slightly shorter version of {@link #formParams(java.util.Map)}. * * @see #formParams(java.util.Map) * @param parametersMap The Map containing the parameter names and their values to send with the request. * @return The request specification */ RequestSpecification formParams(Map parametersMap); /** * A slightly shorter version of {@link #formParameter(String, String, String...)}. * * @see #parameter(String, String, String...) * @param parameterName The parameter key * @param parameterValue The parameter value * @param additionalParameterValues Additional parameter values if you want to specify multiple values for the same parameter * @return The request specification */ RequestSpecification formParam(String parameterName, String parameterValue, String... additionalParameterValues); /** * A slightly shorter version of {@link #formParameter(String, java.util.List)}. * * @see #formParam(String, java.util.List) * @param parameterName The parameter key * @param parameterValues The parameter values * @return The request specification */ RequestSpecification formParam(String parameterName, List parameterValues); /** * 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);
     * 
* * @param parameterName The parameter key * @param parameterValue The parameter value * @return The request specification */ RequestSpecification pathParameter(String parameterName, Object parameterValue); /** * 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);
     * 
* * @param parameterName The parameter key * @param parameterNameValuePairs The value of the first parameter followed by additional parameters in name-value pairs. * @return The request specification */ RequestSpecification pathParameters(String parameterName, Object...parameterNameValuePairs); /** * 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);
     * 
* * @param parameterNameValuePairs A map containing the path parameters. * @return The request specification */ RequestSpecification pathParameters(Map parameterNameValuePairs); /** * A slightly shorter version of {@link #pathParameter(String, Object)}. * * @see #pathParameter(String, Object) * @param parameterName The parameter key * @param parameterValue The parameter value * @return The request specification */ RequestSpecification pathParam(String parameterName, Object parameterValue); /** * A slightly shorter version of {@link #pathParameters(String, Object...)}. * * @see #pathParameters(String, Object...) * @param parameterName The parameter key * @param parameterNameValuePairs The value of the first parameter followed by additional parameters in name-value pairs. * @return The request specification */ RequestSpecification pathParams(String parameterName, Object...parameterNameValuePairs); /** * A slightly shorter version of {@link #pathParameters(java.util.Map)}. * * @see #pathParameters(java.util.Map) * @param parameterNameValuePairs A map containing the path parameters. * @return The request specification */ RequestSpecification pathParams(Map parameterNameValuePairs); /** * 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"). ..
     * 
*

* @param pathToJks The path to the JKS * @param password The store pass */ RequestSpecification keystore(String pathToJks, String password); /** * 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. *
  3. headerName2=headerValue2
  4. *
* and expect that the response body is equal to "something". * * @param headerName The name of the first header * @param headerNameValuePairs The value of the first header followed by additional headers in name-value pairs. * @return The request specification */ RequestSpecification headers(String headerName, String ... headerNameValuePairs); /** * 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. *
  3. headerName2=headerValue2
  4. *
* and expect that the response body is equal to "something". * * @param headers The Map containing the header names and their values to send with the request. * @return The request specification */ RequestSpecification headers(Map headers); /** * 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");
     * 
*

* * @see #headers(String, String...) * @param headerName The header name * @param headerValue The header value * @return The request specification */ RequestSpecification header(String headerName, String headerValue); /** * Specify the content type of the request. * * @see ContentType * @param contentType The content type of the request * @return The request specification */ RequestSpecification contentType(ContentType contentType); /** * Specify the content type of the request. * * @see ContentType * @param contentType The content type of the request * @return The request specification */ RequestSpecification contentType(String contentType); /** * If you need to specify some credentials when performing a request. * * @see AuthenticationSpecification * @return The authentication specification */ AuthenticationSpecification authentication(); /** * A slightly short version of {@link #authentication()}. * * @see #authentication() * @see AuthenticationSpecification * @return The authentication specification */ AuthenticationSpecification auth(); /** * 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");
     * 
*

* * @param port The port of URI * @return The request specification */ RequestSpecification port(int port); /** * 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: *

    *
  • Port
  • *
  • Authentication schemeContent type
  • *
  • Request body
  • *
* The following settings are merged: *
    *
  • Parameters
  • *
  • Cookies
  • *
  • Headers
  • *
* * This method is the same as {@link #specification(RequestSpecification)} but the name is a bit shorter. * * @param requestSpecificationToMerge The specification to merge with. * @return the request specification */ RequestSpecification spec(RequestSpecification requestSpecificationToMerge); /** * 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: *

    *
  • Port
  • *
  • Authentication schemeContent type
  • *
  • Request body
  • *
* The following settings are merged: *
    *
  • Parameters
  • *
  • Cookies
  • *
  • Headers
  • *
* * This method is the same as {@link #specification(RequestSpecification)} but the name is a bit shorter. * * @param requestSpecificationToMerge The specification to merge with. * @return the request specification */ RequestSpecification specification(RequestSpecification requestSpecificationToMerge); /** * 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. * @param isEnabled Specify whether or not URL encoding should be enabled or disabled. * @return the request specification */ RequestSpecification urlEncodingEnabled(boolean isEnabled); /** * Add a filter that will be used in the request. * * @param filter The filter to add * @return the request specification */ RequestSpecification filter(Filter filter); /** * Add filters that will be used in the request. * * @param filters The filters to add * @return the request specification */ RequestSpecification filters(List filters); /** * Log (i.e. print to system out) the response body to system out. This is mainly useful for debug purposes when writing * your tests. A shortcut for: *
     * given().filter(ResponseLoggingFilter.responseLogger()). ..
     * 
* @return the request specification */ RequestSpecification log(); /** * Log (i.e. print to system out) the response body to system out if an error occurs. This is mainly useful for debug purposes when writing * your tests. A shortcut for: *
     * given().filter(ErrorLoggingFilter.errorLogger()). ..
     * 
* @return the request specification */ RequestSpecification logOnError(); /** * 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");
     * 
* * @return the response specification */ ResponseSpecification response(); /** * 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");
     * 
* * @return the request specification */ RequestSpecification and(); /** * 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");
     * 
* * @return the request specification */ RequestSpecification with(); /** * 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");
     * 
* * @return the response specification */ ResponseSpecification then(); /** * 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");
     * 
* * @return the response specification */ ResponseSpecification expect(); /** * Syntactic sugar, e.g. *
     * expect().body(containsString("OK")).when().get("/something");
     * 
* * is that same as: *
     * expect().body(containsString("OK")).get("/something");
     * 
* * @return the request specification */ RequestSpecification when(); /** * 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");
     * 
* * @return the request specification */ RequestSpecification given(); /** * Syntactic sugar, e.g. *
     * expect().that().body(containsString("OK")).when().get("/something");
     * 
* * is that same as: *
     * expect().body(containsString("OK")).get("/something");
     * 
* * @return the request specification */ RequestSpecification that(); /** * 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");
     * 
* * @return the request specification */ RequestSpecification request(); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy