You need to sign in to do that
Don't have an account?
MTBRider
Re-Posting - Collection Store Exception
Sorry for re-posting this but I am stuck on this and will not be able to deploy unless I get t fixed...
I am getting a Collection Store Exception using WebServiceMock in my test. Here is my original post...
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AhHlIAK
Since the last post on the above discussion, I have tried upgrading all classes involved including the test classes to API ver 31.0, changing the response_x map label on one of the web services methods in the wsdl generated class to response_y so that the two web service method responses do not reference the same response map label.
No matter what I change, I always get the same exception using WebServiceMock. I must be missing something. Anyone?
I am getting a Collection Store Exception using WebServiceMock in my test. Here is my original post...
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AhHlIAK
Since the last post on the above discussion, I have tried upgrading all classes involved including the test classes to API ver 31.0, changing the response_x map label on one of the web services methods in the wsdl generated class to response_y so that the two web service method responses do not reference the same response map label.
No matter what I change, I always get the same exception using WebServiceMock. I must be missing something. Anyone?
Step 1:
The class that calls the method of the stub to invoke the webserice. - No change - same as posted above by me.
Step 2:
Implement the Mock interface like this in a class. Change is that the previous two classes has been merged into one class.
Step 3:
A test class that calls these two methods and receives the responses accordingly. Change is that now instead of two separate methods only one test method will do the job.
Now both the callouts take place in a single transaction. And give back the responses conditionally. Sorry for posting such huge pieces of code. The scenario was interesting.
Please let me know if this helps.
Thanks,
Kaustav
All Answers
That will help us to get a look at the request and response element. In the mock interface implementation i think you will have to replicate that.
Thanks,
Kaustav
As I said in my original post, I simplied many of the names. In the below code, the original names are still there. Thanks for our help.
Your processSFChanges method has a response_x variable of type "SFLMBridgeWS.initResponse_element"
Your Mock Callout class puts two instances of different classes into the "response_x" key of your response map. One instance is of type "initResponse_element" and one is of type "syncResponse". It's likely throwing an exception around line 137 above, becuase it can't cast from a syncResponse to an initResponse.
You'll likely need to break out your sync and init responses into separate mock callouts, or provide a mechanism, where you can pass in an array of responses, and then have your mock callout send the right one back based on either the number of callouts made in your unit test or based on a parameter in the request or something.
As an example, I had to implement a mock callout for a method that sent two callouts so here's how I handled it:
First I created a stub from the above code -
Had to comment out the custom settings part.
Step 2: Created a class that does a callout
Step 3: I created a class that implements the mock web service interface
Step 4: Created a test class that executes the method
This executed fine. For your other method that has a web service call out invoke please implement the interface and create a similar fake response.
Please let us know if this works.
Thanks,
Kaustav
Kaustav, I believe you are not getting this exception in your dev org because your class that is making the call out is only calling one of the ws methods. If you call both the .init() and the .processSFChanges() you will get the same exception. If you don't, then let me know! In my environment, if I comment out the .Init() call in my callout method and only call .processSFChanges(), I do not get the exception either.
James, I already tried to break up the mock responses into different classes:
Then in my test class:
I don't believe the problem is in the mock response classes I created. I think the problem may be an issue with WebServiceMock class that they implement.
Even if I call only one of the mock response classes in my test I will get that same exception...
If I call only the SFLMBridgeInitMock() class in my test I will get:
Collection store exception putting SFLMBridgeWS.initResponse_element into MAP<String,SFLMBridgeWS.processSFChangesResponse_element>
On line 125 of the above class generated from the wsdl.
If I call only the SFLMBridgeDoSyncMock() class in my test I will get:
Collection store exception putting SFLMBridgeWS.processSFChangesResponse_element into MAP<String,SFLMBridgeWS.initResponse_element>
on line 86 of the above class generated from the wsdl.
So I think the problem stems from the fact that my @future callout method is calling both of the ws methods. This works fine when making the real callouts and responses, but for the mock callouts and responses, it looks like WebServiceMock is not able to handle the two different response types when trying to override the real callout responses.
Class that makes the call outs:
Mock Response for first callout:
Mock response for second callout:
Test class to execute the two tests:
Ley me know if this helps. I have broken up the calls and their responses in separate test and theat seems to work.
Thanks,
Kaustav
Step 1:
The class that calls the method of the stub to invoke the webserice. - No change - same as posted above by me.
Step 2:
Implement the Mock interface like this in a class. Change is that the previous two classes has been merged into one class.
Step 3:
A test class that calls these two methods and receives the responses accordingly. Change is that now instead of two separate methods only one test method will do the job.
Now both the callouts take place in a single transaction. And give back the responses conditionally. Sorry for posting such huge pieces of code. The scenario was interesting.
Please let me know if this helps.
Thanks,
Kaustav
Based on your last response, which was something that James also suggested in his post, I went back and modified my mock response class so that it had a "switch" that would set one reponse or the other based on how many times the mock response's doInvoke method was called. Here is the code:
The way the web service is implemented, the init ws method is only called once to login to the ws, then processSFChanges can be called multiple times depending on what changes there are to process. So, once I mock up the init response the first time, I am only needing the processResp until I re-instaniate the mock response class again.
The relevent parts of the test method now look like this:
Thanks for you help James and Kaustav!
I wish I could give both of you the Best Answer designation, but I don't think I can....