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