Class ResponseAssertion
java.lang.Object
org.apache.juneau.rest.client.assertion.ResponseAssertion
A fluent assertion class for validating
RestResponse instances.
Provides assertion methods for HTTP status code, response headers, and body content.
All assertion methods return this for chaining, and throw AssertionError
on failure.
Obtain instances via RestResponse.assertThat().
See Also:
- Since:
- 9.2.1
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionand()Returns the underlying response (for further access after assertions).body()Returns a fluent body assertion.Returns a fluent header assertion for the named response header.Asserts that the response status code is in the 4xx (client error) range.isOk()Asserts that the response status code is in the 2xx (success) range.Asserts that the response status code is in the 5xx (server error) range.statusCode(int expected) Asserts that the response status code equals the expected value.
-
Constructor Details
-
ResponseAssertion
Constructor.- Parameters:
response- The response to assert on. Must not benull .
-
-
Method Details
-
statusCode
Asserts that the response status code equals the expected value.- Parameters:
expected- The expected status code.- Returns:
- This object (for chaining).
- Throws:
AssertionError- If the status code does not match.
-
isOk
Asserts that the response status code is in the 2xx (success) range.- Returns:
- This object (for chaining).
- Throws:
AssertionError- If the status code is not in 200–299.
-
isClientError
Asserts that the response status code is in the 4xx (client error) range.- Returns:
- This object (for chaining).
- Throws:
AssertionError- If the status code is not in 400–499.
-
isServerError
Asserts that the response status code is in the 5xx (server error) range.- Returns:
- This object (for chaining).
- Throws:
AssertionError- If the status code is not in 500–599.
-
header
Returns a fluent header assertion for the named response header.- Parameters:
name- The header name (case-insensitive). Must not benull .- Returns:
- A new header assertion. Never
null .
-
body
Returns a fluent body assertion.- Returns:
- A new body assertion. Never
null .
-
and
Returns the underlying response (for further access after assertions).- Returns:
- The response. Never
null .
-