com.jayway.restassured.internal
Class RestAssuredResponseImpl

java.lang.Object
  extended by com.jayway.restassured.internal.RestAssuredResponseImpl
All Implemented Interfaces:
Response, ResponseBody, groovy.lang.GroovyObject

public class RestAssuredResponseImpl
extends Object
implements Response, groovy.lang.GroovyObject


Constructor Summary
RestAssuredResponseImpl()
           
 
Method Summary
 Response andReturn()
          Syntactic sugar, simply returns the same response instance.
<T> T
as(Class<T> cls)
          Get the body and map it to a Java object.
<T> T
as(Class<T> cls, ObjectMapper mapper)
          Get the body and map it to a Java object using a specific object mapper.
 byte[] asByteArray()
          Get the body as a byte array.
 InputStream asInputStream()
          Get the body as an input stream.
 String asString()
          Get the body as a string.
 ResponseBody body()
          Returns the response body
 String contentType()
          Get the content type of the response
 String cookie(String name)
          Get a single cookie value associated with the given name.
 Map<String,String> cookies()
          The response cookies as simple name/value pair.
 Cookie detailedCookie(String name)
          Get a single cookie including all attributes associated with the given name.
 Cookies detailedCookies()
          The response cookies with all the attributes.
 ResponseBody getBody()
          Returns the response body
 Object getContent()
           
 String getContentType()
          Get the content type of the response
 String getCookie(String name)
          Get a single cookie value associated with the given name.
 Map<String,String> getCookies()
          The response cookies as simple name/value pair.
 String getDefaultContentType()
           
 Cookie getDetailedCookie(String name)
          Get a single cookie including all attributes associated with the given name.
 Cookies getDetailedCookies()
          The response cookies with all the attributes.
 boolean getHasExpectations()
           
 String getHeader(String name)
          Get a single header value associated with the given name.
 Headers getHeaders()
          The response headers.
 groovy.lang.MetaClass getMetaClass()
           
 Object getProperty(String property)
           
 Object getResponseHeaders()
           
 ResponseParserRegistrar getRpr()
           
 int getStatusCode()
          Get the status code of the response.
 String getStatusLine()
          Get the status line of the response.
 String header(String name)
          Get a single header value associated with the given name.
 Headers headers()
          The response headers.
 Object invokeMethod(String method, Object arguments)
           
 boolean isHasExpectations()
           
 JsonPath jsonPath()
          Get a JsonPath view of the response body.
 Object parseContentType(Object httpResponse)
           
 Object parseCookies()
           
 Object parseHeaders(Object httpResponse)
           
 void parseResponse(Object httpResponse, Object content, Object hasBodyAssertions, ResponseParserRegistrar responseParserRegistrar)
           
 Object parseStatus(Object httpResponse)
           
<T> T
path(String path)
          Get a value from the response body using the JsonPath or XmlPath syntax.
 String print()
          Print the response body and return it as string.
 void setContent(Object value)
           
 void setContentType(Object value)
           
 void setCookies(Cookies value)
           
 void setDefaultContentType(String value)
           
 void setHasExpectations(boolean value)
           
 void setMetaClass(groovy.lang.MetaClass mc)
           
 void setProperty(String property, Object value)
           
 void setResponseHeaders(Object value)
           
 void setRpr(ResponseParserRegistrar value)
           
 void setStatusCode(Object value)
           
 void setStatusLine(Object value)
           
 int statusCode()
          Get the status code of the response.
 String statusLine()
          Get the status line of the response.
 Response thenReturn()
          Syntactic sugar, simply returns the same response instance.
 Object toString(groovy.lang.Writable node)
           
 XmlPath xmlPath()
          Get an XmlPath view of the response body.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RestAssuredResponseImpl

public RestAssuredResponseImpl()
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

getResponseHeaders

public Object getResponseHeaders()

setResponseHeaders

public void setResponseHeaders(Object value)

setCookies

public void setCookies(Cookies value)

getContent

public Object getContent()

setContent

public void setContent(Object value)

setContentType

public void setContentType(Object value)

setStatusLine

public void setStatusLine(Object value)

setStatusCode

public void setStatusCode(Object value)

getDefaultContentType

public String getDefaultContentType()

setDefaultContentType

public void setDefaultContentType(String value)

getRpr

public ResponseParserRegistrar getRpr()

setRpr

public void setRpr(ResponseParserRegistrar value)

getHasExpectations

