API_MockFactory.MockBuilder
Class
global class API_MockFactory.MockBuilderFluent builder for constructing and registering mock responses.
Since: 1.0
Example:
API_MockFactory.forService('API_SendEmail')
.body('{"messageId":"msg-123"}')
.statusCode(200)
.register();Methods
| Method | Description |
|---|---|
| global API_MockFactory.MockBuilder body(String body) | Sets the response body. |
| global API_MockFactory.MockBuilder fromResponse(HttpResponse response) | Populates the builder from an existing HttpResponse. |
| global void register() | Registers the mock response in the factory. |
| global API_MockFactory.MockBuilder status(String status) | Sets the HTTP status text. |
| global API_MockFactory.MockBuilder statusCode(Integer statusCode) | Sets the HTTP status code. |
| global API_MockFactory.MockBuilder withFailureRate(Integer failureRate) | Sets the failure rate percentage for fault injection. |
| global API_MockFactory.MockBuilder withHeader(String name, String value) | Adds a single response header. |
| global API_MockFactory.MockBuilder withHeaders(Map<String, String> headers) | Adds multiple response headers. |
Method Details
body
global API_MockFactory.MockBuilder body(String body)Sets the response body.
Parameters:
body(String) - The response body (supports {{request.field}} interpolation)
Returns: API_MockFactory.MockBuilder - This builder for chaining
Since: 1.0
fromResponse
global API_MockFactory.MockBuilder fromResponse(HttpResponse response)Populates the builder from an existing HttpResponse.
Parameters:
response(HttpResponse) - The HttpResponse to extract body, status code, and headers from
Returns: API_MockFactory.MockBuilder - This builder for chaining
Since: 1.0
register
global void register()Registers the mock response in the factory.
Since: 1.0
status
global API_MockFactory.MockBuilder status(String status)Sets the HTTP status text.
Parameters:
status(String) - The HTTP status text (e.g., "OK", "Internal Server Error")
Returns: API_MockFactory.MockBuilder - This builder for chaining
Since: 1.0
statusCode
global API_MockFactory.MockBuilder statusCode(Integer statusCode)Sets the HTTP status code.
Parameters:
statusCode(Integer) - The HTTP status code
Returns: API_MockFactory.MockBuilder - This builder for chaining
Since: 1.0
withFailureRate
global API_MockFactory.MockBuilder withFailureRate(Integer failureRate)Sets the failure rate percentage for fault injection.
Parameters:
failureRate(Integer) - Percentage of requests to fail (0-100)
Returns: API_MockFactory.MockBuilder - This builder for chaining
Since: 1.0
withHeader
global API_MockFactory.MockBuilder withHeader(String name, String value)Adds a single response header.
Parameters:
Returns: API_MockFactory.MockBuilder - This builder for chaining
Since: 1.0
withHeaders
global API_MockFactory.MockBuilder withHeaders(Map<String, String> headers)Adds multiple response headers.
Parameters:
headers(Map) - Map of header key-value pairs
Returns: API_MockFactory.MockBuilder - This builder for chaining
Since: 1.0