You need to sign in to do that
Don't have an account?
Multiple response for WebServiceMock
How do I set multiple responses for different call outs in this class that implements WebServiceMock?
@isTest
global class PuchaseWSMock_IsTest implements WebServiceMock {
global void doInvoke(Object stub,
Object request,
Map<String, Object> response,
String endpoint,
String soapAction,
String requestName,
String responseNS,
String responseName,
String responseType) {
//set response for web service method 1
PurchaseWS.ProgramInfoResponse responseElement = new PurchaseWS.ProgramInfoResponse();
responseElement.AgreementID = 344;
response.put('response_x', responseElement);
//set response for web service method2?
}
}
Test method:
static testMethod void myTest() {
Test.setMock(WebServiceMock.class, new PurchaseWSMock_IsTest());
Test.startTest();
//call web service method 1
//call web service method 2
Test.startTest();
}
If you go to the last post, you can see how I implemented multiple mock responses. Hopefully this helps you, if not let me know.
@isTest
global class WebServiceGetReferenceMockImpl implements WebServiceMock {
global void doInvoke(
Object stub,
Object request,
Map<String, Object> response,
String endpoint,
String soapAction,
String requestName,
String responseNS,
String responseName,
String responseType) {
System.debug(requestName);
// Method 1
if(requestName == 'method1'){
// code
}
// Method 2
if(requestName == 'method2'){
// code
}
}