public boolean getHasExpectations()

isHasExpectations

public boolean isHasExpectations()

setHasExpectations

public void setHasExpectations(boolean value)

parseResponse

public void parseResponse(Object httpResponse,
                          Object content,
                          Object hasBodyAssertions,
                          ResponseParserRegistrar responseParserRegistrar)

parseStatus

public Object parseStatus(Object httpResponse)

parseContentType

public Object parseContentType(Object httpResponse)

parseCookies

public Object parseCookies()

parseHeaders

public Object parseHeaders(Object httpResponse)

toString

public Object toString(groovy.lang.Writable node)

print

public String print()
Description copied from interface: ResponseBody
Print the response body and return it as string. Mainly useful for debug purposes when writing tests.

Specified by:
print in interface ResponseBody
Returns:
The body as a string.

asString

public String asString()
Description copied from interface: ResponseBody
Get the body as a string.

Specified by:
asString in interface ResponseBody
Returns:
The body as a string.

asInputStream

public InputStream asInputStream()
Description copied from interface: ResponseBody
Get the body as an input stream.

Specified by:
asInputStream in interface ResponseBody
Returns:
The body as an input stream.

asByteArray

public byte[] asByteArray()
Description copied from interface: ResponseBody
Get the body as a byte array.

Specified by:
asByteArray in interface ResponseBody
Returns:
The body as a array.

as

public <T> T as(Class<T> cls)
Description copied from interface: ResponseBody
Get the body and map it to a Java object. For JSON responses this requires that you have either
  1. Jackson, or
  2. Gson
in the classpath or for XML responses it requires JAXB to be in the classpath.
It also requires that the response content-type is either JSON or XML or that a default parser has been been set. You can also force a specific object mapper using ResponseBody.as(Class, com.jayway.restassured.mapper.ObjectMapper).

Specified by:
as in interface ResponseBody
Returns:
The object

as

public <T> T as(Class<T> cls,
                ObjectMapper mapper)
Description copied from interface: ResponseBody
Get the body and map it to a Java object using a specific object mapper. It will use the supplied mapper regardless of the response content-type.

Specified by:
as in interface ResponseBody
Returns:
The object

detailedCookies

public Cookies detailedCookies()
Description copied from interface: Response
The response cookies with all the attributes. It also gives you the possibility to get multi-value cookies.

Specified by:
detailedCookies in interface Response
Returns:
The response cookies.

getDetailedCookies

public Cookies getDetailedCookies()
Description copied from interface: Response
The response cookies with all the attributes. It also gives you the possibility to get multi-value cookies.

Specified by:
getDetailedCookies in interface Response
Returns:
The response cookies.

detailedCookie

public Cookie detailedCookie(String name)
Description copied from interface: Response
Get a single cookie including all attributes associated with the given name.

Specified by:
detailedCookie in interface Response
Returns:
The cookie value or null if value was not found.

getDetailedCookie

public Cookie getDetailedCookie(String name)
Description copied from interface: Response
Get a single cookie including all attributes associated with the given name.

Specified by:
getDetailedCookie in interface Response
Returns:
The cookie value or null if value was not found.

andReturn

public Response andReturn()
Description copied from interface: Response
Syntactic sugar, simply returns the same response instance.

Specified by:
andReturn in interface Response
Returns:
The same response instance.

body

public ResponseBody body()
Description copied from interface: Response
Returns the response body

Specified by:
body in interface Response
Returns:
The response body.

thenReturn

public Response thenReturn()
Description copied from interface: Response
Syntactic sugar, simply returns the same response instance.

Specified by:
thenReturn in interface Response
Returns:
The same response instance.

getBody

public ResponseBody getBody()
Description copied from interface: Response
Returns the response body

Specified by:
getBody in interface Response
Returns:
The response body.

headers

public Headers headers()
Description copied from interface: Response
The response headers. If there are several response headers with the same name a list of the response header values are returned.

Specified by:
headers in interface Response
Returns:
The response headers.

getHeaders

public Headers getHeaders()
Description copied from interface: Response
The response headers. If there are several response headers with the same name a list of the response header values are returned.

Specified by:
getHeaders in interface Response
Returns:
The response headers.

header

public String header(String name)
Description copied from interface: Response
Get a single header value associated with the given name. If the header is a multi-value header then you need to use Headers.getList(String) in order to get all values.

Specified by:
header in interface Response
Returns:
The header value or null if value was not found.

getHeader

