Callout Multi Mock
An instance of the forvendi.BreezzApi.CalloutMultiMock class is used for creating an HttpCalloutMock that handles multiple API endpoints.
Used in conjunction with CalloutMock to configure responses for specific routes. CalloutMultiMock stores multiple CalloutMock instances and returns the appropriate HttpResponse based on the request method and URL matching.
addRoute(String method, String url)
Creates a child mock that will be matched against a given HTTP method and URL pattern.
Signature: public forvendi.CalloutMock addRoute(String method, String url)
Parameters:
method: HTTP method (e.g., ‘GET’, ‘POST’, ‘PUT’, ‘DELETE’).url: Endpoint URL pattern or regex path.
Return Value: forvendi.CalloutMock – The child mock for route configuration.
CalloutMultiMock Usage Example
To set up multiple mock endpoints in Apex unit tests, use BreezzApi.TESTS.setCalloutMultiMock() along with chained addRoute() calls:
BreezzApi.TESTS.setCalloutMultiMock()
.addRoute('GET', '/services/data/v57.0/tooling/sobjects/ContainerAsyncRequest/(\\w+{18})')
.withOrgBaseUrl()
.withStatusCode(200)
.withHeader('Content-Type', 'application/json')
.withBody('{"State":"Failed","DeployDetails":{"allComponentMessages":[{"problem":"ERROR"}]}}')
.apply()
.addRoute('POST', '/services/data/v57.0/tooling/sobjects/ContainerAsyncRequest')
.withOrgBaseUrl()
.withStatusCode(201)
.withHeader('Content-Type', 'application/json')
.withBody('{"id":"001000000000000AAA","success":true}')
.apply()
.addRoute('POST', '/services/data/v57.0/tooling/sobjects/ApexClassMember')
.withOrgBaseUrl()
.withStatusCode(201)
.withHeader('Content-Type', 'application/json')
.withBody('{"id":"002000000000000AAA","success":true}')
.apply()
.addRoute('POST', '/services/data/v57.0/tooling/sobjects/ApexTriggerMember')
.withOrgBaseUrl()
.withStatusCode(201)
.withHeader('Content-Type', 'application/json')
.withBody('{"id":"003000000000000AAA","success":true}')
.apply()
.addRoute('POST', '/services/data/v57.0/tooling/sobjects/MetadataContainer')
.withOrgBaseUrl()
.withStatusCode(201)
.withHeader('Content-Type', 'application/json')
.withBody('{"id":"005000000000000AAA","success":true}')
.apply()
.addRoute('GET', '/services/data/v57.0/tooling/query')
.withOrgBaseUrl()
.withStatusCode(200)
.withHeader('Content-Type', 'application/json')
.withBody('{"records":[{"id":"006000000000000AAA"}]}')
.apply();