|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface TestResponse
Response returned by TestClient.
It is used as an output of TestClient, which is an output of
RestTester, for example:
TestResponse resp = RestTester.start(new URI("http://www.google.com"))
.get("load from page of Google");
if (resp.getStatus() == 200) {
// everything is fine
} else if (resp.getStatus() == 404) {
// google.com not found, hm...
}
TestResponse extends XmlDocument, which is a abstract
of an XML document, which can be retrieved from itself. For example:
TestResponse resp = RestTester.start(new URI("http://example.com"))
.get("load XML document");
Collection<XmlDocument> employees = resp.nodes("/Staff/Employee");
for (XmlDocument employee : employees) {
String name = employee.xpath("name/text()").get(0);
// ...
}
TestResponse also extends JsonDocument, which is an
abstract of a Json document, which can be retrieved from itself.
In case of any problems inside (connection, time-outs, assertions, etc.)
implementation has to throw AssertionError.
Implementation of this interface shall be mutable and thread-safe.
| Field Summary | |
|---|---|
static int |
MAX_ATTEMPTS
How many attempts to make when assertThat(AssertionPolicy)
reports a problem. |
| Method Summary | |
|---|---|
TestResponse |
assertBody(org.hamcrest.Matcher<String> matcher)
Verifies HTTP response body content against provided matcher, and throws AssertionError in case of mismatch. |
TestResponse |
assertHeader(String name,
org.hamcrest.Matcher<Iterable<String>> matcher)
Verifies HTTP header against provided matcher, and throws AssertionError in case of mismatch. |
TestResponse |
assertJson(String element)
Verifies the Json data against the element identifier argument, and throws AssertionError in case of mismatch. |
TestResponse |
assertStatus(int status)
Verifies HTTP response status code against the provided absolute value, and throws AssertionError in case of mismatch. |
TestResponse |
assertStatus(org.hamcrest.Matcher<Integer> matcher)
Verifies HTTP response status code against the provided matcher, and throws AssertionError in case of mismatch. |
TestResponse |
assertThat(AssertionPolicy assertion)
Assert something ( AssertionError will be thrown if assertion
fails). |
TestResponse |
assertXPath(String xpath)
Verifies HTTP response body XHTML/XML content against XPath query, and throws AssertionError in case of mismatch. |
Cookie |
cookie(String name)
Get cookie. |
void |
fail(String reason)
Fail and report a problem (throws AssertionError with the
message provided). |
TestClient |
follow()
Follow the LOCATION header. |
String |
getBody()
Get body as a string, assuming it's UTF-8. |
MultivaluedMap<String,String> |
getHeaders()
Get a collection of all headers. |
int |
getStatus()
Get status of the response as a positive integer number. |
String |
getStatusLine()
Get status line of the response. |
TestResponse |
registerNs(String prefix,
Object uri)
Register additional namespace prefix for XPath. |
TestClient |
rel(String query)
Find link in XML and return new client with this link as URI. |
| Methods inherited from interface com.rexsl.test.XmlDocument |
|---|
merge, node, nodes, xpath |
| Methods inherited from interface com.rexsl.test.JsonDocument |
|---|
json, nodesJson |
| Field Detail |
|---|
static final int MAX_ATTEMPTS
assertThat(AssertionPolicy)
reports a problem.
| Method Detail |
|---|
TestClient follow()
TestClient rel(@NotNull
String query)
query - The path of the link, as XPath query
int getStatus()
String getStatusLine()
MultivaluedMap<String,String> getHeaders()
Cookie cookie(@NotNull
String name)
name - Name of the cookie to get
String getBody()
UTF-8.
TestResponse registerNs(@NotNull
String prefix,
@NotNull
Object uri)
For example:
String name = RestTester.start(new URI("http://www.example.com"))
.registerNs("ns1", "http://example.com")
.registerNs("foo", "http://example.com/foo")
.xpath("/ns1:root/foo:name/text()")
.get(0);
A number of standard namespaces are registered by default in
instances of XmlDocument returned by RestTester. Their
full list is in SimpleXml.SimpleXml(String).
If a namespace prefix is already registered an
IllegalArgumentException will be thrown.
registerNs in interface XmlDocumentprefix - The XPath prefix to registeruri - Namespace URI
void fail(@NotNull
String reason)
AssertionError with the
message provided).
reason - Reason of failure
TestResponse assertThat(@NotNull
AssertionPolicy assertion)
AssertionError will be thrown if assertion
fails).
assertion - The assertion to use
TestResponse assertStatus(int status)
AssertionError in case of mismatch.
status - Expected status code
TestResponse assertStatus(@NotNull
org.hamcrest.Matcher<Integer> matcher)
AssertionError in case of mismatch.
matcher - Matcher to validate status code
TestResponse assertBody(@NotNull
org.hamcrest.Matcher<String> matcher)
AssertionError in case of mismatch.
matcher - The matcher to use
TestResponse assertHeader(@NotNull
String name,
@NotNull
org.hamcrest.Matcher<Iterable<String>> matcher)
AssertionError in case of mismatch.
The iterator for the matcher will always be a real object an never
NULL, even if such a header is absent in the response. If the
header is absent the iterable will be empty.
name - Name of the header to matchmatcher - The matcher to use
TestResponse assertXPath(@NotNull
String xpath)
AssertionError in case of mismatch.
xpath - Query to use
TestResponse assertJson(@NotNull
String element)
AssertionError in case of mismatch.
element - Element in the Json data of this object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||