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 TypeMethodDescriptionvoidassertAllMocksCount(int receivedCount) Asserts that the total number of requests to mock-server matches the expected count.voidassertAllMocksCount(int from, int to) Asserts that the total number of requests to mock-server is within the specified range.voidassertMocksCountWithAwait(int from, int to) Asserts that the total number of requests to mock-server is within the specified range.voidClean mock-server logs (requests/responses)voidcreateMock(String mockExpectation) Creates a mock-server expectation.voidcreateMockCustom(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).voidReset mock-server.voidAdds an attachment with a list of mock-server requests (only HTTP method and path).voidAdds an attachment with mock-server logs (requests/responses).voidAdd attachment with requests to mock-servervoidverifyMock(String verifySetup) Verifies mock-server requests according to the provided verification setup.voidverifyMockCustom(String description, String path) Verifies mock-server requests according to the verification setup loaded from a file.voidverifyMockCustomWithAwait(String description, String path) Verifies mock-server requests according to the verification setup loaded from a file.voidverifyMockSequence(String verifySetup) Verifies mock-server requests according to the verification setup loaded from a file.voidverifyMockSequenceWithAwait(String verifySequenceSetup) Verifies mock-server requests according to the sequence verification setupvoidverifyMockWithAwait(String verifySetup) 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
Creates a mock-server expectation.- Parameters:
mockExpectation- JSON string containing the mock-server expectation definition
-
createMockCustom
Creates a mock-server expectation loaded from a file.- Parameters:
description- description part for steppath- 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
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 failsIllegalArgumentException- if the provided data is not valid JSON
-
verifyMockCustom
Verifies mock-server requests according to the verification setup loaded from a file.- Parameters:
description- description part for steppath- path to the resource file with mock-server verification setup- Throws:
AssertionError- if the assertion failsIllegalArgumentException- if reading the file fails or the provided data is not valid JSON
-
verifyMockSequence
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 failsIllegalArgumentException- if the provided data is not valid JSON
-
verifyMockWithAwait
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 failsIllegalArgumentException- if the provided data is not valid JSON
-
verifyMockCustomWithAwait
Verifies mock-server requests according to the verification setup loaded from a file.Uses await.
- Parameters:
description- description part for steppath- path to the resource file with mock-server verification setup- Throws:
AssertionError- if the assertion failsIllegalArgumentException- if reading the file fails or the provided data is not valid JSON
-
verifyMockSequenceWithAwait
Verifies mock-server requests according to the sequence verification setupUses await.
- Parameters:
verifySequenceSetup- JSON string containing the mock-server sequence verification setup- Throws:
AssertionError- if the assertion failsIllegalArgumentException- 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 requeststo- maximum expected number of requests- Throws:
AssertionError- if the assertion failsIllegalArgumentException- 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 failsIllegalArgumentException- 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 requeststo- maximum expected number of requests- Throws:
AssertionError- if the assertion failsIllegalArgumentException- if the provided data is not valid JSON
-
getRequestValue
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 requestextractPath- - json path in request to mock (example:"[0].body.json.id")- Returns:
- Object (any types)
-