Class MocksApi
- All Implemented Interfaces:
MocksConfig,MocksInt
For one instance run recommended: MocksApi mockApi = MocksApi.getInstance();
Create @Step for every Created and Verified mock in your mock Class for allure report
Enchanted Report for mocks verify default:ON: enchantedReport, can be disabled by: setEnchantedReport(boolean))
Await for some assert default: awaitMs, can be changed by: setAwaitMs(int)
-
Field Summary
Fields inherited from class net.bugreaper.modules.api.setup.ApiAbstract
authToken, contentType, enableLogging, headers, logger, maxResponseMsAssert, maxTimeoutMs, password, port, queryParams, requestHeaders, requestQueryParams, url, useBasicAuth, username -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidassertAllMocksCount(int receivedCount) Assert of all requests to mock-server countvoidassertAllMocksCount(int from, int to) Assert of all requests to mock-server count from tovoidassertMocksCountWithAwait(int from, int to) Assert of all requests to mock-server count from tostatic StringbaseAuthGenerate(String user, String pass) voidClean mock-server logs (requests/responses)voidcreateMock(String mockExpectation) Create mock expectationvoidcreateMockCustom(String description, String path) Create mock expectationReturns and logs (at INFO level) a human-readable summary of all resolved configuration values.static MocksApiReturns the instance ofMocksApiwith config builderMocksApi().getRequestValue(String mockSetup, String extractPath) Return value from request (can be body, header, other)voidReset mock serversetAwaitMs(int awaitMs) Configure global await for asserts with awaitsetEnchantedReport(boolean enchantedReport) Enabling or disabling enchanted mockVerify reportsetLogging(boolean enable) Enables or disables logging manually (debug log level will print logs anyway!)voidAdd attachment with mock requests list (only method and path)voidAdd attachment with mock server logs (requests/responses)voidAdd attachment with requests to mock-servervoidverifyMock(String verifySetup) Verify requests to mock-server by verify setupvoidverifyMockCustom(String description, String path) Verify requests to mock-server by setup from filevoidverifyMockCustomWithAwait(String description, String path) Verify requests to mock-server by setup from filevoidverifyMockSequence(String verifySetup) Verify sequence of requests to mock-server by verify setupvoidverifyMockSequenceWithAwait(String verifySetup) Verify sequence of requests to mock server by verify setupvoidverifyMockWithAwait(String verifySetup) Verify requests to mock-server by verify setupwithAwaitMs(int specificAwaitMs) Configure await for next assert with await (than await rollback to global) globalMocksConfig.setAwaitMs(int)will be ignoredMethods inherited from class net.bugreaper.modules.api.setup.ApiAbstract
buildRequest, buildSimpleRequest
-
Constructor Details
-
MocksApi
This constructor initializes client for interaction with mock-server- Parameters:
url- mock-server url ("http://localhost")port- mock-server port
-
MocksApi
public MocksApi()Constructs mock-server client configuration.Loads configuration values from a YAML file.
Default file:
bugreaper.ymlCustom file: using
-DbugreaperEnv=testloadsbugreaper-test.ymlmodules: mocks: url: http://localhost port: 1082 await: 440 # optional logging: true # optional enchanted-report: false # optionalMissing required keys will result in configuration errors. Missing optional keys will fall back to predefined defaults.
-
-
Method Details
-
getInstance
Returns the instance ofMocksApiwith config builderMocksApi().This implementation is thread-safe using method-level synchronization.
- Returns:
- the singleton instance of
MocksApi - See Also:
-
setAwaitMs
Description copied from interface:MocksConfigConfigure global await for asserts with await- Specified by:
setAwaitMsin interfaceMocksConfig- Parameters:
awaitMs- await ms- Returns:
- this instance for method chaining
-
withAwaitMs
Description copied from interface:MocksConfigConfigure await for next assert with await (than await rollback to global) globalMocksConfig.setAwaitMs(int)will be ignored- Specified by:
withAwaitMsin interfaceMocksConfig- Parameters:
specificAwaitMs- ms await- Returns:
- this instance for method chaining
-
setLogging
Description copied from interface:MocksConfigEnables or disables logging manually (debug log level will print logs anyway!)- Specified by:
setLoggingin interfaceMocksConfig- Parameters:
enable- true=request/response logging (Allure on always!)- Returns:
- this instance for method chaining
-
setEnchantedReport
Description copied from interface:MocksConfigEnabling or disabling enchanted mockVerify reportSame behavior as
MockEnchantedDiffer.- Specified by:
setEnchantedReportin interfaceMocksConfig- Parameters:
enchantedReport- true=on/false=off- Returns:
- this instance for method chaining
-
getConfigSummary
Description copied from interface:MocksConfigReturns and logs (at INFO level) a human-readable summary of all resolved configuration values.The summary includes values loaded from the YAML configuration file as well as any fields overridden programmatically after construction. Optional fields that were not present in the configuration and resolved via default values may also be included.
- Specified by:
getConfigSummaryin interfaceMocksConfig- Returns:
- String with summary
-
resetMocks
@Step("(MOCK)[RESET]: reset Mocks") public void resetMocks()Description copied from interface:MocksIntReset mock serverClean all: logs, requests, expectations
- Specified by:
resetMocksin interfaceMocksInt
-
cleanMockLogs
@Step("(MOCK)[CLEAN] Clean all recorded log messages from mock-server") public void cleanMockLogs()Description copied from interface:MocksIntClean mock-server logs (requests/responses)- Specified by:
cleanMockLogsin interfaceMocksInt
-
showMockLogs
@Step("(MOCK)[LOGS] Retrieve all recorded log messages from mock-server") public void showMockLogs()Description copied from interface:MocksIntAdd attachment with mock server logs (requests/responses)On DEBUG level also print to console
- Specified by:
showMockLogsin interfaceMocksInt
-
showMockRequests
@Step("(MOCK)[LOGS] Retrieve all requests to mock-server") public void showMockRequests()Description copied from interface:MocksIntAdd attachment with requests to mock-server- Specified by:
showMockRequestsin interfaceMocksInt
-
showBaseRequestsList
public void showBaseRequestsList()Description copied from interface:MocksIntAdd attachment with mock requests list (only method and path)- Specified by:
showBaseRequestsListin interfaceMocksInt
-
createMock
@Step("(MOCK)[CREATE] Create Mock") public void createMock(@Param(mode=HIDDEN) String mockExpectation) Description copied from interface:MocksIntCreate mock expectation- Specified by:
createMockin interfaceMocksInt- Parameters:
mockExpectation- - String with mock expectation Json
-
createMockCustom
Description copied from interface:MocksIntCreate mock expectation- Specified by:
createMockCustomin interfaceMocksInt- Parameters:
description- - description part for steppath- - path to file in resources
-
assertAllMocksCount
@Step("(MOCK)[VERIFY] Assert count of ALL requests to Mock-server {receivedCount}") public void assertAllMocksCount(int receivedCount) Description copied from interface:MocksIntAssert of all requests to mock-server count- Specified by:
assertAllMocksCountin interfaceMocksInt- Parameters:
receivedCount- - expected EXACTLY count of requests
-
assertAllMocksCount
@Step("(MOCK)(VERIFY) Assert count of ALL requests to Mock-server from:{from} to{to}") public void assertAllMocksCount(int from, int to) Description copied from interface:MocksIntAssert of all requests to mock-server count from to- Specified by:
assertAllMocksCountin interfaceMocksInt- Parameters:
from- int expected fromto- int expected to
-
verifyMockCustom
Description copied from interface:MocksIntVerify requests to mock-server by setup from file- Specified by:
verifyMockCustomin interfaceMocksInt- Parameters:
description- - description part for steppath- - path to file in resources
-
verifyMock
Description copied from interface:MocksIntVerify requests to mock-server by verify setup- Specified by:
verifyMockin interfaceMocksInt- Parameters:
verifySetup- - String with mock verify Json
-
verifyMockSequence
Description copied from interface:MocksIntVerify sequence of requests to mock-server by verify setup- Specified by:
verifyMockSequencein interfaceMocksInt- Parameters:
verifySetup- - String with mock verify Json
-
verifyMockCustomWithAwait
Description copied from interface:MocksIntVerify requests to mock-server by setup from filewith await
- Specified by:
verifyMockCustomWithAwaitin interfaceMocksInt- Parameters:
description- - description part for steppath- - path to file in resources
-
verifyMockSequenceWithAwait
@Step("(MOCK)[VERIFY] Verify sequence with await") public void verifyMockSequenceWithAwait(@Param(mode=HIDDEN) String verifySetup) Description copied from interface:MocksIntVerify sequence of requests to mock server by verify setupwith await
- Specified by:
verifyMockSequenceWithAwaitin interfaceMocksInt- Parameters:
verifySetup- - String with mock verify Json
-
verifyMockWithAwait
@Step("(MOCK)[VERIFY] Verify mock with await") public void verifyMockWithAwait(@Param(mode=HIDDEN) String verifySetup) Description copied from interface:MocksIntVerify requests to mock-server by verify setupwith await
- Specified by:
verifyMockWithAwaitin interfaceMocksInt- Parameters:
verifySetup- - String with mock verify Json
-
assertMocksCountWithAwait
@Step("(MOCK)(VERIFY) Assert count of ALL requests to Mock-server from:{from} to{to} with await") public void assertMocksCountWithAwait(int from, int to) Description copied from interface:MocksIntAssert of all requests to mock-server count from towith await
- Specified by:
assertMocksCountWithAwaitin interfaceMocksInt- Parameters:
from- int minimum expected requeststo- int maximum expected requests
-
getRequestValue
@Step("[MOCK]: Get value from request {extractPath}") public Object getRequestValue(String mockSetup, String extractPath) Description copied from interface:MocksIntReturn value from request (can be body, header, other)Can be used to get some info (id, hash, base64...) for next check
var value = mocksApi.getRequestValue( """ { "method": "POST", "path": "/api/user" }""", "[0].body.name"); //grab value from key "name" from body of first request by condition- Specified by:
getRequestValuein interfaceMocksInt- Parameters:
mockSetup- - setup for requestextractPath- - json path in request to mock (example: "[0].body.parameters.name")- Returns:
- Object (any types)
-
baseAuthGenerate
-