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.

Since: 1.0

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 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, String, String> parameters)Tests that an API call aborts as expected with parameters.
global static API_Base assertCallAborted(String serviceName, String> parameterNames)Tests an aborted API call with parameter names.
global static API_Base assertCallAborted(String serviceName, String parameterName)Tests an aborted API call with a single parameter name.
global static List assertCallFailed(List<ApiCall__c> apiCalls)Tests that a web service call fails as expected.
global static List 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, String, String> parameters)Tests the successful execution of a web service call, passing a map of parameters.
global static API_Base assertCallSuccessful(String serviceName, String> parameterNames)Tests the successful execution of a web service call, passing a set of parameters.
global static API_Base assertCallSuccessful(String serviceName, String parameterName)Tests the successful execution of a web service call, passing a single parameter.
global static List assertParseFailed(List<ApiCall__c> apiCalls)Tests that a web service call fails to parse the response.

Method Details

assertCallAborted

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

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

Parameters:

  • apiCall (ApiCall__c) - The API call containing the service and parameters to call
  • exceptionMessage (String) - The error message that must exist in the response

Since: 1.0

Example:

apex
ApiCall__c apiCall = TST_Factory.newOutboundApiCall(SERVICE_NAME, record.Id);
API_OutboundTestHelper.assertCallAborted(apiCall, 'Expected error message');

assertCallAborted

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

Tests that a web service call is aborted as expected.

Parameters:

  • apiCalls (List) - The API calls containing the services and parameters to call

Returns: API_Base - A list of handlers that processed the requests.

Since: 1.0

Example:

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

assertCallAborted

apex
global static void assertCallAborted(List<ApiCall__c> apiCalls, String exceptionMessage)

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

Parameters:

  • 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

Since: 1.0

Example:

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

assertCallAborted

apex
global static API_Base assertCallAborted(String serviceName, Id recordId)

Tests that a web service call is aborted as expected.

Parameters:

  • 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.

Since: 1.0

Example:

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

assertCallAborted

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:

  • 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

Since: 1.0

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);

assertCallAborted

apex
global static API_Base assertCallAborted(String serviceName, Id recordId, Set<String> parameterNames)

Tests an aborted API call with parameter names.

Parameters:

  • 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

Since: 1.0

Example:

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

assertCallAborted

apex
global static API_Base assertCallAborted(String serviceName, Id recordId, String parameterName)

Tests an aborted API call with a single parameter name.

Parameters:

  • 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

Since: 1.0

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:

  • apiCalls (List) - The API calls containing the services and parameters to call

Returns: API_Base - A list of handlers that processed the request

Since: 1.0

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:

  • apiCalls (List) - The API calls containing the services and parameters to call

Returns: API_Base - A list of handlers that processed the request

Since: 1.0

Example:

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

assertCallSuccessful

apex
global static API_Base assertCallSuccessful(String serviceName, Id recordId)

Tests the successful execution of a web service call.

Parameters:

  • 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

Since: 1.0

Example:

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

assertCallSuccessful

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:

  • 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

Since: 1.0

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);

assertCallSuccessful

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:

  • 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

Since: 1.0

Example:

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

assertCallSuccessful

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:

  • 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

Since: 1.0

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:

  • apiCalls (List) - The API calls containing the services and parameters to call

Returns: API_Base - A list of handlers that processed the request

Since: 1.0

Example:

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