function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TerminusbotTerminusbot 

Test Class: System.XmlException: Failed to parse XML due to: only whitespace content allowed before start tag??

Hello All. 

I am running into a strange issue when executing a test class on a @future callout. The error message is below. 
 
System.XmlException: Failed to parse XML due to: only whitespace content allowed before start tag and not { (position: START_DOCUMENT seen {... @1:1)

It is failing at 'doc.load(toParse);' which is where I load my XML response into the DOM for reading.  Here is my callout
 
public with sharing class ClientBatchQuery {
	
@future (callout=true)
public static void sendBatchQuery() {    

   	String account;
   	String username;
   	String password;
   	String serverpool;
    //Get Sagitta Info Main Record Data
    List<SagittaInfo__c> sagittaSettings = new List<SagittaInfo__c>([Select Id, Name, account__c, username__c, password__c, serverpool__c, Client_Date__c, Client_GTTIME__c,Client_LTTIME__c, 
                                                                    Client_Sync_Sent__c,Client_Sync_Minutes__c,UniVerse_Time__c,Current_UniVerse_Time__c
                                                                    from SagittaInfo__c where Name = 'MAIN']);
    //Set login credentials for Saggita 
    if (sagittaSettings.size()>0){
     account    = sagittaSettings.get(0).account__c;
     username   = sagittaSettings.get(0).username__c;
     password   = sagittaSettings.get(0).password__c;
     serverpool = sagittaSettings.get(0).serverpool__c;
    }

    // Create XmlStreamWriter  
    XmlStreamWriter writer = new XmlStreamWriter();    
            
    //Build PassThroughReq Soap XML 
        writer.writeStartDocument('utf-8','1.0');  
            writer.writeStartElement(null,'soap12:Envelope',null);
            writer.writeAttribute(null,null,'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
            writer.writeAttribute(null,null,'xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
            writer.writeAttribute(null,null, 'xmlns:soap12', 'http://www.w3.org/2003/05/soap-envelope');
                    
            writer.writeStartElement(null,'soap12:Body', null);
                writer.writeStartElement(null,'PassThroughReq',null);
                writer.writeAttribute(null,null,'xmlns', 'http://amsservices.com/');
                    writer.writeStartElement(null,'XMLinput',null);
                        writer.writeStartElement(null,'INPUT',null);
                                writer.writeStartElement(null,'Account',null);
                			    writer.writeAttribute(null,null,'value', account);
                                writer.writeEndElement(); // Account Close
                			    writer.writeStartElement(null,'Username',null);
                			    writer.writeAttribute(null,null,'value', username);
                                writer.writeEndElement(); // Username Close
    						    writer.writeStartElement(null,'Password',null);
                			    writer.writeAttribute(null,null,'value', password);
                                writer.writeEndElement(); // Password Close
                			    writer.writeStartElement(null,'Serverpool',null);
                			    writer.writeAttribute(null,null,'value', serverpool);
                                writer.writeEndElement(); // Serverpool Close
                                writer.writeStartElement(null,'Access',null);
                                writer.writeAttribute(null,null,'statement', 'LIST CLIENTS WITH AUDIT.DATE.TIME GT \\'+ String.valueOf(sagittaSettings.get(0).UniVerse_Time__c) +'\\ *OUTPUT* CLIENT.CODE CAT.CODE.1 CLIENT.NAME ADDR1 ADDR2 CITY STATE ZIP.CODE PRIME.PROD PRIME.SERVICER.NAME PHONE1 PHONE2 EMAIL.ADDRESS');
                                writer.writeEndElement(); // Access Close
                        writer.writeEndElement(); // INPUT Close
                        writer.writeEndElement(); // XMLinput Close
                    writer.writeEndElement(); // PassThroughReq Close
                writer.writeEndElement(); // Soap Body Close
            writer.writeEndElement(); // Envelope Body Close    
            
    // Write XML to String Variable
    string xml = writer.getXmlString();
    System.debug('XML OUTPUT' + xml);      
    //End XmlStreamWriter 
    writer.close();
    
    // Create instance of HttpRequest, HttpResponse, and Http. Preparing to send to XML to Saggita
    HttpRequest req = new HttpRequest();
    HttpResponse res = new HttpResponse();
    Http http = new Http();
            
    // Set Method, Endpoint, Header, and Body details for SOAP request. 
    req.setMethod('POST');
    req.setEndpoint('http://167.206.227.210/sagittaws/transporter.asmx');
    req.setHeader('Content-Type', 'text/xml');
    req.setHeader('SOAPAction','http://amsservices.com/PassThroughReq');
    req.setBody(xml);
                       
    //Execute Callout 
    try {        
        res = http.send(req);
    }   catch (System.CalloutException e) {
        System.debug('Callout error: '+ e);
        System.debug('Response to String' + res.toString());
    }           
        
    // Creating XMLStreamReader to read the response - Looking for SagittaID and Sagitta Client Code        
    // Clean XMl response from Sagitta - Call cleanXML method  
    String bodyXMLFinal = XMLCleaner.cleanXML(res.getBody());
            
        
    

    //Create List of all Policy Records and Attributes to Update and Insert 
    List<Account> clientUpsert = new List<Account>();
        
    String toParse = bodyXMLFinal;
    String fileAttrValue; 
    String itemAttribute;
    
    //Create DOM to read XML response 
    DOM.Document doc = new DOM.Document();
    doc.load(toParse);
    
    //Get Root 
    DOM.XMLNode root = doc.getRootElement();
    String nms = root.getNameSpace();
    System.Debug('namespace: ' + nms); // http://www.w3.org/2003/05/soap-envelope

        DOM.XMLNode body = root.getChildElement('Body', nms); // Gets the body of the XML 
        System.Debug('body: ' + body); 
        List<DOM.XMLNode> bodyChildrenList = body.getChildElements();

            for (DOM.XMLNode passThroughReqResponse : bodyChildrenList) {
            System.Debug('passThroughReqResponse: ' + passThroughReqResponse.getName());
            List<DOM.XMLNode> passThroughReqResultList = passThroughReqResponse.getChildElements();

                for (DOM.XMLNode passThroughReqResult : passThroughReqResultList) {
                System.Debug('passThroughReqResult: ' + passThroughReqResult.getName());
                List<DOM.XMLNode> pickResponseList = passThroughReqResult.getChildElements();

                    for (DOM.XMLNode pickResponse : pickResponseList) {
                    System.Debug('pickResponse: ' + pickResponse.getName());
                    List<DOM.XMLNode> filesList = pickResponse.getChildElements();
                                
                        for (DOM.XMLNode files : filesList) {
                        System.Debug('files: ' + files.getName());
                        List<DOM.XMLNode> fileList = files.getChildElements();
                                   
                            for (DOM.XMLNode file : fileList) {
                            System.Debug('file: ' + file.getName());
                            List<DOM.XMLNode> itemList = file.getChildElements();
                     
                                for (DOM.XMLNode item : itemList) {
                                System.Debug('item: ' + item.getName());
                                itemAttribute = item.getAttributeValue('sagitem', null);
                                System.Debug('item attribute sagitem: ' + itemAttribute);
                                Account accountDetails = new Account();

                                    if (!itemAttribute.startsWith('WEBSERVICE')) {
                                    System.debug('Item is not WEBSERVICE' + itemAttribute + ' Entering Data');
                                    System.debug ('Updated Policy Details: ' + accountDetails);
                                    System.debug('Running query on : ' + itemAttribute);
                                    List<Account> lookUpID = new List<Account> ([Select Id from Account where SagittaID__c =:itemAttribute]);
                                    System.debug('Results for queory on : ' + itemAttribute + ': ' + lookUpID);
                                    
                                        if (!lookupId.isEmpty()) {
                                        System.debug('ID IS NOT EMPTY: ' + lookupID);
                                        accountDetails.Id = string.valueOf(lookupID.get(0).Id);
                                        System.debug('Adding ID to Policy Object: ' + lookupID);
                                        System.debug ('Updated Policy Details: ' + accountDetails);
                                        }
                                        accountDetails.SagittaId__c = itemAttribute;
                                        List<DOM.XMLNode> aList = item.getChildElements();
                                       
                                            for (DOM.XMLNode a : aList) {
                                            String aPosition = a.getName();
                                            String aText = a.getText();
                                            System.Debug('a: ' + aPosition);
                                            System.Debug('text: ' + aText);
                                                
                                                if (aPosition != null && aPosition == 'a1') {
                                                	//Client Code
                                                	accountDetails.Client_Code__c = aText;
                                                	accountDetails.Preferred_Method_of_Contact__c = 'Email';
                                                }

                                                if (aPosition != null && aPosition == 'a2') {
                                                    //Category Code 
                                                    String catCode;
                                                    if (aText == 'COM') {
                                                    	catCode = 'Business';
                                                    } else {
                                                    	catCode = 'Individual';
                                                    }
                                                   
                                                    List<recordtype> recTypeId = new List<recordtype>([Select Id from recordtype where Name=:catCode]);
                                                    accountDetails.recordtypeid = recTypeId.get(0).Id;
                                                    System.debug('Adding Category Code to Account Object: ' + aText);
                                                    System.debug ('Updated Account Details: ' + accountDetails);
                                                }
                                                
                                                if (aPosition != null && aPosition == 'a3') {
                                                    //Account Name
                                                    accountDetails.Name = aText;
                                                    System.debug('Adding Account Name to Account Object: ' + aText);
                                                    System.debug ('Updated Account Details: ' + accountDetails);
                                                }
                                                
                                                if (aPosition != null && aPosition == 'a4') {
                                                    //Address 1
                                                    accountDetails.BillingStreet = aText;
                                                    System.debug('Adding Address 1 to Account Object: ' + aText);
                                                    System.debug ('Updated Account Details: ' + accountDetails);
                                                }
                                                
                                                if (aPosition != null && aPosition == 'a5') {
                                                    //Address 2
                                                    //
                                                    //System.debug('Adding Coverages to Policy Object: ' + aText);
                                                    //System.debug ('Updated Policy Details: ' + accountDetails);
                                                }
                                                
                                                if (aPosition != null && aPosition == 'a6') {
                                                    //City
                                                    accountDetails.BillingCity = aText;
                                                    System.debug('Adding City to Account Object: ' + aText);
                                                    System.debug ('Updated Account Details: ' + accountDetails);
                                                }
                                                
                                                if (aPosition != null && aPosition == 'a7') {
                                                    //State
                                                    accountDetails.BillingState = aText;
                                                    System.debug('Adding State to Account Object: ' + aText);
                                                    System.debug ('Updated Account Details: ' + accountDetails);
                                                }
                                                
                                                if (aPosition != null && aPosition == 'a8') {
                                                    //ZipCode
                                                    accountDetails.BillingPostalCode = aText;
                                                    System.debug('Adding Zip Code to Account Object: ' + aText);
                                                    System.debug ('Updated Account Details: ' + accountDetails);
                                                }
                                                
                                                if (aPosition != null && aPosition == 'a9') {
                                                    //Producer Code 
                                                    String prodCode = aText;
                                                    List<User> producerCode = [Select Id From User where Sagitta_User_Code__c =:prodCode ];
      												accountDetails.OwnerId = string.valueOf(producerCode[0].Id);
                                                    System.debug('Adding Producer Code to Account Object: ' + aText);
                                                    System.debug ('Updated Account Details: ' + accountDetails);
                                                }
                                                
                                                if (aPosition != null && aPosition == 'a10') {
                                                    //Account Executive 
                                                    accountDetails.Account_Exec__c = aText;
                                                    System.debug('Adding Account Exec to Account Object: ' + aText);
                                                    System.debug ('Updated Account Details: ' + accountDetails);
                                                }
                                                
                                                if (aPosition != null && aPosition == 'a11') {
                                                    //Phone1
                                                    accountDetails.Phone = aText;
                                                    System.debug('Adding Phone to Account Object: ' + aText);
                                                    System.debug ('Updated Account Details: ' + accountDetails);
                                                }
                                                
                                                if (aPosition != null && aPosition == 'a12') {
                                                    //Phone2
                                                    accountDetails.Phone_2__c = aText;
                                                    System.debug('Adding Phone 2 to Account Object: ' + aText);
                                                    System.debug ('Updated Account Details: ' + accountDetails);
                                                }
                                                
                                                if (aPosition != null && aPosition == 'a13') {
                                                    //Email 
                                                    
                                                    accountDetails.Email__c = aText;
                                                    System.debug('Adding Status to Account Object: ' + aText);
                                                    System.debug ('Updated Account Details: ' + accountDetails);
                                                }

                                                //End of A# lists
                                                 
                                            } // End For aList 
                                             
                                    } //If Sagitta ID Exists    
                                        System.debug('Does Account` Details Exist?' + accountDetails);
                                            if (accountDetails.Name != null) {
                                                System.debug('Yes, add to clientUpsert List' + accountDetails);
                                                System.debug('Account Upsert List Before Add' + clientUpsert);
                                                clientUpsert.add(accountDetails);
                                                System.debug('Account Upsert List After Add' + clientUpsert);
                                            }    
                                
                                } //item 
                            } // file
                        } //files
                    } //pickResponse
                } //passThroughReqResult
            } //passThroughReqResponse

    try {
    System.debug('Upsert These Records' + clientUpsert);
    upsert clientUpsert;
	} catch(DmlException e) {
    System.debug('The following exception has occurred during Upsert: ' + e.getMessage());
	}
	System.debug('Succesfully Upserted the Following.' + clientUpsert);
    
    //Update Latest Request Date, GTTIME, LTTIME for next Policy Delta Sync 
    SagittaInfo__c sagInfo = new SagittaInfo__c();
        sagInfo.Id                  = sagittaSettings.get(0).Id;
        sagInfo.Client_Sync_Sent__c = false;
        update sagInfo; 

            
    } 

}


Has anyone run into this before? Did some searching around the forums and saw the use of Test.isRunning() but not sure I want to exclude portions of my class when testing. 
 

Thanks as always! 

Best Answer chosen by Terminusbot
UC InnovationUC Innovation
I see.  It makes sense now.  You also need to add the <soap:Envelope> tag as well before the <soap:Body> in your MockClientQueryResponse  class:
 
res.setBody('<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> <soap:Body> <PassThroughReqResponse xmlns=\"http://amsservices.com/\"> <PassThroughReqResult> <PickResponse> <Files> <File sagfile=\"WORK.7864470\"> <Item sagitem=\"WEBSERVICE.TAGS*WORK.7864470\"> <a1>POLICY.NUMBER</a1> <a2>CLIENT.CODE</a2> <a3>EFF.DATE</a3> <a4>EXP.DATE</a4> <a5>COV</a5> <a6>INS</a6> <a7>TERM</a7> <a8>POLICY.STATUS</a8> <a9>BILLING.METHOD</a9> <a10>31</a10> <a11>32</a11> <a12>33</a12> <a13>POLICY.STATUS</a13> <a14>NEW.REN</a14> <a15>CHG.TIME</a15> </Item> </File> <File sagfile=\"WORK.7864470\"> <Item sagitem=\"579615\"> <a1>TESTINGNEW</a1> <a2>ZIMJO1</a2> <a3>08/08/16</a3> <a4>08/08/17</a4> <a5>ARA</a5> <a6>CER</a6> <a7>A</a7> <a9>Agency Bill</a9> <a14>NEW</a14> <a15>12:06:46</a15> </Item> </File> </Files> </PickResponse></PassThroughReqResult> </PassThroughReqResponse> </soap:Body> </soap:Envelope>');

Once you do that, the error you are seeing should go away.  But now, you'll have to update your Assert statements.

Hope that helps!

All Answers

UC InnovationUC Innovation
What is the actual value of bodyXMLFinal?
TerminusbotTerminusbot
Here is an example of the bodyXMLFinal
 
<?xml version="1.0" encoding="utf-8"?><soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:Body><PassThroughReq xmlns="http://amsservices.com/"><XMLinput><INPUT><Account value="gemdata"></Account><Username value="wksmt"></Username><Password value="adminwk"></Password><Serverpool value="websvc"></Serverpool><Access statement="LIST CLIENTS WITH AUDIT.DATE.TIME GT \1776953102\ *OUTPUT* CLIENT.CODE CAT.CODE.1 CLIENT.NAME ADDR1 ADDR2 CITY STATE ZIP.CODE PRIME.PROD PRIME.SERVICER.NAME PHONE1 PHONE2 EMAIL.ADDRESS"></Access></INPUT></XMLinput></PassThroughReq></soap12:Body></soap12:Envelope>

 
UC InnovationUC Innovation
I think the issue is in the following text:

"\1776953102\"

Backslashes have special meanings in strings, so you'll need to escape the backslashes (ie, replace each "\" with "\\"):

"\\1776953102\\"

Code would be something like:
 
bodyXMLFinal = bodyXMLFinal.replace('\\', '\\\\');

 
TerminusbotTerminusbot
I made a mistake and pasted the wrong response. That was my request. 

Here is my response:
 
'<?xml version=\"1.0\" encoding=\"utf-8\"?> <soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> <soap:Body> <PassThroughReqResponse xmlns=\"http://amsservices.com/\"> <PassThroughReqResult> <PickResponse> <Files> <File sagfile=\"WORK.7864470\"> <Item sagitem=\"WEBSERVICE.TAGS*WORK.7864470\"> <a1>POLICY.NUMBER</a1> <a2>CLIENT.CODE</a2> <a3>EFF.DATE</a3> <a4>EXP.DATE</a4> <a5>COV</a5> <a6>INS</a6> <a7>TERM</a7> <a8>POLICY.STATUS</a8> <a9>BILLING.METHOD</a9> <a10>31</a10> <a11>32</a11> <a12>33</a12> <a13>POLICY.STATUS</a13> <a14>NEW.REN</a14> <a15>CHG.TIME</a15> </Item> </File> <File sagfile=\"WORK.7864470\"> <Item sagitem=\"579615\"> <a1>TESTINGNEW</a1> <a2>ZIMJO1</a2> <a3>08/08/16</a3> <a4>08/08/17</a4> <a5>ARA</a5> <a6>CER</a6> <a7>A</a7> <a9>Agency Bill</a9> <a14>NEW</a14> <a15>12:06:46</a15> </Item> </File> </Files> </PickResponse></PassThroughReqResult> </PassThroughReqResponse> </soap:Body> </soap:Envelope>'

 
UC InnovationUC Innovation
Hmmm...  That worked for me.  It didn't give me any errors:
 
String bodyXMLFinal  = '<?xml version=\"1.0\" encoding=\"utf-8\"?> <soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> <soap:Body> <PassThroughReqResponse xmlns=\"http://amsservices.com/\"> <PassThroughReqResult> <PickResponse> <Files> <File sagfile=\"WORK.7864470\"> <Item sagitem=\"WEBSERVICE.TAGS*WORK.7864470\"> <a1>POLICY.NUMBER</a1> <a2>CLIENT.CODE</a2> <a3>EFF.DATE</a3> <a4>EXP.DATE</a4> <a5>COV</a5> <a6>INS</a6> <a7>TERM</a7> <a8>POLICY.STATUS</a8> <a9>BILLING.METHOD</a9> <a10>31</a10> <a11>32</a11> <a12>33</a12> <a13>POLICY.STATUS</a13> <a14>NEW.REN</a14> <a15>CHG.TIME</a15> </Item> </File> <File sagfile=\"WORK.7864470\"> <Item sagitem=\"579615\"> <a1>TESTINGNEW</a1> <a2>ZIMJO1</a2> <a3>08/08/16</a3> <a4>08/08/17</a4> <a5>ARA</a5> <a6>CER</a6> <a7>A</a7> <a9>Agency Bill</a9> <a14>NEW</a14> <a15>12:06:46</a15> </Item> </File> </Files> </PickResponse></PassThroughReqResult> </PassThroughReqResponse> </soap:Body> </soap:Envelope>';

DOM.Document doc = new DOM.Document();
String toParse = bodyXMLFinal ;
doc.load(toParse);

DOM.XMLNode root = doc.getRootElement();
String nms = root.getNameSpace();
System.Debug('namespace: ' + nms);

DOM.XMLNode body = root.getChildElement('Body', nms);
System.Debug('body: ' + body);

Was this the response that gave you the error, or are there other responses?
TerminusbotTerminusbot
I am getting this error when running a test class that fires my callout. 
Here is my test class and mock:

Mock:
 
@isTest
global class MockClientQueryResponse implements HttpCalloutMock {
    // Implement this interface method
    global HTTPResponse respond(HTTPRequest req) {
        // Optionally, only send a mock response for a specific endpoint
        // and method.
        System.assertEquals('http://167.206.227.210/sagittaws/transporter.asmx', req.getEndpoint());
        System.assertEquals('POST', req.getMethod());
        
        // Create a fake response
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'text/xml');
        res.setBody('<soap:Body> <PassThroughReqResponse xmlns=\"http://amsservices.com/\"> <PassThroughReqResult> <PickResponse> <Files> <File sagfile=\"WORK.7864470\"> <Item sagitem=\"WEBSERVICE.TAGS*WORK.7864470\"> <a1>POLICY.NUMBER</a1> <a2>CLIENT.CODE</a2> <a3>EFF.DATE</a3> <a4>EXP.DATE</a4> <a5>COV</a5> <a6>INS</a6> <a7>TERM</a7> <a8>POLICY.STATUS</a8> <a9>BILLING.METHOD</a9> <a10>31</a10> <a11>32</a11> <a12>33</a12> <a13>POLICY.STATUS</a13> <a14>NEW.REN</a14> <a15>CHG.TIME</a15> </Item> </File> <File sagfile=\"WORK.7864470\"> <Item sagitem=\"579615\"> <a1>TESTINGNEW</a1> <a2>ZIMJO1</a2> <a3>08/08/16</a3> <a4>08/08/17</a4> <a5>ARA</a5> <a6>CER</a6> <a7>A</a7> <a9>Agency Bill</a9> <a14>NEW</a14> <a15>12:06:46</a15> </Item> </File> </Files> </PickResponse></PassThroughReqResult> </PassThroughReqResponse> </soap:Body>');
        //res.setBody('{"foo":"bar"}');
        res.setStatusCode(200);
        return res;
    }
}

Test Class:
 
@isTest
public class TestClientQueryCallout {



     @isTest (SeeAllData=true)
     static void testCallout() {
     
        
        // Set mock callout class 
        Test.setMock(HttpCalloutMock.class, new MockClientQueryResponse());
        
        // Call method to test.
        // This causes a fake response to be sent
        // from the class that implements HttpCalloutMock. 
        Test.startTest();
        ClientBatchQuery.sendBatchQuery();
        Test.stopTest();
        HttpRequest req = new HttpRequest();
        MockClientQueryResponse mock = new MockClientQueryResponse();
        HttpResponse res = mock.respond(req);
        // Verify response received contains fake values
        String contentType = res.getHeader('Content-Type');
        System.assert(contentType == 'text/xml');
        String actualValue = res.getBody();
        String expectedValue = '<soap:Body> <PassThroughReqResponse xmlns=\"http://amsservices.com/\"> <PassThroughReqResult> <PickResponse> <Files> <File sagfile=\"WORK.7864470\"> <Item sagitem=\"WEBSERVICE.TAGS*WORK.7864470\"> <a1>POLICY.NUMBER</a1> <a2>CLIENT.CODE</a2> <a3>EFF.DATE</a3> <a4>EXP.DATE</a4> <a5>COV</a5> <a6>INS</a6> <a7>TERM</a7> <a8>POLICY.STATUS</a8> <a9>BILLING.METHOD</a9> <a10>31</a10> <a11>32</a11> <a12>33</a12> <a13>POLICY.STATUS</a13> <a14>NEW.REN</a14> <a15>CHG.TIME</a15> </Item> </File> <File sagfile=\"WORK.7864470\"> <Item sagitem=\"579615\"> <a1>TESTINGNEW</a1> <a2>ZIMJO1</a2> <a3>08/08/16</a3> <a4>08/08/17</a4> <a5>ARA</a5> <a6>CER</a6> <a7>A</a7> <a9>Agency Bill</a9> <a14>NEW</a14> <a15>12:06:46</a15> </Item> </File> </Files> </PickResponse></PassThroughReqResult> </PassThroughReqResponse> </soap:Body>';
        System.assertEquals(actualValue, expectedValue);
        System.assertEquals(200, res.getStatusCode());
    }
}

 
UC InnovationUC Innovation
I see.  It makes sense now.  You also need to add the <soap:Envelope> tag as well before the <soap:Body> in your MockClientQueryResponse  class:
 
res.setBody('<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> <soap:Body> <PassThroughReqResponse xmlns=\"http://amsservices.com/\"> <PassThroughReqResult> <PickResponse> <Files> <File sagfile=\"WORK.7864470\"> <Item sagitem=\"WEBSERVICE.TAGS*WORK.7864470\"> <a1>POLICY.NUMBER</a1> <a2>CLIENT.CODE</a2> <a3>EFF.DATE</a3> <a4>EXP.DATE</a4> <a5>COV</a5> <a6>INS</a6> <a7>TERM</a7> <a8>POLICY.STATUS</a8> <a9>BILLING.METHOD</a9> <a10>31</a10> <a11>32</a11> <a12>33</a12> <a13>POLICY.STATUS</a13> <a14>NEW.REN</a14> <a15>CHG.TIME</a15> </Item> </File> <File sagfile=\"WORK.7864470\"> <Item sagitem=\"579615\"> <a1>TESTINGNEW</a1> <a2>ZIMJO1</a2> <a3>08/08/16</a3> <a4>08/08/17</a4> <a5>ARA</a5> <a6>CER</a6> <a7>A</a7> <a9>Agency Bill</a9> <a14>NEW</a14> <a15>12:06:46</a15> </Item> </File> </Files> </PickResponse></PassThroughReqResult> </PassThroughReqResponse> </soap:Body> </soap:Envelope>');

Once you do that, the error you are seeing should go away.  But now, you'll have to update your Assert statements.

Hope that helps!
This was selected as the best answer
TerminusbotTerminusbot
Boom, thank you. That worked. 
TerminusbotTerminusbot
Quick question. What do I need to update my Assets to? I am getting this error now. 

System.AssertException: Assertion Failed: Expected: http://167.206.227.210/sagittaws/transporter.asmx, Actual: null

 
UC InnovationUC Innovation
I think you'll need to update the System.Assert() methods in a couple of places.  First, in your MockClientQueryResponse class, you have:

System.assertEquals('http://167.206.227.210/sagittaws/transporter.asmx', req.getEndpoint());

However, in your test class, you have the following code:

HttpRequest req = new HttpRequest();
MockClientQueryResponse mock = new MockClientQueryResponse();
HttpResponse res = mock.respond(req);

As you can see, the endpoint was never set when respond() is called, so the assert will fail.

The other place you need to update is the below in your test class:

System.assertEquals(actualValue, expectedValue);

You need to change the expectedValue to match the response body in the MockClientQueryResponse class (ie, incude the <soap:Envelope> tag).

Those are th two places that I noticed.
 
TerminusbotTerminusbot
Thank you