You need to sign in to do that
Don't have an account?
Martin Chalot 15
Testing Multiple Webservice Callout in a single Transaction
Hello,
I'm trying to understand how can I test multiple webservice callout from a single transation. My transaction work like this :
- Step 1 : I call Web Service A. I get an ID from this Webservice
- Step 2 : From the Id I got from the webservice I call Webservice B
- Then I make some operations...
So far the only way to distinguish where the webservice is from is by making a condition on the endpoint :
I'm trying to understand how can I test multiple webservice callout from a single transation. My transaction work like this :
- Step 1 : I call Web Service A. I get an ID from this Webservice
- Step 2 : From the Id I got from the webservice I call Webservice B
- Then I make some operations...
So far the only way to distinguish where the webservice is from is by making a condition on the endpoint :
global class ExpertiseMock implements HttpCalloutMock { global HTTPResponse respond(HTTPRequest req) { String content = null; String endpoint = req.getEndpoint(); HttpResponse res = new HttpResponse(); if(endpoint.startsWith('**********************************')) { res.setBody(ReponseA); } else { res.setBody(ReponseB); } res.setHeader('Content-Type', 'application/json'); res.setStatusCode(200); return res; } }
But I think it's not very clean. Is there another way ?
Thanks,
Regards,
Martin