Activity › Forums › Salesforce® Discussions › How to specify multiple responses in SOAP callout?
-
How to specify multiple responses in SOAP callout?
Posted by sushant on February 13, 2017 at 2:12 PMHi All,
How to specify multiple responses in SOAP callout?
Thanks
Vikas Kumar replied 9 years, 3 months ago 2 Members · 1 Reply -
1 Reply
-
Hi sushant,
You could create a constructor for example:
@isTest
global class PuchaseWSMock_IsTest implements WebServiceMock {public String type;
global PuchaseWSMock_IsTest(final String type){
this.type = type;
}global void doInvoke(Object stub,
Object request,
Map<String, Object> response,
String endpoint,
String soapAction,
String requestName,
String responseNS,
String responseName,
String responseType) {if(type == ‘A’){
//set response for web service method 1
PurchaseWS.ProgramInfoResponse responseElementA = new PurchaseWS.ProgramInfoResponse();
responseElement.AgreementID = 344;
response.put(‘response_x’, responseElementA);
}
//set response for web service method2?
if(type == ‘B’){
//set response for web service method 2
PurchaseWS.ProgramInfoResponse responseElementB = new PurchaseWS.ProgramInfoResponse();
responseElement.AgreementID = 100;
response.put(‘response_x’, responseElementB);
}
}
}Test method:
static testMethod void myTestA() {
Test.setMock(WebServiceMock.class, new PurchaseWSMock_IsTest(‘A’));Test.startTest();
//call web service method 1
Test.startTest();
}static testMethod void myTestB() {
Test.setMock(WebServiceMock.class, new PurchaseWSMock_IsTest(‘B’));Test.startTest();
//call web service method 2
Test.startTest();
}
Log In to reply.