Skip to content

API_OutboundTestHelper

Class · Group: Testing

apex
global inherited sharing class API_OutboundTestHelper

Class has base methods that can be used to test an outbound service.

Example

apex
API_OutboundTestHelper.assertCallSuccessful(SERVICE_NAME, record.Id, parameters);

Methods

MethodDescription
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

apex
global static void assertCallAborted(ApiCall__c apiCall, String exceptionMessage)

Tests that an API call aborts with a specific error message.

Parameters

ParameterTypeDescription
apiCallApiCall__cThe API call containing the service and parameters to call
exceptionMessageStringThe error message that must exist in the response

Example

apex
ApiCall__c apiCall = TST_Factory.newOutboundApiCall(SERVICE_NAME, record.Id);
API_OutboundTestHelper.assertCallAborted(apiCall, 'Expected error message');
apex
global static List<API_Base> assertCallAborted(List<ApiCall__c> apiCalls)

Tests that a web service call is aborted as expected.

Parameters

ParameterTypeDescription
apiCallsListThe API calls containing the services and parameters to call

Returns API_Base — A list of handlers that processed the requests.

Example

apex
List<ApiCall__c> apiCalls = TST_Factory.newOutboundApiCall(SERVICE_NAME, record.Id);
List<API_Base> handlers = API_OutboundTestHelper.assertCallAborted(apiCalls);
apex
global static void assertCallAborted(List<ApiCall__c> apiCalls, String exceptionMessage)

Tests that an API call aborts with a specific error message.

Parameters

ParameterTypeDescription
apiCallsListThe API calls containing the services and parameters to call
exceptionMessageApiCall__cThe message string which is checked in the abort message

Example

apex
List<ApiCall__c> apiCalls = TST_Factory.newOutboundApiCall(SERVICE_NAME, record.Id);
API_OutboundTestHelper.assertCallAborted(apiCalls, 'Expected error message');
apex
global static API_Base assertCallAborted(String serviceName, Id recordId)

Tests that a web service call is aborted as expected.

Parameters

ParameterTypeDescription
serviceNameStringThe class name of the API handler
recordIdIdThe object that triggered the callout (optional)

Returns API_Base — The handler executing the web service call.

Example

apex
API_Base handler = API_OutboundTestHelper.assertCallAborted(SERVICE_NAME, record.Id);
apex
global static API_Base assertCallAborted(String serviceName, Id recordId, Map<String, String> parameters)

Tests that an API call aborts as expected with parameters.

Parameters

ParameterTypeDescription
serviceNameStringThe name of the web service handler
recordIdIdid of the triggering object (optional)
parametersMapMap of parameters to pass to the API call

Returns API_Base — The handler executing the API call

Example

apex
Map<String, String> parameters = new Map<String, String>{API_MyService.PARAM_KEY => 'value'};
API_Base handler = API_OutboundTestHelper.assertCallAborted(SERVICE_NAME, record.Id, parameters);
apex
global static API_Base assertCallAborted(String serviceName, Id recordId, Set<String> parameterNames)

Tests an aborted API call with parameter names.

Parameters

ParameterTypeDescription
serviceNameStringThe name of the web service handler
recordIdIdid of the triggering object (optional)
parameterNamesSetNames of parameters to pass to the service handler

Returns API_Base — The handler executing the API call

Example

apex
Set<String> parameterNames = new Set<String>{'param1', 'param2'};
API_Base handler = API_OutboundTestHelper.assertCallAborted(SERVICE_NAME, record.Id, parameterNames);
apex
global static API_Base assertCallAborted(String serviceName, Id recordId, String parameterName)

Tests an aborted API call with a single parameter name.

Parameters

ParameterTypeDescription
serviceNameStringThe name of the web service handler
recordIdIdid of the triggering object (optional)
parameterNameStringName of a parameter to pass to the service handler

Returns API_Base — The handler executing the API call

Example

apex
API_Base handler = API_OutboundTestHelper.assertCallAborted(SERVICE_NAME, record.Id, API_MyService.PARAM_KEY);

assertCallFailed

apex
global static List<API_Base> assertCallFailed(List<ApiCall__c> apiCalls)

Tests that a web service call fails as expected.

Parameters

ParameterTypeDescription
apiCallsListThe API calls containing the services and parameters to call

Returns API_Base — A list of handlers that processed the request

Example

apex
List<ApiCall__c> apiCalls = TST_Factory.newOutboundApiCall(SERVICE_NAME, record.Id);
List<API_Base> handlers = API_OutboundTestHelper.assertCallFailed(apiCalls);

assertCallSuccessful

apex
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

ParameterTypeDescription
apiCallsListThe API calls containing the services and parameters to call

Returns API_Base — A list of handlers that processed the request

Example

apex
List<ApiCall__c> apiCalls = TST_Factory.newOutboundApiCall(SERVICE_NAME, record.Id);
List<API_Base> handlers = API_OutboundTestHelper.assertCallSuccessful(apiCalls);
apex
global static API_Base assertCallSuccessful(String serviceName, Id recordId)

Tests the successful execution of a web service call.

Parameters

ParameterTypeDescription
serviceNameStringThe name of the web service handler
recordIdIdId of the triggering object (optional)

Returns API_Base — The handler executing the API call

Example

apex
API_Base handler = API_OutboundTestHelper.assertCallSuccessful(SERVICE_NAME, record.Id);
apex
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

ParameterTypeDescription
serviceNameStringThe name of the web service handler
recordIdIdid of the triggering object (optional)
parametersMapMap of parameters to pass to the API call

Returns API_Base — The handler executing the API call

Example

apex
Map<String, String> parameters = new Map<String, String>{API_MyService.PARAM_KEY => 'value'};
API_Base handler = API_OutboundTestHelper.assertCallSuccessful(SERVICE_NAME, record.Id, parameters);
apex
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

ParameterTypeDescription
serviceNameStringThe name of the web service handler
recordIdIdid of the triggering object (optional)
parameterNamesSetNames of parameters to pass to the service handler

Returns API_Base — The handler executing the API call

Example

apex
Set<String> parameterNames = new Set<String>{'param1', 'param2'};
API_Base handler = API_OutboundTestHelper.assertCallSuccessful(SERVICE_NAME, record.Id, parameterNames);
apex
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

ParameterTypeDescription
serviceNameStringThe name of the web service handler
recordIdIdid of the triggering object (optional)
parameterNameStringName of a parameter to pass to the service handler

Returns API_Base — The handler executing the API call

Example

apex
API_Base handler = API_OutboundTestHelper.assertCallSuccessful(SERVICE_NAME, record.Id, API_MyService.PARAM_KEY);

assertParseFailed

apex
global static List<API_Base> assertParseFailed(List<ApiCall__c> apiCalls)

Tests that a web service call fails to parse the response.

Parameters

ParameterTypeDescription
apiCallsListThe API calls containing the services and parameters to call

Returns API_Base — A list of handlers that processed the request

Example

apex
List<ApiCall__c> apiCalls = TST_Factory.newOutboundApiCall(SERVICE_NAME, record.Id);
List<API_Base> handlers = API_OutboundTestHelper.assertParseFailed(apiCalls);