Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am testing a callout to a third party web service as documented here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex_testing.htm

Works great - but I can't see how to test for when the service fails e.g. time out, 400 response. Is there a way to set the mock web service interface to a bad response in the same way I can when I test REST responses?

share|improve this question
    
Have you tried passing in invalid parameters, or parameters you know will make the service return an error? Then test the results under those conditions...? –  jonnybro Mar 19 '13 at 1:09
    
That also works fine - what I am after is the ability to mimic a timeout - so the whole callout fails (and triggers my Try/Catch)... –  BritishBoyinDC Mar 19 '13 at 1:45

1 Answer 1

up vote 2 down vote accepted

WebServiceMock route. I've taken a look at this and while it does appear that while WebServiceMock allows you to emulate nicely the responses using the generated Apex classes for your third party service (very cool actually). It does appear in doing so to abstract away the ability to mimic some of the low level HTTP aspects of the response (unlike HttpCalloutMock i reference below).

Though I cannot help feeling the 'response' parameter map in which you place the 'response_x' key value. May support other entires, unfortunately I cannot find any other documentation on what they might be. Such as 'response_status' would be nice!

response: A collection of key/value pairs representing the response to send for the request.

Trying via HttpCalloutMock route. Sadly the presence of a HttpCalloutMock interface implementation does not satisfy (what are still effectively HTTP callouts) web service callouts made via the generated Apex classes. So while I was able to setup one of these to return status 400, I still got the 'Methods defined as TestMethod do not support Web service callouts, test skipped' error when running my test.

Conclusion: Sorry but it looks like this may not be possible to mock this when your using the WSDL2Apex web service call out style. Unless you want to move to making raw HTTP callouts (handling the XML creation and parsing yourself). Or unless someone from Salesforce dev might want to venture forth what additional values can be placed in the 'response' map when implementing WebServiceMock?

share|improve this answer
    
Thanks - I like to use the WSDL2Apex when they work out the box...in this case, I'll just work with the third party to disable their service briefly, confirm my catch works ok, and accept that as good enough! –  BritishBoyinDC Mar 20 '13 at 2:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.