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 TypeMethodDescriptionvoid
void
addHeader
(org.apache.http.Header header) void
checkContentContains
(String... expected) Assert that all the providedStrings
are contained in the responsevoid
checkContentRegexp
(String... regexp) For each regular expression, assert that at least one line of the response matches the expressionvoid
checkContentType
(String expected) Assert that response matches supplied content type (from Content-Type header)void
checkStatus
(int expected) Assert that response matches supplied statusvoid
close()
boolean
containsHeader
(String name) protected String
extractFromHTMLResponse
(String searchPattern) Extract information from responseorg.apache.http.Header[]
Get theString
content of the response.org.apache.http.HttpEntity
org.apache.http.Header
getFirstHeader
(String name) org.apache.http.Header[]
getHeaders
(String name) org.apache.http.Header
getLastHeader
(String name) org.apache.http.params.HttpParams
org.apache.http.ProtocolVersion
Get 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 Responseint
Get status from Sling Response as integerorg.apache.http.StatusLine
org.apache.http.HeaderIterator
org.apache.http.HeaderIterator
headerIterator
(String name) boolean
void
removeHeader
(org.apache.http.Header header) void
removeHeaders
(String name) void
setEntity
(org.apache.http.HttpEntity entity) void
void
setHeader
(org.apache.http.Header header) void
setHeaders
(org.apache.http.Header[] headers) void
void
setParams
(org.apache.http.params.HttpParams params) void
setReasonPhrase
(String reason) void
setStatusCode
(int code) void
setStatusLine
(org.apache.http.ProtocolVersion ver, int code) void
setStatusLine
(org.apache.http.ProtocolVersion ver, int code, String reason) void
setStatusLine
(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
String
content 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
Strings
are 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:
getStatusLine
in interfaceorg.apache.http.HttpResponse
-
setStatusLine
public void setStatusLine(org.apache.http.StatusLine statusline) - Specified by:
setStatusLine
in interfaceorg.apache.http.HttpResponse
-
setStatusLine
public void setStatusLine(org.apache.http.ProtocolVersion ver, int code) - Specified by:
setStatusLine
in interfaceorg.apache.http.HttpResponse
-
setStatusLine
- Specified by:
setStatusLine
in interfaceorg.apache.http.HttpResponse
-
setStatusCode
- Specified by:
setStatusCode
in interfaceorg.apache.http.HttpResponse
- Throws:
IllegalStateException
-
setReasonPhrase
- Specified by:
setReasonPhrase
in interfaceorg.apache.http.HttpResponse
- Throws:
IllegalStateException
-
getEntity
public org.apache.http.HttpEntity getEntity()- Specified by:
getEntity
in interfaceorg.apache.http.HttpResponse
-
setEntity
public void setEntity(org.apache.http.HttpEntity entity) - Specified by:
setEntity
in interfaceorg.apache.http.HttpResponse
-
getLocale
- Specified by:
getLocale
in interfaceorg.apache.http.HttpResponse
-
setLocale
- Specified by:
setLocale
in interfaceorg.apache.http.HttpResponse
-
getProtocolVersion
public org.apache.http.ProtocolVersion getProtocolVersion()- Specified by:
getProtocolVersion
in interfaceorg.apache.http.HttpMessage
-
containsHeader
- Specified by:
containsHeader
in interfaceorg.apache.http.HttpMessage
-
getHeaders
- Specified by:
getHeaders
in interfaceorg.apache.http.HttpMessage
-
getFirstHeader
- Specified by:
getFirstHeader
in interfaceorg.apache.http.HttpMessage
-
getLastHeader
- Specified by:
getLastHeader
in interfaceorg.apache.http.HttpMessage
-
getAllHeaders
public org.apache.http.Header[] getAllHeaders()- Specified by:
getAllHeaders
in interfaceorg.apache.http.HttpMessage
-
addHeader
public void addHeader(org.apache.http.Header header) - Specified by:
addHeader
in interfaceorg.apache.http.HttpMessage
-
addHeader
- Specified by:
addHeader
in interfaceorg.apache.http.HttpMessage
-
setHeader
public void setHeader(org.apache.http.Header header) - Specified by:
setHeader
in interfaceorg.apache.http.HttpMessage
-
setHeader
- Specified by:
setHeader
in interfaceorg.apache.http.HttpMessage
-
setHeaders
public void setHeaders(org.apache.http.Header[] headers) - Specified by:
setHeaders
in interfaceorg.apache.http.HttpMessage
-
removeHeader
public void removeHeader(org.apache.http.Header header) - Specified by:
removeHeader
in interfaceorg.apache.http.HttpMessage
-
removeHeaders
- Specified by:
removeHeaders
in interfaceorg.apache.http.HttpMessage
-
headerIterator
public org.apache.http.HeaderIterator headerIterator()- Specified by:
headerIterator
in interfaceorg.apache.http.HttpMessage
-
headerIterator
- Specified by:
headerIterator
in interfaceorg.apache.http.HttpMessage
-
getParams
public org.apache.http.params.HttpParams getParams()- Specified by:
getParams
in interfaceorg.apache.http.HttpMessage
-
setParams
public void setParams(org.apache.http.params.HttpParams params) - Specified by:
setParams
in interfaceorg.apache.http.HttpMessage
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-