API_OutboundTestHelper
Class · Group: Testing
global inherited sharing class API_OutboundTestHelperClass has base methods that can be used to test an outbound service.
Example
API_OutboundTestHelper.assertCallSuccessful(SERVICE_NAME, record.Id, parameters);Methods
| Method | Description |
|---|---|
| global static void assertCallAborted(ApiCall__c apiCall, String exceptionMessage) | Tests that an API call aborts with a specific error message. |
| global static List<API_Base> assertCallAborted(List<ApiCall__c> apiCalls) | Tests that a web service call is aborted as expected. |
| global static void assertCallAborted(List<ApiCall__c> apiCalls, String exceptionMessage) | Tests that an API call aborts with a specific error message. |
| global static API_Base assertCallAborted(String serviceName, Id recordId) | Tests that a web service call is aborted as expected. |
| global static API_Base assertCallAborted(String serviceName, Id recordId, Map<String, String> parameters) | Tests that an API call aborts as expected with parameters. |
| global static API_Base assertCallAborted(String serviceName, Id recordId, Set<String> parameterNames) | Tests an aborted API call with parameter names. |
| global static API_Base assertCallAborted(String serviceName, Id recordId, String parameterName) | Tests an aborted API call with a single parameter name. |
| global static List<API_Base> assertCallFailed(List<ApiCall__c> apiCalls) | Tests that a web service call fails as expected. |
| global static List<API_Base> assertCallSuccessful(List<ApiCall__c> apiCalls) | Tests that a web service call is executed successfully for each of the provided API calls. |
| global static API_Base assertCallSuccessful(String serviceName, Id recordId) | Tests the successful execution of a web service call. |
| global static API_Base assertCallSuccessful(String serviceName, Id recordId, Map<String, String> parameters) | Tests the successful execution of a web service call, passing a map of parameters. |
| global static API_Base assertCallSuccessful(String serviceName, Id recordId, Set<String> parameterNames) | Tests the successful execution of a web service call, passing a set of parameters. |
| global static API_Base assertCallSuccessful(String serviceName, Id recordId, String parameterName) | Tests the successful execution of a web service call, passing a single parameter. |
| global static List<API_Base> assertParseFailed(List<ApiCall__c> apiCalls) | Tests that a web service call fails to parse the response. |
assertCallAborted
global static void assertCallAborted(ApiCall__c apiCall, String exceptionMessage)Tests that an API call aborts with a specific error message.
Parameters
| Parameter | Type | Description |
|---|---|---|
apiCall | ApiCall__c | The API call containing the service and parameters to call |
exceptionMessage | String | The error message that must exist in the response |
Example
ApiCall__c apiCall = TST_Factory.newOutboundApiCall(SERVICE_NAME, record.Id);
API_OutboundTestHelper.assertCallAborted(apiCall, 'Expected error message');global static List<API_Base> assertCallAborted(List<ApiCall__c> apiCalls)Tests that a web service call is aborted as expected.
Parameters
| Parameter | Type | Description |
|---|---|---|
apiCalls | List | The API calls containing the services and parameters to call |
Returns API_Base — A list of handlers that processed the requests.
Example
List<ApiCall__c> apiCalls = TST_Factory.newOutboundApiCall(SERVICE_NAME, record.Id);
List<API_Base> handlers = API_OutboundTestHelper.assertCallAborted(apiCalls);global static void assertCallAborted(List<ApiCall__c> apiCalls, String exceptionMessage)Tests that an API call aborts with a specific error message.
Parameters
| Parameter | Type | Description |
|---|---|---|
apiCalls | List | The API calls containing the services and parameters to call |
exceptionMessage | ApiCall__c | The message string which is checked in the abort message |
Example
List<ApiCall__c> apiCalls = TST_Factory.newOutboundApiCall(SERVICE_NAME, record.Id);
API_OutboundTestHelper.assertCallAborted(apiCalls, 'Expected error message');global static API_Base assertCallAborted(String serviceName, Id recordId)Tests that a web service call is aborted as expected.
Parameters
| Parameter | Type | Description |
|---|---|---|
serviceName | String | The class name of the API handler |
recordId | Id | The object that triggered the callout (optional) |
Returns API_Base — The handler executing the web service call.
Example
API_Base handler = API_OutboundTestHelper.assertCallAborted(SERVICE_NAME, record.Id);global static API_Base assertCallAborted(String serviceName, Id recordId, Map<String, String> parameters)Tests that an API call aborts as expected with parameters.
Parameters
| Parameter | Type | Description |
|---|---|---|
serviceName | String | The name of the web service handler |
recordId | Id | id of the triggering object (optional) |
parameters | Map | Map of parameters to pass to the API call |
Returns API_Base — The handler executing the API call
Example
Map<String, String> parameters = new Map<String, String>{API_MyService.PARAM_KEY => 'value'};
API_Base handler = API_OutboundTestHelper.assertCallAborted(SERVICE_NAME, record.Id, parameters);global static API_Base assertCallAborted(String serviceName, Id recordId, Set<String> parameterNames)Tests an aborted API call with parameter names.
Parameters
| Parameter | Type | Description |
|---|---|---|
serviceName | String | The name of the web service handler |
recordId | Id | id of the triggering object (optional) |
parameterNames | Set | Names of parameters to pass to the service handler |
Returns API_Base — The handler executing the API call
Example
Set<String> parameterNames = new Set<String>{'param1', 'param2'};
API_Base handler = API_OutboundTestHelper.assertCallAborted(SERVICE_NAME, record.Id, parameterNames);global static API_Base assertCallAborted(String serviceName, Id recordId, String parameterName)Tests an aborted API call with a single parameter name.
Parameters
| Parameter | Type | Description |
|---|---|---|
serviceName | String | The name of the web service handler |
recordId | Id | id of the triggering object (optional) |
parameterName | String | Name of a parameter to pass to the service handler |
Returns API_Base — The handler executing the API call
Example
API_Base handler = API_OutboundTestHelper.assertCallAborted(SERVICE_NAME, record.Id, API_MyService.PARAM_KEY);assertCallFailed
global static List<API_Base> assertCallFailed(List<ApiCall__c> apiCalls)Tests that a web service call fails as expected.
Parameters
| Parameter | Type | Description |
|---|---|---|
apiCalls | List | The API calls containing the services and parameters to call |
Returns API_Base — A list of handlers that processed the request
Example
List<ApiCall__c> apiCalls = TST_Factory.newOutboundApiCall(SERVICE_NAME, record.Id);
List<API_Base> handlers = API_OutboundTestHelper.assertCallFailed(apiCalls);assertCallSuccessful
global static List<API_Base> assertCallSuccessful(List<ApiCall__c> apiCalls)Tests that a web service call is executed successfully for each of the provided API calls.
Parameters
| Parameter | Type | Description |
|---|---|---|
apiCalls | List | The API calls containing the services and parameters to call |
Returns API_Base — A list of handlers that processed the request
Example
List<ApiCall__c> apiCalls = TST_Factory.newOutboundApiCall(SERVICE_NAME, record.Id);
List<API_Base> handlers = API_OutboundTestHelper.assertCallSuccessful(apiCalls);global static API_Base assertCallSuccessful(String serviceName, Id recordId)Tests the successful execution of a web service call.
Parameters
| Parameter | Type | Description |
|---|---|---|
serviceName | String | The name of the web service handler |
recordId | Id | Id of the triggering object (optional) |
Returns API_Base — The handler executing the API call
Example
API_Base handler = API_OutboundTestHelper.assertCallSuccessful(SERVICE_NAME, record.Id);global static API_Base assertCallSuccessful(String serviceName, Id recordId, Map<String, String> parameters)Tests the successful execution of a web service call, passing a map of parameters.
Parameters
| Parameter | Type | Description |
|---|---|---|
serviceName | String | The name of the web service handler |
recordId | Id | id of the triggering object (optional) |
parameters | Map | Map of parameters to pass to the API call |
Returns API_Base — The handler executing the API call
Example
Map<String, String> parameters = new Map<String, String>{API_MyService.PARAM_KEY => 'value'};
API_Base handler = API_OutboundTestHelper.assertCallSuccessful(SERVICE_NAME, record.Id, parameters);global static API_Base assertCallSuccessful(String serviceName, Id recordId, Set<String> parameterNames)Tests the successful execution of a web service call, passing a set of parameters.
Parameters
| Parameter | Type | Description |
|---|---|---|
serviceName | String | The name of the web service handler |
recordId | Id | id of the triggering object (optional) |
parameterNames | Set | Names of parameters to pass to the service handler |
Returns API_Base — The handler executing the API call
Example
Set<String> parameterNames = new Set<String>{'param1', 'param2'};
API_Base handler = API_OutboundTestHelper.assertCallSuccessful(SERVICE_NAME, record.Id, parameterNames);global static API_Base assertCallSuccessful(String serviceName, Id recordId, String parameterName)Tests the successful execution of a web service call, passing a single parameter.
Parameters
| Parameter | Type | Description |
|---|---|---|
serviceName | String | The name of the web service handler |
recordId | Id | id of the triggering object (optional) |
parameterName | String | Name of a parameter to pass to the service handler |
Returns API_Base — The handler executing the API call
Example
API_Base handler = API_OutboundTestHelper.assertCallSuccessful(SERVICE_NAME, record.Id, API_MyService.PARAM_KEY);assertParseFailed
global static List<API_Base> assertParseFailed(List<ApiCall__c> apiCalls)Tests that a web service call fails to parse the response.
Parameters
| Parameter | Type | Description |
|---|---|---|
apiCalls | List | The API calls containing the services and parameters to call |
Returns API_Base — A list of handlers that processed the request
Example
List<ApiCall__c> apiCalls = TST_Factory.newOutboundApiCall(SERVICE_NAME, record.Id);
List<API_Base> handlers = API_OutboundTestHelper.assertParseFailed(apiCalls);