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 TypeMethodDescriptionReturn response body field data (any type)Return response bodygrabResponseHeader(String header) Return response header dataReturn response body field data (converted to String)seeResponseBodyElementsCount(int expectedCount) Assert that response body(JsonArray) has exactly count elementsseeResponseBodyFieldMatch(String path, org.hamcrest.Matcher<?> matcher) Assert response Body field match matcherseeResponseCodeIs(int statusCode) Assert response StatusCodeAssert response StatusCode should be 2xxseeResponseContainsExtendedJson(String expectedSetup) Json assertion contains and/or optional checksseeResponseContainsJson(String expectedBody) Json assertion without strict array orderingseeResponseContainsJson(Path path) Json assertion without strict array orderingseeResponseContainsJsonStrictOrder(String expectedBody) Json assertion with strict array orderingseeResponseContainsJsonSubset(String expectedBody) Json assertion without strict array orderingseeResponseExactlyMatchJson(String expectedBody) Json assertion with strict array orderingJson assertion with strict array orderingseeResponseExactlyMatchJsonIgnoringOrder(String expectedBody) Json assertion without strict array orderingseeResponseHeaderMatch(String header, org.hamcrest.Matcher<?> matcher) Assert response header match matcherAssert response is Json/JsonArray typeValidate that the response matches the JSON schemaValidate that the response matches the XML schemaseeResponseTimeLess(long maxResponseMs) Assert response time less then maximum expectedMethods 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:ResponseAssertsAssert response StatusCode- Specified by:
seeResponseCodeIsin interfaceResponseAsserts- Parameters:
statusCode- expected StatusCode- Returns:
- this instance for method chaining
-
seeResponseCodeIsSuccessful
@Step("\u2191(API)[ASSERT] Status code is: SUCCESSFUL(2xx)") public AssertableResponse seeResponseCodeIsSuccessful()Description copied from interface:ResponseAssertsAssert response StatusCode should be 2xx- Specified by:
seeResponseCodeIsSuccessfulin interfaceResponseAsserts
-
seeResponseTimeLess
@Step("\u2191(API)[ASSERT] Response time less: {maxResponseMs}") public AssertableResponse seeResponseTimeLess(long maxResponseMs) Description copied from interface:ResponseAssertsAssert response time less then 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:ResponseAssertsAssert response Body field match matcher- 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:ResponseAssertsAssert response header match matcher- 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:ResponseAssertsAssert response is Json/JsonArray type- 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:ResponseAssertsJson assertion without strict array orderingextensible fields will be skipped. But extensible elements in array cause AssertionError
- Specified by:
seeResponseContainsJsonin interfaceResponseAsserts- Parameters:
expectedBody- expected part of JSON (arrays can be not ordered but must have same count of elements)- 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:ResponseAssertsJson assertion without strict array orderingextensible fields and elements in array will be skipped
- Specified by:
seeResponseContainsJsonSubsetin interfaceResponseAsserts- Parameters:
expectedBody- expected part of JSON (arrays can be not ordered and have different count)- Returns:
- this instance for method chaining
-
seeResponseContainsJson
@Step("\u2191(API)[ASSERT] Response body: CONTAINS JSON with non-strict order") public AssertableResponse seeResponseContainsJson(Path path) Description copied from interface:ResponseAssertsJson assertion without strict array orderingextensible fields will be skipped
- Specified by:
seeResponseContainsJsonin interfaceResponseAsserts- Parameters:
path- path to file in resources with expected part of JSON (arrays can be not ordered)- 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:ResponseAssertsJson assertion with strict array orderingextensible fields not expected
- Specified by:
seeResponseExactlyMatchJsonin interfaceResponseAsserts- Parameters:
expectedBody- expected full JSON with strict ordered arrays- Returns:
- this instance for method chaining
-
seeResponseExactlyMatchJson
@Step("\u2191(API)[ASSERT] Response body: EQUAL to JSON with strict order") public AssertableResponse seeResponseExactlyMatchJson(Path path) Description copied from interface:ResponseAssertsJson assertion with strict array orderingextensible fields not expected
- Specified by:
seeResponseExactlyMatchJsonin interfaceResponseAsserts- Parameters:
path- path to file in resources with expected full JSON with strict ordered arrays- 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:ResponseAssertsJson assertion with strict array orderingextensible fields will be skipped
- 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:ResponseAssertsJson assertion contains and/or optional checksSame behavior as
JsonAsserts.assertJsonsExtended(String, String).- Specified by:
seeResponseContainsExtendedJsonin interfaceResponseAsserts- Parameters:
expectedSetup- expected part of JSON and/or 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:ResponseAssertsJson assertion without strict array orderingextensible fields not expected
- Specified by:
seeResponseExactlyMatchJsonIgnoringOrderin interfaceResponseAsserts- Parameters:
expectedBody- expected full JSON with arrays (can be not ordered)
-
seeResponseMatchesJsonSchema
@Step("\u2191(API)[ASSERT] Response body: has correct JSON schema") public AssertableResponse seeResponseMatchesJsonSchema(Path path) Description copied from interface:ResponseAssertsValidate that the response matches the JSON schema- Specified by:
seeResponseMatchesJsonSchemain interfaceResponseAsserts- Parameters:
path- path to file in resources with Json schema- Returns:
- this instance for method chaining
-
seeResponseMatchesXmlSchema
@Step("\u2191(API)[ASSERT] Response body: has correct XML schema") public AssertableResponse seeResponseMatchesXmlSchema(Path path) Description copied from interface:ResponseAssertsValidate that the response matches the XML schema- Specified by:
seeResponseMatchesXmlSchemain interfaceResponseAsserts- Parameters:
path- path to file in resources with 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:ResponseAssertsAssert that response body(JsonArray) has exactly count elements- Specified by:
seeResponseBodyElementsCountin interfaceResponseAsserts- Parameters:
expectedCount- expected count of elements- Returns:
- this instance for method chaining
-
grabResponseHeader
Description copied from interface:ResponseGrabReturn response header data- Specified by:
grabResponseHeaderin interfaceResponseGrab- Parameters:
header- header name- Returns:
- String with response header value
-
grabResponseBody
Description copied from interface:ResponseGrabReturn response body- Specified by:
grabResponseBodyin interfaceResponseGrab- Returns:
- String with response body
-
grabStringFromResponseByPath
@Step("\u2191(API) Grab response body field <{path}> value as String") public String grabStringFromResponseByPath(String path) Description copied from interface:ResponseGrabReturn response body field data (converted to String)- Specified by:
grabStringFromResponseByPathin interfaceResponseGrab- Parameters:
path- path to field (example:data.user.id)- Returns:
- String with response body field data
-
grabDataFromResponseByPath
@Step("\u2191(API) Grab response body field <{path}>") public Object grabDataFromResponseByPath(String path) Description copied from interface:ResponseGrabReturn response body field data (any type)- Specified by:
grabDataFromResponseByPathin interfaceResponseGrab- Parameters:
path- path to field (example:data.user.id)- Returns:
- Object with response body field data
-