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
      Assert response StatusCode
      Specified by:
      seeResponseCodeIs in interface ResponseAsserts
      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: ResponseAsserts
      Assert response StatusCode should be 2xx
      Specified by:
      seeResponseCodeIsSuccessful in interface ResponseAsserts
    • seeResponseTimeLess

      @Step("\u2191(API)[ASSERT] Response time less: {maxResponseMs}") public AssertableResponse seeResponseTimeLess(long maxResponseMs)
      Description copied from interface: ResponseAsserts
      Assert response time less then 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
      Assert response Body field match matcher
      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
      Assert response header match matcher
      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
      Assert response is Json/JsonArray type
      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
      Json assertion without strict array ordering

      extensible fields will be skipped. But extensible elements in array cause AssertionError

      Specified by:
      seeResponseContainsJson in interface ResponseAsserts
      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: ResponseAsserts
      Json assertion without strict array ordering

      extensible fields and elements in array will be skipped

      Specified by:
      seeResponseContainsJsonSubset in interface ResponseAsserts
      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: ResponseAsserts
      Json assertion without strict array ordering

      extensible fields will be skipped

      Specified by:
      seeResponseContainsJson in interface ResponseAsserts
      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: ResponseAsserts
      Json assertion with strict array ordering

      extensible fields not expected

      Specified by:
      seeResponseExactlyMatchJson in interface ResponseAsserts
      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: ResponseAsserts
      Json assertion with strict array ordering

      extensible fields not expected

      Specified by:
      seeResponseExactlyMatchJson in interface ResponseAsserts
      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: ResponseAsserts
      Json assertion with strict array ordering

      extensible fields will be skipped

      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
      Json assertion contains and/or optional checks

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

      Specified by:
      seeResponseContainsExtendedJson in interface ResponseAsserts
      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: ResponseAsserts
      Json assertion without strict array ordering

      extensible fields not expected

      Specified by:
      seeResponseExactlyMatchJsonIgnoringOrder in interface ResponseAsserts
      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: ResponseAsserts
      Validate that the response matches the JSON schema
      Specified by:
      seeResponseMatchesJsonSchema in interface ResponseAsserts
      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: ResponseAsserts
      Validate that the response matches the XML schema
      Specified by:
      seeResponseMatchesXmlSchema in interface ResponseAsserts
      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: ResponseAsserts
      Assert that response body(JsonArray) has exactly count elements
      Specified by:
      seeResponseBodyElementsCount in interface ResponseAsserts
      Parameters:
      expectedCount - expected count 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
      Return response header data
      Specified by:
      grabResponseHeader in interface ResponseGrab
      Parameters:
      header - header name
      Returns:
      String with response header value
    • grabResponseBody

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