Advertisement
Learnify_Rectify

Apex SOAP Callouts

Jun 25th, 2024 (edited)
15,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | Source Code | 0 0
  1. Apex SOAP Callouts from (module - Apex Integration Services)
  2.  
  3.  
  4. Remote Site URL : https://th-apex-soap-service.herokuapp.com
  5. -------------------------------------------------
  6. SOURCE CODE: ParkLocator
  7.  
  8. public class ParkLocator {
  9. public static string[] country(string theCountry) {
  10. ParkService.ParksImplPort parkSvc = new ParkService.ParksImplPort();
  11. return parkSvc.byCountry(theCountry);
  12. } }
  13.  
  14. -------------------------------------------------
  15. SOURCE CODE: ParkLocatorTest
  16. @isTest
  17. private class ParkLocatorTest {
  18. @isTest static void testCallout() {
  19. Test.setMock(WebServiceMock.class, new ParkServiceMock ());
  20. String country = 'United States';
  21. List<String> result = ParkLocator.country(country);
  22. List<String> parks = new List<String>{'Kaziranga National Park', 'Gir National Park', 'Deer Park'};
  23. System.assertEquals(parks, result);
  24. } }
  25.  
  26. -------------------------------------------------
  27. SOURCE CODE: ParkServiceMock
  28. @isTest
  29. global class ParkServiceMock implements WebServiceMock {
  30. global void doInvoke(
  31. Object stub,
  32. Object request,
  33. Map<String, Object> response,
  34. String endpoint,
  35. String soapAction,
  36. String requestName,
  37. String responseNS,
  38. String responseName,
  39. String responseType) {
  40. // start - specify the response you want to send
  41. ParkService.byCountryResponse response_x = new ParkService.byCountryResponse();
  42. response_x.return_x = new List<String>{'Kaziranga National Park', 'Gir National Park', 'Deer Park'};
  43. // end
  44. response.put('response_x', response_x);
  45. } }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement