...
Overall, the ContentSearchMock class provides a convenient way to test HTTP requests made to the content service API by simulating the API behaviour with mock responses.
...
Implementation Steps:
Check the value of the
CONTENT_SERVICE_MOCK_ENABLED
property in the configuration file using theProjectUtil.getConfigValue()
method.If the property value is
true
, then:
a. Call theContentSearchMock.setup()
method to set up a mock server for testing HTTP requests made to the content service API.
b. Get the mock URL from the configuration file using theProjectUtil.getConfigValue()
method and store it in themockUrl
variable.
c. Send a GET request to the mock URL using theHttpUtil.sendGet/Post/PatchRequest()
method with the specifiedheaders
and store the response in theresponse
variable.
d. Call theContentSearchMock.teardown()
method to shut down the mock server.If the property value is
false
, then:
a. Send a GET request to the base content read URL using theHttpUtil.sendGet/Post/PatchRequest()
method with the specifiedheaders
and store the response in theresponse
variable.Continue with the rest of the code using the
response
variable.