You need to sign in to do that
Don't have an account?
MTBRider
Collection store exception
I have a web service callout that is workign fine, but I cannot get the tests working for it. The ws has two methods; init() and sync(). init() returns a String ans sync() returns List<String>
When I try to mock the response for the two WS methods in my test method, I get a an error:
Collection store exception putting myWS.syncResponse_element into MAP<String,myWS.initResponse_element>
So, it is trying to put one methods response into the response map of the other method.
The WebServiceMock class looks like this:
I also tried structuring it with multiple mock response classes, one for each type of response, but I still get the Collection Store exception.
Thanks for your help.
When I try to mock the response for the two WS methods in my test method, I get a an error:
Collection store exception putting myWS.syncResponse_element into MAP<String,myWS.initResponse_element>
So, it is trying to put one methods response into the response map of the other method.
The WebServiceMock class looks like this:
@isTest public class myWSMock implements WebServiceMock { public void doInvoke(Object stub, Object request, Map<String, Object> response, String endpoint, String soapAction, String requestName, String responseNS, String responseName, String responseType) { myWS.initResponse_element r1 = new myWS.initResponse_element(); myWS.syncResponse_element r2 = new myWS.syncResponse_element(); r1.initReturn = 'response1'; r2.syncReturn = new List<String>{'response2'}; response.put('response_x', r1); response.put('response_x', r2); } }
I also tried structuring it with multiple mock response classes, one for each type of response, but I still get the Collection Store exception.
Thanks for your help.
I have a feeling that because you are putting in an item r1 that is not a geenric object buut rather a specific class inheriting the object type that it is casting the map to be of type <String, myWS.initResponse_element>. Note as well how I have updated line 19 as it seemed you were opverwriting the item you had just placed on the map.
It seems as though there is a bug in the built in WebServiceMock class as no matter what I do the stack trace shows that it crashes when trying to initialize the response of one of the methods in the wsdl generate ws class. This happens even when I create two seperate mock web service response classes and then only call one of them in my test class.
It also seems unlikely that there could be a bug in this as I am sure there are many implementations of webservices within Salesforce that implement multiple methods that return different object types.
I keep going back to the fact that the generated ws class is labeling both of webservice methods returns as 'response_x', but as I said in my original post, the actual web service is working fine. So obviously that is not an issue for the ws to function. I would hate to have to go in a start making major changes to the generated WS class now just to get the test to run.
Any other ideas?
Anyone else come across this?
Thanks
Here is the test:
As I said, I also tried breaking out the Mock responses into individual classes like so:
Modifying the test to only call one of the above mock response class gives me the same exception.
I simplified the actual web service method names, so hopefully I did not make any typos.
Thanks again for your help.
Just looking briefly at your code, you're using the same key when you put the diffferent classes into the map.
Note how they are both 'response_x'.
Did you try using different keys, as pbattinson suggested? Could be that the map gets into some weird state where it expects the same type when you put a value into the map with the same key.
Also, what happens if you just take out the r1 class? Do you still get an error then?
Lastly, have you tried casting both of the classes to the generic object type when you initialize them? Something like below? (Doubt it would work, but worth a shot)
http://salesforce.stackexchange.com/questions/40031/how-to-mock-metadataservice-cls-responses-in-testmethods-collection-store-exce