Interface MocksInt

All Known Implementing Classes:
MocksApi

public interface MocksInt
Interface defines methods for facilitating helper interactions and assertions. Validates that all required methods are implemented.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    assertAllMocksCount(int receivedCount)
    Asserts that the total number of requests to mock-server matches the expected count.
    void
    assertAllMocksCount(int from, int to)
    Asserts that the total number of requests to mock-server is within the specified range.
    void
    assertMocksCountWithAwait(int from, int to)
    Asserts that the total number of requests to mock-server is within the specified range.
    void
    Clean mock-server logs (requests/responses)
    void
    createMock(String mockExpectation)
    Creates a mock-server expectation.
    void
    createMockCustom(String description, String path)
    Creates a mock-server expectation loaded from a file.
    getRequestValue(String mockSetup, String extractPath)
    Returns a value extracted from a mock-server request (body, header, or other source).
    void
    Reset mock-server.
    void
    Adds an attachment with a list of mock-server requests (only HTTP method and path).
    void
    Adds an attachment with mock-server logs (requests/responses).
    void
    Add attachment with requests to mock-server
    void
    verifyMock(String verifySetup)
    Verifies mock-server requests according to the provided verification setup.
    void
    verifyMockCustom(String description, String path)
    Verifies mock-server requests according to the verification setup loaded from a file.
    void
    Verifies mock-server requests according to the verification setup loaded from a file.
    void
    Verifies mock-server requests according to the verification setup loaded from a file.
    void
    verifyMockSequenceWithAwait(String verifySequenceSetup)
    Verifies mock-server requests according to the sequence verification setup
    void
    Verifies mock-server requests according to the provided verification setup.
  • Method Details

    • resetMocks

      void resetMocks()
      Reset mock-server.

      Clean all: logs, requests, expectations

    • cleanMockLogs

      void cleanMockLogs()
      Clean mock-server logs (requests/responses)
    • showMockLogs

      void showMockLogs()
      Adds an attachment with mock-server logs (requests/responses).

      At DEBUG level, logs are also printed to the console.

    • showMockRequests

      void showMockRequests()
      Add attachment with requests to mock-server
    • showBaseRequestsList

      void showBaseRequestsList()
      Adds an attachment with a list of mock-server requests (only HTTP method and path).
    • createMock

      void createMock(String mockExpectation)
      Creates a mock-server expectation.
      Parameters:
      mockExpectation - JSON string containing the mock-server expectation definition
    • createMockCustom

      void createMockCustom(String description, String path)
      Creates a mock-server expectation loaded from a file.
      Parameters:
      description - description part for step
      path - path to the resource file with mock-server expectation
      Throws:
      IllegalArgumentException - if reading the file fails or the provided data is not valid JSON
    • verifyMock

      void verifyMock(String verifySetup)
      Verifies mock-server requests according to the provided verification setup.
      Parameters:
      verifySetup - JSON string containing the mock-server verification setup
      Throws:
      AssertionError - if the assertion fails
      IllegalArgumentException - if the provided data is not valid JSON
    • verifyMockCustom

      void verifyMockCustom(String description, String path)
      Verifies mock-server requests according to the verification setup loaded from a file.
      Parameters:
      description - description part for step
      path - path to the resource file with mock-server verification setup
      Throws:
      AssertionError - if the assertion fails
      IllegalArgumentException - if reading the file fails or the provided data is not valid JSON
    • verifyMockSequence

      void verifyMockSequence(String verifySetup)
      Verifies mock-server requests according to the verification setup loaded from a file.
      Parameters:
      verifySetup - JSON string containing the mock-server sequence verification setup
      Throws:
      AssertionError - if the assertion fails
      IllegalArgumentException - if the provided data is not valid JSON
    • verifyMockWithAwait

      void verifyMockWithAwait(String verifySetup)
      Verifies mock-server requests according to the provided verification setup.

      Uses await.

      Parameters:
      verifySetup - JSON string containing the mock-server verification setup
      Throws:
      AssertionError - if the assertion fails
      IllegalArgumentException - if the provided data is not valid JSON
    • verifyMockCustomWithAwait

      void verifyMockCustomWithAwait(String description, String path)
      Verifies mock-server requests according to the verification setup loaded from a file.

      Uses await.

      Parameters:
      description - description part for step
      path - path to the resource file with mock-server verification setup
      Throws:
      AssertionError - if the assertion fails
      IllegalArgumentException - if reading the file fails or the provided data is not valid JSON
    • verifyMockSequenceWithAwait

      void verifyMockSequenceWithAwait(String verifySequenceSetup)
      Verifies mock-server requests according to the sequence verification setup

      Uses await.

      Parameters:
      verifySequenceSetup - JSON string containing the mock-server sequence verification setup
      Throws:
      AssertionError - if the assertion fails
      IllegalArgumentException - if the provided data is not valid JSON
    • assertMocksCountWithAwait

      void assertMocksCountWithAwait(int from, int to)
      Asserts that the total number of requests to mock-server is within the specified range.

      Uses await.

      Parameters:
      from - minimum expected number of requests
      to - maximum expected number of requests
      Throws:
      AssertionError - if the assertion fails
      IllegalArgumentException - if the provided data is not valid JSON
    • assertAllMocksCount

      void assertAllMocksCount(int receivedCount)
      Asserts that the total number of requests to mock-server matches the expected count.
      Parameters:
      receivedCount - expected exact number of requests
      Throws:
      AssertionError - if the assertion fails
      IllegalArgumentException - if the provided data is not valid JSON
    • assertAllMocksCount

      void assertAllMocksCount(int from, int to)
      Asserts that the total number of requests to mock-server is within the specified range.
      Parameters:
      from - minimum expected number of requests
      to - maximum expected number of requests
      Throws:
      AssertionError - if the assertion fails
      IllegalArgumentException - if the provided data is not valid JSON
    • getRequestValue

      Object getRequestValue(String mockSetup, String extractPath)
      Returns a value extracted from a mock-server request (body, header, or other source).

      Can be used to retrieve dynamic data (for example, ID, hash, or Base64 value) required for subsequent assertions.

      
       var value = mocksApi.getRequestValue(
            """
            {
                 "method": "POST",
                 "path": "/api/user"
            }""",
            "[0].body.json.name"); //grab value from key "name" from body of first request by condition
       
      Parameters:
      mockSetup - - setup for request
      extractPath - - json path in request to mock (example: "[0].body.json.id")
      Returns:
      Object (any types)