public String getHeader(String name)
Description copied from interface: Response
Get a single header value associated with the given name. If the header is a multi-value header then you need to use Headers.getList(String) in order to get all values..

Specified by:
getHeader in interface Response
Returns:
The header value or null if value was not found.

cookies

public Map<String,String> cookies()
Description copied from interface: Response
The response cookies as simple name/value pair. It assumes that no cookies have the same name. If two cookies should never the less have the same name the first cookie value is used. If you want to return ALL cookies including all the details such as Max-Age etc use Response.detailedCookies().

Specified by:
cookies in interface Response
Returns:
The response cookies.

getCookies

public Map<String,String> getCookies()
Description copied from interface: Response
The response cookies as simple name/value pair. It assumes that no cookies have the same name. If two cookies should never the less have the same name the first cookie value is used. If you want to return ALL cookies inlucding all the details such as Max-Age etc use Response.getDetailedCookies().

Specified by:
getCookies in interface Response
Returns:
The response cookies.

cookie

public String cookie(String name)
Description copied from interface: Response
Get a single cookie value associated with the given name. If you want more details than just the value use Response.detailedCookie(String).

Specified by:
cookie in interface Response
Returns:
The cookie value or null if value was not found.

getCookie

public String getCookie(String name)
Description copied from interface: Response
Get a single cookie value associated with the given name. If you want more details than just the value use Response.getDetailedCookie(String).

Specified by:
getCookie in interface Response
Returns:
The cookie value or null if value was not found.

contentType

public String contentType()
Description copied from interface: Response
Get the content type of the response

Specified by:
contentType in interface Response
Returns:
The content type value or null if not found.

getContentType

public String getContentType()
Description copied from interface: Response
Get the content type of the response

Specified by:
getContentType in interface Response
Returns:
The content type value or null if not found.

statusLine

public String statusLine()
Description copied from interface: Response
Get the status line of the response.

Specified by:
statusLine in interface Response
Returns:
The status line of the response.

statusCode

public int statusCode()
Description copied from interface: Response
Get the status code of the response.

Specified by:
statusCode in interface Response
Returns:
The status code of the response.

getStatusLine

public String getStatusLine()
Description copied from interface: Response
Get the status line of the response.

Specified by:
getStatusLine in interface Response
Returns:
The status line of the response.

getStatusCode

public int getStatusCode()
Description copied from interface: Response
Get the status code of the response.

Specified by:
getStatusCode in interface Response
Returns:
The status code of the response.

jsonPath

public JsonPath jsonPath()
Description copied from interface: ResponseBody
Get a JsonPath view of the response body. This will let you use the JsonPath syntax to get values from the response. Example:

Assume that the GET request (to http://localhost:8080/lotto) returns JSON as:

 {
 "lotto":{
   "lottoId":5,
   "winning-numbers":[2,45,34,23,7,5,3],
   "winners":[{
     "winnerId":23,
     "numbers":[2,45,34,23,3,5]
   },{
     "winnerId":54,
     "numbers":[52,3,12,11,18,22]
   }]
  }
 }
 

You can the make the request and get the winner id's by using JsonPath:
 List winnerIds = get("/lotto").jsonPath().getList("lotto.winnders.winnerId");
 

Specified by:
jsonPath in interface ResponseBody

xmlPath

public XmlPath xmlPath()
Description copied from interface: ResponseBody
Get an XmlPath view of the response body. This will let you use the XmlPath syntax to get values from the response. Example:

Imagine that a POST request to http://localhost:8080/greetXML returns:

 <greeting>
     <firstName>John</firstName>
     <lastName>Doe</lastName>
   </greeting>
 

You can the make the request and get the winner id's by using JsonPath:
 String firstName = get("/greetXML").xmlPath().getString("greeting.firstName");
 

Specified by:
xmlPath in interface ResponseBody

path

public <T> T path(String path)
Description copied from interface: ResponseBody
Get a value from the response body using the JsonPath or XmlPath syntax. REST Assured will automatically determine whether to use JsonPath or XmlPath based on the content-type of the response. If no content-type is defined then REST Assured will try to look at the "default parser" if defined (RestAssured.defaultParser).

Specified by:
path in interface ResponseBody
Type Parameters:
T - The return type
Parameters:
path - The json- or xml path
Returns:
The value returned by the path
See Also:
ResponseBody.jsonPath(), ResponseBody.xmlPath()


Copyright © 2010-2011. All Rights Reserved.