0

Hi I am running a test class but one method fail giving:System.TypeException: Collection store exception putting ScenarioDumpJob.args_element into Map

Here is my mock class:

@IsTest
global class mockServiceTest 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){
            if(request instanceof ScenarioDumpJob.args_element){
                ScenarioDumpJob.args_element responseElement = new ScenarioDumpJob.args_element();
                response.put('response_x', responseElement );
            }
            return;
        }
}

And my test Class method that is failing is:

private static testMethod void ScenarioDump2_CopyCoverMethodTest(){
        Test.setMock(WebServiceMock.class, new mockServiceTest());
        String[] item = new String[]{'item','0','-1','false'};
        ScenarioDumpJob.ScenarioDump2_Copy obj = new ScenarioDumpJob.ScenarioDump2_Copy();
        List<String> lst = new List<String>();
        lst=obj.runJob(item);
    }
1
  • 2
    From a quick Google, it seems like the underlying response collection will reject the wrong object type: is ScenarioDumpJob.args_element the right type?
    – Keith C
    Feb 14 '17 at 9:30
2

It is possible that 2 web service methods are being called in your test class. Below is a sample for 2 mock responses based on the method called.

public void doInvoke(
                Object stub,
                Object request,
                Map<String, Object> response,
                String endpoint,
                String soapAction,
                String requestName,
                String responseNS,
                String responseName,
                String responseType) {

    // Create response based on called method
    if(request instanceof DocuSignTK.CreateEnvelope_element){
        DocuSignTK.CreateEnvelopeResponse_element details = new DocuSignTK.CreateEnvelopeResponse_element();

        DocuSignTK.EnvelopeStatus createEnvelopeResult = new DocuSignTK.EnvelopeStatus();
        createEnvelopeResult.Status = 'Success';
        createEnvelopeResult.EnvelopeID = '1';

        details.CreateEnvelopeResult = createEnvelopeResult;

        response.put('response_x', details); 
    }else if(request instanceof DocuSignTK.RequestSenderToken_element){
        DocuSignTK.RequestSenderTokenResponse_element details = new DocuSignTK.RequestSenderTokenResponse_element();
        details.RequestSenderTokenResult = 'testtoken';
        response.put('response_x', details); 
    }
}
1
  • 1
    This is a good suggestion since you could have scenarios like Lead conversion where multiple triggers fire in a single transaction with multiple callouts and you cannot just set one Mock Response. Thanks @GulShan Jul 26 '19 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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