Loading
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Integration Procedure Unit Testing from Apex (Managed Package)

          Integration Procedure Unit Testing from Apex (Managed Package)

          For the managed package runtime, you can set up a test class in Apex and use it to call and test an Integration Procedure. You must mock HTTP Action responses.

          Managed Package app icon This information is for Omnistudio for Managed Packages. For Omnistudio on standard runtime, see Omnistudio Help.

          The following is an example unit test of an Integration Procedure:

          @isTest(seeAllData=true)
          global with sharing class TestVlocityIntergationProcedure
          {
              static testMethod void testVip()
              {
                  Map<String, Object> response = (Map<String, Object>)namespace.IntegrationProcedureService.runIntegrationService('Type_Subtype',
                      new Map<String, Object>{
                          'AccountName' => 'Vlocity'
                      }, new Map<String, Object>());
                  System.assertEquals('joe@vlocity.com', response.get('ContactEmail'));
              }
          }
          

          Note these features of the example:

          • You must use Salesforce's seeAllData property on the @isTest annotation. This ensures that the unit test sees the Vlocity SObject data in the org.

          • The method that runs the Integration Procedure is IntegrationProcedureService.runIntegrationService.

          • The namespace is vlocity_cmt, vlocity_ins, or vlocity_ps.

          • The Type_Subtype parameter specifies the Integration Procedure to test.

          Salesforce has specific requirements for testing HTTP callouts. Therefore, HTTP Actions require special handling.

          In Fall '19 and later releases, you can set the mock HTTP response of an Integration Procedure using the following Vlocity global method: 

          IntegrationProcedureServiceTest.setMockHttpResponse(HttpResponse response)

          This is required because when an Integration Procedure runs, the Vlocity Managed Package makes the HTTP callout internally.

          The following is an example unit test of an Integration Procedure that includes an HTTP Action:

          @isTest(seeAllData=true)
          global with sharing class TestVlocityIntergationProcedure
          {
              static testMethod void testVipWithHttpCallout()
              {
                  HttpResponse res = new HttpResponse();
                  res.setHeader('Content-Type', 'application/json');
                  res.setBody('{"ContactEmail":"joe@vlocity.com"}');
                  res.setStatusCode(200);
           
                  namespace.IntegrationProcedureServiceTest.setMockHttpResponse(res);
           
                  Map<String, Object> response = (Map<String, Object>)namespace.IntegrationProcedureService.runIntegrationService('Type_Subtype',
                      new Map<String, Object>{
                          'AccountName' => 'Vlocity'
                      }, new Map<String, Object>());
           
                  System.assertEquals('joe@vlocity.com', response.get('ContactEmail'));
              }
          }
          

          In Winter '20 and later releases, if an Integration Procedure includes more than one HTTP Action, you can set the mock HTTP responses using the following Vlocity global method:

          IntegrationProcedureServiceTest.setMockHttpResponseByUrlOrActionName()

          Using the Element Name of the HTTP Action is often easier. However, for some HTTP Actions, such as one within a Loop Block, you might have to specify the URL. If you specify the URL, it must be the exact URL you are calling. If it is a NamedCredential, it follows the pattern callout:NamedCredentialName.

          The following is an example unit test of an Integration Procedure that includes two HTTP Actions:

          @isTest(seeAllData=true)
          global with sharing class TestMockHttpIP 
          {
              static testMethod void testVipWithHttpCallout()
              {
                  HttpResponse res1 = new HttpResponse();
                  res1.setHeader('Content-Type', 'application/json');
          
                  res1.setBody('{"ContactEmail":"joe@vlocity.com"}');
                  res1.setStatusCode(200);
          
                  namespace.IntegrationProcedureServiceTest.setMockHttpResponseByUrlOrActionName('GetContactsHttp', res1);
                  
          	HttpResponse res2 = new HttpResponse();
                  res2.setHeader('Content-Type', 'application/json');
          
                  res2.setBody('{"ContactEmail":"joe2@vlocity.com"}');
                  res2.setStatusCode(200);
          
                  namespace.IntegrationProcedureServiceTest.setMockHttpResponseByUrlOrActionName('callout:MyContactInfo2', res2);
          
          		Map<String, Object> response = (Map<String, Object>)namespace.IntegrationProcedureService.runIntegrationService('Type_Subtype', 
          			new Map<String, Object>{
          				'AccountName' => 'Vlocity'
          			}, new Map<String, Object>());
          
          	System.assertEquals('joe@vlocity.com', response.get('ContactEmail')); 
                  System.assertEquals('joe2@vlocity.com', response.get('Action2Response')); 
              }
          }
           
          Loading
          Salesforce Help | Article