Package org.apache.sling.testing.clients
Class SlingHttpResponse
java.lang.Object
org.apache.sling.testing.clients.SlingHttpResponse
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.http.client.methods.CloseableHttpResponse,org.apache.http.HttpMessage,org.apache.http.HttpResponse
public class SlingHttpResponse
extends Object
implements org.apache.http.client.methods.CloseableHttpResponse
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSlingHttpResponse(org.apache.http.client.methods.CloseableHttpResponse response) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddHeader(org.apache.http.Header header) voidcheckContentContains(String... expected) Assert that all the providedStringsare contained in the responsevoidcheckContentRegexp(String... regexp) For each regular expression, assert that at least one line of the response matches the expressionvoidcheckContentType(String expected) Assert that response matches supplied content type (from Content-Type header)voidcheckStatus(int expected) Assert that response matches supplied statusvoidclose()booleancontainsHeader(String name) protected StringextractFromHTMLResponse(String searchPattern) Extract information from responseorg.apache.http.Header[]Get theStringcontent of the response.org.apache.http.HttpEntityorg.apache.http.HeadergetFirstHeader(String name) org.apache.http.Header[]getHeaders(String name) org.apache.http.HeadergetLastHeader(String name) org.apache.http.params.HttpParamsorg.apache.http.ProtocolVersionGet change log from Sling ResponseString[]Get copy paths from messageGet location from Sling ResponseGet message from Sling ResponseGet parent location from Sling ResponseGet path from Sling ResponseGet referer from Sling ResponseGet status from Sling ResponseintGet status from Sling Response as integerorg.apache.http.StatusLineorg.apache.http.HeaderIteratororg.apache.http.HeaderIteratorheaderIterator(String name) booleanvoidremoveHeader(org.apache.http.Header header) voidremoveHeaders(String name) voidsetEntity(org.apache.http.HttpEntity entity) voidvoidsetHeader(org.apache.http.Header header) voidsetHeaders(org.apache.http.Header[] headers) voidvoidsetParams(org.apache.http.params.HttpParams params) voidsetReasonPhrase(String reason) voidsetStatusCode(int code) voidsetStatusLine(org.apache.http.ProtocolVersion ver, int code) voidsetStatusLine(org.apache.http.ProtocolVersion ver, int code, String reason) voidsetStatusLine(org.apache.http.StatusLine statusline)
-
Field Details
-
STATUS
- See Also:
-
MESSAGE
- See Also:
-
LOCATION
- See Also:
-
PARENT_LOCATION
- See Also:
-
PATH
- See Also:
-
REFERER
- See Also:
-
CHANGE_LOG
- See Also:
-
-
Constructor Details
-
SlingHttpResponse
public SlingHttpResponse(org.apache.http.client.methods.CloseableHttpResponse response)
-
-
Method Details
-
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
Assert that response matches supplied status
- Parameters:
expected- the expected http status- Throws:
TestingValidationException- if the response does not match the expected
-
checkContentType
Assert that response matches supplied content type (from Content-Type header)
- Parameters:
expected- the expected content type- Throws:
TestingValidationException- if the response content type does not match the expected
-
checkContentRegexp
For 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:
TestingValidationException- if the response content does not match one of the regexp
-
checkContentContains
Assert that all the provided
Stringsare contained in the response- Parameters:
expected- list of expected strings- Throws:
TestingValidationException- if the response content does not match one of the strings
-
getSlingStatus
Get status from Sling Response- Returns:
- Sling Status
-
getSlingStatusAsInt
Get status from Sling Response as integer- Returns:
- Sling Status
- Throws:
NumberFormatException- if sling status can't be parsed as a number
-
getSlingMessage
Get message from Sling Response- Returns:
- Sling Message
-
getSlingCopyPaths
Get copy paths from message- Returns:
- copy paths as String Array
-
getSlingLocation
Get location from Sling Response- Returns:
- Sling Location
-
getSlingParentLocation
Get parent location from Sling Response- Returns:
- Sling Parent Location
-
getSlingPath
Get path from Sling Response- Returns:
- Sling Path
-
getSlingReferer
Get referer from Sling Response- Returns:
- Sling Referer
-
getSlingChangeLog
Get change log from Sling Response- Returns:
- Sling Change Log
-
extractFromHTMLResponse
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
- Specified by:
setStatusLinein interfaceorg.apache.http.HttpResponse
-
setStatusCode
- Specified by:
setStatusCodein interfaceorg.apache.http.HttpResponse- Throws:
IllegalStateException
-
setReasonPhrase
- Specified by:
setReasonPhrasein interfaceorg.apache.http.HttpResponse- Throws:
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
- Specified by:
getLocalein interfaceorg.apache.http.HttpResponse
-
setLocale
- Specified by:
setLocalein interfaceorg.apache.http.HttpResponse
-
getProtocolVersion
public org.apache.http.ProtocolVersion getProtocolVersion()- Specified by:
getProtocolVersionin interfaceorg.apache.http.HttpMessage
-
containsHeader
- Specified by:
containsHeaderin interfaceorg.apache.http.HttpMessage
-
getHeaders
- Specified by:
getHeadersin interfaceorg.apache.http.HttpMessage
-
getFirstHeader
- Specified by:
getFirstHeaderin interfaceorg.apache.http.HttpMessage
-
getLastHeader
- 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
- Specified by:
addHeaderin interfaceorg.apache.http.HttpMessage
-
setHeader
public void setHeader(org.apache.http.Header header) - Specified by:
setHeaderin interfaceorg.apache.http.HttpMessage
-
setHeader
- 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
- Specified by:
removeHeadersin interfaceorg.apache.http.HttpMessage
-
headerIterator
public org.apache.http.HeaderIterator headerIterator()- Specified by:
headerIteratorin interfaceorg.apache.http.HttpMessage
-
headerIterator
- 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
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-