Class AssertableResponse
java.lang.Object
net.bugreaper.modules.api.assertable.AssertableResponseAbstract
net.bugreaper.modules.api.assertable.AssertableResponse
- All Implemented Interfaces:
ResponseAsserts,ResponseGrab
public class AssertableResponse
extends AssertableResponseAbstract
implements ResponseAsserts, ResponseGrab
Provides a fluent API for asserting and extracting data from API responses.
This class is designed to be used in a chainable manner, allowing multiple assertions to be performed in a single readable statement.
Usage Example:
api.sendGet("/users/1")
.seeResponseCodeIs(200)
.seeResponseContainsJson(Paths.get("expected.json"));
Design Notes:
- All assertion methods return
thisto support fluent chaining. - Assertion logic is delegated to internal helper methods to keep steps readable.
- Failures should throw assertion errors to immediately fail the test.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the response body field value as the specified type.Returns the full response body.grabResponseHeader(String header) Returns the response header value.Returns the response body field value converted to String.seeResponseBodyElementsCount(int expectedCount) Asserts that the response body JSON array contains exactly the expected number of elements.seeResponseBodyFieldMatch(String path, org.hamcrest.Matcher<?> matcher) Asserts response Body field using custom matchers.seeResponseCodeIs(int statusCode) Asserts that the response StatusCode matches the expected status code.Asserts that the response StatusCode is in the 2xx range.seeResponseContainsExtendedJson(String expectedSetup) Asserts response JSON matches the expected JSON using contains, AND/OR, and optional checks.seeResponseContainsJson(String expectedBody) Asserts that the response JSON matches the expected JSON without strict array ordering.seeResponseContainsJson(Path filePath) Asserts that the response JSON matches the expected JSON without strict array ordering.seeResponseContainsJsonStrictOrder(String expectedBody) Asserts that the response JSON matches the expected JSON with strict array ordering.seeResponseContainsJsonSubset(String expectedBody) Asserts that the response JSON matches the expected JSON without strict array ordering.seeResponseExactlyMatchJson(String expectedBody) Asserts that the response JSON matches the expected JSON with strict array ordering.seeResponseExactlyMatchJson(Path filePath) Asserts that the response JSON matches the expected JSON with strict array ordering.seeResponseExactlyMatchJsonIgnoringOrder(String expectedBody) Asserts that the response JSON matches the expected JSON without strict array ordering.seeResponseHeaderMatch(String header, org.hamcrest.Matcher<?> matcher) Asserts response Header using custom matchers.Asserts that the response is JSON object or JSON array.seeResponseMatchesJsonSchema(Path filePath) Asserts that the response matches the JSON schema.seeResponseMatchesXmlSchema(Path filePath) Asserts that the response matches the XML schema.seeResponseTimeLess(long maxResponseMs) Asserts that the response time is less than maximum expected.Methods inherited from class net.bugreaper.modules.api.assertable.AssertableResponseAbstract
grabDataFromResponseByPathMethod, grabResponseBodyMethod, grabResponseHeaderMethod, grabStringFromResponseByPathMethod, seeResponseBodyElementsCountMethod, seeResponseBodyFieldMatchMethod, seeResponseCodeIsMethod, seeResponseCodeIsSuccessfulMethod, seeResponseContainsExtendedJsonMethod, seeResponseContainsJsonMethod, seeResponseContainsJsonMethod, seeResponseContainsJsonStrictOrderMethod, seeResponseContainsJsonSubsetMethod, seeResponseExactlyMatchJsonIgnoringOrderMethod, seeResponseExactlyMatchJsonMethod, seeResponseExactlyMatchJsonMethod, seeResponseHeaderMatchMethod, seeResponseIsJsonTypeMethod, seeResponseMatchesJsonSchemaMethod, seeResponseMatchesXmlSchemaMethod, seeResponseTimeLessMethod
-
Constructor Details
-
AssertableResponse
public AssertableResponse(io.restassured.response.Response response)
-
-
Method Details
-
seeResponseCodeIs
@Step("\u2191(API)[ASSERT] Status code is: <{statusCode}>") public AssertableResponse seeResponseCodeIs(int statusCode) Description copied from interface:ResponseAssertsAsserts that the response StatusCode matches the expected status code.- Specified by:
seeResponseCodeIsin interfaceResponseAsserts- Parameters:
statusCode- expected HTTP StatusCode- Returns:
- this instance for method chaining
-
seeResponseCodeIsSuccessful
@Step("\u2191(API)[ASSERT] Status code is: SUCCESSFUL(2xx)") public AssertableResponse seeResponseCodeIsSuccessful()Description copied from interface:ResponseAssertsAsserts that the response StatusCode is in the 2xx range.- Specified by:
seeResponseCodeIsSuccessfulin interfaceResponseAsserts- Returns:
- this instance for method chaining
-
seeResponseTimeLess
@Step("\u2191(API)[ASSERT] Response time less: <{maxResponseMs}>") public AssertableResponse seeResponseTimeLess(long maxResponseMs) Description copied from interface:ResponseAssertsAsserts that the response time is less than maximum expected.- Specified by:
seeResponseTimeLessin interfaceResponseAsserts- Parameters:
maxResponseMs- maximum expected response time in MS- Returns:
- this instance for method chaining
-
seeResponseBodyFieldMatch
@Step("\u2191(API)[ASSERT] Response body field: \'{path}\' <{matcher}>") public AssertableResponse seeResponseBodyFieldMatch(String path, org.hamcrest.Matcher<?> matcher) Description copied from interface:ResponseAssertsAsserts response Body field using custom matchers.- Specified by:
seeResponseBodyFieldMatchin interfaceResponseAsserts- Parameters:
path- path to field (data.user.id)matcher- Matcher- Returns:
- this instance for method chaining
-
seeResponseHeaderMatch
@Step("\u2191(API)[ASSERT] Response header: \'{header}\' <{matcher}>") public AssertableResponse seeResponseHeaderMatch(String header, org.hamcrest.Matcher<?> matcher) Description copied from interface:ResponseAssertsAsserts response Header using custom matchers.- Specified by:
seeResponseHeaderMatchin interfaceResponseAsserts- Parameters:
header- header namematcher- Matcher- Returns:
- this instance for method chaining
-
seeResponseIsJsonType
@Step("\u2191(API)[ASSERT] Response is JSON type") public AssertableResponse seeResponseIsJsonType()Description copied from interface:ResponseAssertsAsserts that the response is JSON object or JSON array.- Specified by:
seeResponseIsJsonTypein interfaceResponseAsserts- Returns:
- this instance for method chaining
-
seeResponseContainsJson
@Step("\u2191(API)[ASSERT] Response body: CONTAINS JSON with non-strict order") public AssertableResponse seeResponseContainsJson(@Param(mode=HIDDEN) String expectedBody) Description copied from interface:ResponseAssertsAsserts that the response JSON matches the expected JSON without strict array ordering.Extra object fields are ignored, but additional array elements cause an
AssertionError.- Specified by:
seeResponseContainsJsonin interfaceResponseAsserts- Parameters:
expectedBody- expected JSON subset (array order is ignored, but the number of elements must match if provided)- Returns:
- this instance for method chaining
-
seeResponseContainsJsonSubset
@Step("\u2191(API)[ASSERT] Response body: CONTAINS JSON with non-strict order (ignoring extensive array elements)") public AssertableResponse seeResponseContainsJsonSubset(@Param(mode=HIDDEN) String expectedBody) Description copied from interface:ResponseAssertsAsserts that the response JSON matches the expected JSON without strict array ordering.Extra fields and the order of elements in arrays are ignored.
- Specified by:
seeResponseContainsJsonSubsetin interfaceResponseAsserts- Parameters:
expectedBody- expected JSON subset (array order is ignored and array size may differ)- Returns:
- this instance for method chaining
-
seeResponseContainsJson
@Step("\u2191(API)[ASSERT] Response body: CONTAINS JSON with non-strict order") public AssertableResponse seeResponseContainsJson(Path filePath) Description copied from interface:ResponseAssertsAsserts that the response JSON matches the expected JSON without strict array ordering.Extra object fields are ignored, but additional array elements cause an
AssertionError.- Specified by:
seeResponseContainsJsonin interfaceResponseAsserts- Parameters:
filePath- path to the local file, including the file name, relative to resources, containing the expected JSON subset (array order is ignored, but the number of elements must match if provided)- Returns:
- this instance for method chaining
-
seeResponseExactlyMatchJson
@Step("\u2191(API)[ASSERT] Response body: EQUAL to JSON with strict order") public AssertableResponse seeResponseExactlyMatchJson(@Param(mode=HIDDEN) String expectedBody) Description copied from interface:ResponseAssertsAsserts that the response JSON matches the expected JSON with strict array ordering.Extra object fields cause an
AssertionError.- Specified by:
seeResponseExactlyMatchJsonin interfaceResponseAsserts- Parameters:
expectedBody- expected full JSON with strict array ordering- Returns:
- this instance for method chaining
-
seeResponseExactlyMatchJson
@Step("\u2191(API)[ASSERT] Response body: EQUAL to JSON with strict order") public AssertableResponse seeResponseExactlyMatchJson(Path filePath) Description copied from interface:ResponseAssertsAsserts that the response JSON matches the expected JSON with strict array ordering.Extra object fields cause an
AssertionError.- Specified by:
seeResponseExactlyMatchJsonin interfaceResponseAsserts- Parameters:
filePath- path to the local file, including the file name, relative to resources, containing the expected JSON with strict array ordering- Returns:
- this instance for method chaining
-
seeResponseContainsJsonStrictOrder
@Step("\u2191(API)[ASSERT] Response body: CONTAINS JSON with strict order") public AssertableResponse seeResponseContainsJsonStrictOrder(@Param(mode=HIDDEN) String expectedBody) Description copied from interface:ResponseAssertsAsserts that the response JSON matches the expected JSON with strict array ordering.Extra object fields are ignored.
- Specified by:
seeResponseContainsJsonStrictOrderin interfaceResponseAsserts- Parameters:
expectedBody- expected part of JSON with strict ordered arrays- Returns:
- this instance for method chaining
-
seeResponseContainsExtendedJson
@Step("Response body: CONTAINS extended JSON (with options)") public AssertableResponse seeResponseContainsExtendedJson(@Param(mode=HIDDEN) String expectedSetup) Description copied from interface:ResponseAssertsAsserts response JSON matches the expected JSON using contains, AND/OR, and optional checks.Same behavior as
JsonAsserts.assertJsonsExtended(String, String).- Specified by:
seeResponseContainsExtendedJsonin interfaceResponseAsserts- Parameters:
expectedSetup- expected JSON with contains, AND/OR, and optional checks- Returns:
- this instance for method chaining
-
seeResponseExactlyMatchJsonIgnoringOrder
@Step("\u2191(API)[ASSERT] Response body: EQUAL to JSON with non-strict order") public AssertableResponse seeResponseExactlyMatchJsonIgnoringOrder(@Param(mode=HIDDEN) String expectedBody) Description copied from interface:ResponseAssertsAsserts that the response JSON matches the expected JSON without strict array ordering.Extra object fields cause an
AssertionError.- Specified by:
seeResponseExactlyMatchJsonIgnoringOrderin interfaceResponseAsserts- Parameters:
expectedBody- expected full JSON with arrays (array order is ignored)
-
seeResponseMatchesJsonSchema
@Step("\u2191(API)[ASSERT] Response body: has correct JSON schema") public AssertableResponse seeResponseMatchesJsonSchema(Path filePath) Description copied from interface:ResponseAssertsAsserts that the response matches the JSON schema.- Specified by:
seeResponseMatchesJsonSchemain interfaceResponseAsserts- Parameters:
filePath- path to the local file, including the file name, relative to resources, containing the JSON schema- Returns:
- this instance for method chaining
-
seeResponseMatchesXmlSchema
@Step("\u2191(API)[ASSERT] Response body: has correct XML schema") public AssertableResponse seeResponseMatchesXmlSchema(Path filePath) Description copied from interface:ResponseAssertsAsserts that the response matches the XML schema.- Specified by:
seeResponseMatchesXmlSchemain interfaceResponseAsserts- Parameters:
filePath- path to the local file, including the file name, relative to resources, containing the XML schema- Returns:
- this instance for method chaining
-
seeResponseBodyElementsCount
@Step("\u2191(API)[ASSERT] Response body: has {expectedCount} elements") public AssertableResponse seeResponseBodyElementsCount(int expectedCount) Description copied from interface:ResponseAssertsAsserts that the response body JSON array contains exactly the expected number of elements.- Specified by:
seeResponseBodyElementsCountin interfaceResponseAsserts- Parameters:
expectedCount- expected number of elements- Returns:
- this instance for method chaining
-
grabResponseHeader
Description copied from interface:ResponseGrabReturns the response header value.- Specified by:
grabResponseHeaderin interfaceResponseGrab- Parameters:
header- header name- Returns:
- response header value as a String
-
grabResponseBody
Description copied from interface:ResponseGrabReturns the full response body.- Specified by:
grabResponseBodyin interfaceResponseGrab- Returns:
- response body as a String
-
grabStringFromResponseByPath
@Step("\u2191(API) Grab response body field <{path}> value as String") public String grabStringFromResponseByPath(String path) Description copied from interface:ResponseGrabReturns the response body field value converted to String.- Specified by:
grabStringFromResponseByPathin interfaceResponseGrab- Parameters:
path- path to field (example:data.user.id)- Returns:
- String representation of the response body field value
-
grabDataFromResponseByPath
@Step("\u2191(API) Grab response body field <{path}>") public Object grabDataFromResponseByPath(String path) Description copied from interface:ResponseGrabReturns the response body field value as the specified type.- Specified by:
grabDataFromResponseByPathin interfaceResponseGrab- Parameters:
path- path to field (example:data.user.id)- Returns:
- response body field value as an Object
-