Package org.apache.sling.testing.clients
Class SlingHttpResponse
- java.lang.Object
-
- org.apache.sling.testing.clients.SlingHttpResponse
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,org.apache.http.client.methods.CloseableHttpResponse,org.apache.http.HttpMessage,org.apache.http.HttpResponse
public class SlingHttpResponse extends java.lang.Object implements org.apache.http.client.methods.CloseableHttpResponse
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCHANGE_LOGstatic java.lang.StringLOCATIONstatic java.lang.StringMESSAGEstatic java.lang.StringPARENT_LOCATIONstatic java.lang.StringPATHstatic java.lang.StringREFERERstatic java.lang.StringSTATUS
-
Constructor Summary
Constructors Constructor Description SlingHttpResponse(org.apache.http.client.methods.CloseableHttpResponse response)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHeader(java.lang.String name, java.lang.String value)voidaddHeader(org.apache.http.Header header)voidcheckContentContains(java.lang.String... expected)Assert that all the providedStringsare contained in the responsevoidcheckContentRegexp(java.lang.String... regexp)For each regular expression, assert that at least one line of the response matches the expressionvoidcheckContentType(java.lang.String expected)Assert that response matches supplied content type (from Content-Type header)voidcheckStatus(int expected)Assert that response matches supplied statusvoidclose()booleancontainsHeader(java.lang.String name)protected java.lang.StringextractFromHTMLResponse(java.lang.String searchPattern)Extract information from responseorg.apache.http.Header[]getAllHeaders()java.lang.StringgetContent()Get theStringcontent of the response.org.apache.http.HttpEntitygetEntity()org.apache.http.HeadergetFirstHeader(java.lang.String name)org.apache.http.Header[]getHeaders(java.lang.String name)org.apache.http.HeadergetLastHeader(java.lang.String name)java.util.LocalegetLocale()org.apache.http.params.HttpParamsgetParams()org.apache.http.ProtocolVersiongetProtocolVersion()java.lang.StringgetSlingChangeLog()Get change log from Sling Responsejava.lang.String[]getSlingCopyPaths()Get copy paths from messagejava.lang.StringgetSlingLocation()Get location from Sling Responsejava.lang.StringgetSlingMessage()Get message from Sling Responsejava.lang.StringgetSlingParentLocation()Get parent location from Sling Responsejava.lang.StringgetSlingPath()Get path from Sling Responsejava.lang.StringgetSlingReferer()Get referer from Sling Responsejava.lang.StringgetSlingStatus()Get status from Sling ResponseintgetSlingStatusAsInt()Get status from Sling Response as integerorg.apache.http.StatusLinegetStatusLine()org.apache.http.HeaderIteratorheaderIterator()org.apache.http.HeaderIteratorheaderIterator(java.lang.String name)booleanisConsumed()voidremoveHeader(org.apache.http.Header header)voidremoveHeaders(java.lang.String name)voidsetEntity(org.apache.http.HttpEntity entity)voidsetHeader(java.lang.String name, java.lang.String value)voidsetHeader(org.apache.http.Header header)voidsetHeaders(org.apache.http.Header[] headers)voidsetLocale(java.util.Locale loc)voidsetParams(org.apache.http.params.HttpParams params)voidsetReasonPhrase(java.lang.String reason)voidsetStatusCode(int code)voidsetStatusLine(org.apache.http.ProtocolVersion ver, int code)voidsetStatusLine(org.apache.http.ProtocolVersion ver, int code, java.lang.String reason)voidsetStatusLine(org.apache.http.StatusLine statusline)
-
-
-
Field Detail
-
STATUS
public static final java.lang.String STATUS
- See Also:
- Constant Field Values
-
MESSAGE
public static final java.lang.String MESSAGE
- See Also:
- Constant Field Values
-
LOCATION
public static final java.lang.String LOCATION
- See Also:
- Constant Field Values
-
PARENT_LOCATION
public static final java.lang.String PARENT_LOCATION
- See Also:
- Constant Field Values
-
PATH
public static final java.lang.String PATH
- See Also:
- Constant Field Values
-
REFERER
public static final java.lang.String REFERER
- See Also:
- Constant Field Values
-
CHANGE_LOG
public static final java.lang.String CHANGE_LOG
- See Also:
- Constant Field Values
-
-
Method Detail
-
getContent
public java.lang.String getContent()
Get the
Stringcontent of the response.The content is cached so it is safe to call this method several times.
Attention! Calling this method consumes the entity, so it cannot be used as an InputStream later
- Returns:
- the content as String
-
isConsumed
public boolean isConsumed()
-
checkStatus
public void checkStatus(int expected) throws ClientExceptionAssert that response matches supplied status
- Parameters:
expected- the expected http status- Throws:
ClientException- if the response does not match the expected
-
checkContentType
public void checkContentType(java.lang.String expected) throws ClientExceptionAssert that response matches supplied content type (from Content-Type header)
- Parameters:
expected- the expected content type- Throws:
ClientException- if the response content type does not match the expected
-
checkContentRegexp
public void checkContentRegexp(java.lang.String... regexp) throws ClientExceptionFor each regular expression, assert that at least one line of the response matches the expression
The regular expressions are automatically prefixed and suffixed with .* it order to partial-match the lines
- Parameters:
regexp- list of regular expressions- Throws:
ClientException- if the response content does not match one of the regexp
-
checkContentContains
public void checkContentContains(java.lang.String... expected) throws ClientExceptionAssert that all the provided
Stringsare contained in the response- Parameters:
expected- list of expected strings- Throws:
ClientException- @throws ClientException if the response content does not match one of the strings
-
getSlingStatus
public java.lang.String getSlingStatus()
Get status from Sling Response- Returns:
- Sling Status
-
getSlingStatusAsInt
public int getSlingStatusAsInt() throws java.lang.NumberFormatExceptionGet status from Sling Response as integer- Returns:
- Sling Status
- Throws:
java.lang.NumberFormatException- if sling status can't be parsed as a number
-
getSlingMessage
public java.lang.String getSlingMessage()
Get message from Sling Response- Returns:
- Sling Message
-
getSlingCopyPaths
public java.lang.String[] getSlingCopyPaths()
Get copy paths from message- Returns:
- copy paths as String Array
-
getSlingLocation
public java.lang.String getSlingLocation()
Get location from Sling Response- Returns:
- Sling Location
-
getSlingParentLocation
public java.lang.String getSlingParentLocation()
Get parent location from Sling Response- Returns:
- Sling Parent Location
-
getSlingPath
public java.lang.String getSlingPath()
Get path from Sling Response- Returns:
- Sling Path
-
getSlingReferer
public java.lang.String getSlingReferer()
Get referer from Sling Response- Returns:
- Sling Referer
-
getSlingChangeLog
public java.lang.String getSlingChangeLog()
Get change log from Sling Response- Returns:
- Sling Change Log
-
extractFromHTMLResponse
protected java.lang.String extractFromHTMLResponse(java.lang.String searchPattern)
Extract information from response- Parameters:
searchPattern- search pattern to look for- Returns:
- Sling information
-
getStatusLine
public org.apache.http.StatusLine getStatusLine()
- Specified by:
getStatusLinein interfaceorg.apache.http.HttpResponse
-
setStatusLine
public void setStatusLine(org.apache.http.StatusLine statusline)
- Specified by:
setStatusLinein interfaceorg.apache.http.HttpResponse
-
setStatusLine
public void setStatusLine(org.apache.http.ProtocolVersion ver, int code)- Specified by:
setStatusLinein interfaceorg.apache.http.HttpResponse
-
setStatusLine
public void setStatusLine(org.apache.http.ProtocolVersion ver, int code, java.lang.String reason)- Specified by:
setStatusLinein interfaceorg.apache.http.HttpResponse
-
setStatusCode
public void setStatusCode(int code) throws java.lang.IllegalStateException- Specified by:
setStatusCodein interfaceorg.apache.http.HttpResponse- Throws:
java.lang.IllegalStateException
-
setReasonPhrase
public void setReasonPhrase(java.lang.String reason) throws java.lang.IllegalStateException- Specified by:
setReasonPhrasein interfaceorg.apache.http.HttpResponse- Throws:
java.lang.IllegalStateException
-
getEntity
public org.apache.http.HttpEntity getEntity()
- Specified by:
getEntityin interfaceorg.apache.http.HttpResponse
-
setEntity
public void setEntity(org.apache.http.HttpEntity entity)
- Specified by:
setEntityin interfaceorg.apache.http.HttpResponse
-
getLocale
public java.util.Locale getLocale()
- Specified by:
getLocalein interfaceorg.apache.http.HttpResponse
-
setLocale
public void setLocale(java.util.Locale loc)
- Specified by:
setLocalein interfaceorg.apache.http.HttpResponse
-
getProtocolVersion
public org.apache.http.ProtocolVersion getProtocolVersion()
- Specified by:
getProtocolVersionin interfaceorg.apache.http.HttpMessage
-
containsHeader
public boolean containsHeader(java.lang.String name)
- Specified by:
containsHeaderin interfaceorg.apache.http.HttpMessage
-
getHeaders
public org.apache.http.Header[] getHeaders(java.lang.String name)
- Specified by:
getHeadersin interfaceorg.apache.http.HttpMessage
-
getFirstHeader
public org.apache.http.Header getFirstHeader(java.lang.String name)
- Specified by:
getFirstHeaderin interfaceorg.apache.http.HttpMessage
-
getLastHeader
public org.apache.http.Header getLastHeader(java.lang.String name)
- Specified by:
getLastHeaderin interfaceorg.apache.http.HttpMessage
-
getAllHeaders
public org.apache.http.Header[] getAllHeaders()
- Specified by:
getAllHeadersin interfaceorg.apache.http.HttpMessage
-
addHeader
public void addHeader(org.apache.http.Header header)
- Specified by:
addHeaderin interfaceorg.apache.http.HttpMessage
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value)- Specified by:
addHeaderin interfaceorg.apache.http.HttpMessage
-
setHeader
public void setHeader(org.apache.http.Header header)
- Specified by:
setHeaderin interfaceorg.apache.http.HttpMessage
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value)- Specified by:
setHeaderin interfaceorg.apache.http.HttpMessage
-
setHeaders
public void setHeaders(org.apache.http.Header[] headers)
- Specified by:
setHeadersin interfaceorg.apache.http.HttpMessage
-
removeHeader
public void removeHeader(org.apache.http.Header header)
- Specified by:
removeHeaderin interfaceorg.apache.http.HttpMessage
-
removeHeaders
public void removeHeaders(java.lang.String name)
- Specified by:
removeHeadersin interfaceorg.apache.http.HttpMessage
-
headerIterator
public org.apache.http.HeaderIterator headerIterator()
- Specified by:
headerIteratorin interfaceorg.apache.http.HttpMessage
-
headerIterator
public org.apache.http.HeaderIterator headerIterator(java.lang.String name)
- Specified by:
headerIteratorin interfaceorg.apache.http.HttpMessage
-
getParams
public org.apache.http.params.HttpParams getParams()
- Specified by:
getParamsin interfaceorg.apache.http.HttpMessage
-
setParams
public void setParams(org.apache.http.params.HttpParams params)
- Specified by:
setParamsin interfaceorg.apache.http.HttpMessage
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-