function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PranavLAXPranavLAX 

Test class for WebService SOAP API Call

Hello,

Can anyone please provide some guidance in how to go about writing test code coverage for Webservices API Calls to a 3rd party application.

Following is the code, that I am trying to get code coverage for:

 String datumapp = '{'
      + '"serial_number":"'+SerialNumber + '",'
      + '"model":"A20-R-500",'
      + '"reseller":"'+ SFDCResellerID +'",'
      + '"client":"' + SFDCClientID +'",'
      + '"package":"'+ PackageType +'",'
      + '"offsite":"'+ Offsite +'",'
      + '"data_center":"'+ DataCenter +'",'
      + '"status":"active"'
      + '}';
      
             
      Http httpProtocolInsertAppliance = new Http();       // Create HTTP request to send.
      HttpRequest requestapp = new HttpRequest(); // Set the endpoint URL.
      String endpointapp = 'https://rmc01.asdsdt.net/sfapi/appliance/';
      requestapp.setEndPoint(endpointapp);
      requestapp.setBody(datumapp);
      requestapp.setMethod('POST');
      requestapp.setHeader('X-API-KEY','abczyx');
      requestapp.setHeader('Content-length', String.valueOf(datumapp.length()));

      
      try
      {
      
      HttpResponse responseapp = httpProtocolInsertAppliance.send(requestapp);
      System.debug(responseapp.getBody()+'APPLIANCE INSERTION CHECK 1');
      System.debug(responseapp.getHeader('Location')+'APPLIANCE INSERTION CHECK 1');
     
      
      if(String.valueof(responseapp.getStatus())=='400')
      {
      
      throw new IntegrationException('Already exists');
      }

    Submitted

Santhosh KumarSanthosh Kumar

It is still a bit pain to test the Call outs so users have come up with varies ways to come around the problem and still achive the test coverage. Check out these links.

 

http://sfdc.arrowpointe.com/2009/05/01/testing-http-callouts/

http://www.pinguinshow.com/2011/10/09/testing-httpcallouts-in-salesforce/

http://richardvanhook.com/2011/04/

 

JitendraJitendra

Hi Pranav,

 

You ant test the SOAP webservice callout. Whenever code encounters the "invoke" method, it stops at that place only.

 

You can try to have more test coverage only by adjusting your logic.

 

In my case, i create separate method which only call the webservice and returns reult. That method is used by other part. In Test Method, manualy create the test data and test remaining code.

lakshman.mattilakshman.matti
HI jitendra,

i'm posted my class and test class in this community.
I'm not getting fake response in test class. can u please tel me how to write fake response for soap webservice callouts.
Please check below link for details


https://developer.salesforce.com/forums/ForumsMain?id=906F0000000B0HwIAK

Regards
Lakshminarayana