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 this to 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 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: ResponseAsserts
      Asserts that the response StatusCode matches the expected status code.
      Specified by:
      seeResponseCodeIs in interface ResponseAsserts
      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: ResponseAsserts
      Asserts that the response StatusCode is in the 2xx range.
      Specified by:
      seeResponseCodeIsSuccessful in interface ResponseAsserts
      Returns:
      this instance for method chaining
    • seeResponseTimeLess

      @Step("\u2191(API)[ASSERT] Response time less: <{maxResponseMs}>") public AssertableResponse seeResponseTimeLess(long maxResponseMs)
      Description copied from interface: ResponseAsserts
      Asserts that the response time is less than maximum expected.
      Specified by:
      seeResponseTimeLess in interface ResponseAsserts
      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: ResponseAsserts
      Asserts response Body field using custom matchers.
      Specified by:
      seeResponseBodyFieldMatch in interface ResponseAsserts
      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: ResponseAsserts
      Asserts response Header using custom matchers.
      Specified by:
      seeResponseHeaderMatch in interface ResponseAsserts
      Parameters:
      header - header name
      matcher - Matcher
      Returns:
      this instance for method chaining
    • seeResponseIsJsonType

      @Step("\u2191(API)[ASSERT] Response is JSON type") public AssertableResponse seeResponseIsJsonType()
      Description copied from interface: ResponseAsserts
      Asserts that the response is JSON object or JSON array.
      Specified by:
      seeResponseIsJsonType in interface ResponseAsserts
      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: ResponseAsserts
      Asserts 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:
      seeResponseContainsJson in interface ResponseAsserts
      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: ResponseAsserts
      Asserts 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:
      seeResponseContainsJsonSubset in interface ResponseAsserts
      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: ResponseAsserts
      Asserts 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:
      seeResponseContainsJson in interface ResponseAsserts
      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: ResponseAsserts
      Asserts that the response JSON matches the expected JSON with strict array ordering.

      Extra object fields cause an AssertionError.

      Specified by:
      seeResponseExactlyMatchJson in interface ResponseAsserts
      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: ResponseAsserts
      Asserts that the response JSON matches the expected JSON with strict array ordering.

      Extra object fields cause an AssertionError.

      Specified by:
      seeResponseExactlyMatchJson in interface ResponseAsserts
      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: ResponseAsserts
      Asserts that the response JSON matches the expected JSON with strict array ordering.

      Extra object fields are ignored.

      Specified by:
      seeResponseContainsJsonStrictOrder in interface ResponseAsserts
      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: ResponseAsserts
      Asserts response JSON matches the expected JSON using contains, AND/OR, and optional checks.

      Same behavior as JsonAsserts.assertJsonsExtended(String, String).

      Specified by:
      seeResponseContainsExtendedJson in interface ResponseAsserts
      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: ResponseAsserts
      Asserts that the response JSON matches the expected JSON without strict array ordering.

      Extra object fields cause an AssertionError.

      Specified by:
      seeResponseExactlyMatchJsonIgnoringOrder in interface ResponseAsserts
      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: ResponseAsserts
      Asserts that the response matches the JSON schema.
      Specified by:
      seeResponseMatchesJsonSchema in interface ResponseAsserts
      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: ResponseAsserts
      Asserts that the response matches the XML schema.
      Specified by:
      seeResponseMatchesXmlSchema in interface ResponseAsserts
      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: ResponseAsserts
      Asserts that the response body JSON array contains exactly the expected number of elements.
      Specified by:
      seeResponseBodyElementsCount in interface ResponseAsserts
      Parameters:
      expectedCount - expected number of elements
      Returns:
      this instance for method chaining
    • grabResponseHeader

      @Step("\u2191(API) Grab header <{header}> value") public String grabResponseHeader(String header)
      Description copied from interface: ResponseGrab
      Returns the response header value.
      Specified by:
      grabResponseHeader in interface ResponseGrab
      Parameters:
      header - header name
      Returns:
      response header value as a String
    • grabResponseBody

      @Step("\u2191(API) Grab response body") public String grabResponseBody()
      Description copied from interface: ResponseGrab
      Returns the full response body.
      Specified by:
      grabResponseBody in interface ResponseGrab
      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: ResponseGrab
      Returns the response body field value converted to String.
      Specified by:
      grabStringFromResponseByPath in interface ResponseGrab
      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: ResponseGrab
      Returns the response body field value as the specified type.
      Specified by:
      grabDataFromResponseByPath in interface ResponseGrab
      Parameters:
      path - path to field (example: data.user.id)
      Returns:
      response body field value as an Object