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
Rajesh Rajesh KumarRajesh Rajesh Kumar 

Test Class for Dom Xml

HI all,
I need to write the test class for DOM XML parser. Could anyone please help me out from this

public class DomNamespaceSample 
{

    public void sendRequest(String Endpoint)
    {
        // Create the request envelope
     
        
        DOM.Document doc = new DOM.Document();
        
         List<Address__c> addr=[SELECT Company__c,Division__c,City__c,PostalCode__c FROM Address__c];
         string str1= addr[0].Company__c;
         string str2=addr[0].Division__c;
         string str3=addr[0].City__c;
         string str4=addr[0].PostalCode__c;
         List<LineItem__c> addr1=[SELECT Product__c,ExtendedPrice__c FROM LineItem__c];
         string str5=addr1[0].Product__c;
         string str6=addr1[0].ExtendedPrice__c;
         string str7=addr1[1].Product__c;
         string str8=addr1[1].ExtendedPrice__c;
        
        

        
        
        VertexAPI__c vertexConfig=VertexAPI__c.getInstance();
        string soapNS=vertexConfig.soapNS__c;
        String user=vertexConfig.UserName__c;
        string pass=vertexConfig.Password__c;
        String xsi =vertexConfig.xsi__c;
        String serviceNS=vertexConfig.serviceNS__c;
        //String soapNS = 'http://schemas.xmlsoap.org/soap/envelope/';
       // String xsi = 'urn:vertexinc:o-series:tps:8:0';
        //String serviceNS = 'http://www.w3.org/2001/XMLSchema-instance';
        
        dom.XmlNode envelope =doc.createRootElement('Envelope', soapNS, 'soapenv');
        envelope.setNamespace('urn', xsi);
        //envelope.setNamespace('xmlns', xsi);
        //envelope.setAttributeNS('urn',xsi, null);
        //envelope.setNamespace('xsi','urn:vertexinc:o-series:tps:8:0');
        
        dom.XmlNode header=envelope.addChildElement('Header', soapNS, 'soapenv');
        
        dom.XmlNode body=envelope.addChildElement('Body', soapNS,  'soapenv');
        Dom.XmlNode vertexEnvelope =body.addChildElement('urn:VertexEnvelope',soapNS,'');
        vertexEnvelope.setAttributeNS('xmlns', soapNS, xsi, null);
        //vertexEnvelope.setAttribute('xmlns',serviceNS);
        //vertexEnvelope.setNamespace('xsi','http://www.w3.org/2001/XMLSchema-instance');
        Dom.XmlNode login=vertexEnvelope.addChildElement('urn:Login', null,null);
        Dom.XmlNode uid=login.addChildElement('urn:UserName',null,null).addTextNode(user);
        Dom.XmlNode pwd=login.addChildElement('urn:Password', null,null).addTextNode(pass);
        Dom.XmlNode invoiceRequest =vertexEnvelope.addChildElement('urn:InvoiceRequest', null, null);
        invoiceRequest.setattribute('documentDate','2019-01-30');
        invoiceRequest.setattribute('transactionType','LEASE');
        
        Dom.XmlNode seller=invoiceRequest.addChildElement('urn:Seller',null,null);
        seller.addChildElement('urn:Company', null, null).addTextNode(str1);  
        seller.addChildElement('urn:Division', null, null).addTextNode(str2);
        
        // start coustomer tag
        Dom.XmlNode customer = invoiceRequest.addChildElement('urn:Customer', null, null);
        //customer.setattribute('isTaxExempt','false');
        Dom.XmlNode destination= customer.addChildElement('urn:Destination',null,null);
        Dom.XmlNode city=destination.addChildElement('urn:City',null,null).addTextNode(str3);
        Dom.XmlNode zipCode=destination.addChildElement('urn:PostalCode',null,null).addTextNode(str4);
        
        // LineItem="1"
        Dom.XmlNode lineitem1=invoiceRequest.addChildElement('urn:LineItem',null,null);
        lineitem1.setattribute('lineItemNumber','1');
        // product tag
        lineItem1.addChildElement('urn:Product',null,null).addTextNode(str5);
        lineItem1.addChildElement('urn:ExtendedPrice',null,null).addTextNode(str6);
        
        // LineItem="2"
        Dom.XmlNode lineitem2=invoiceRequest.addChildElement('urn:LineItem',null,null);
        lineitem2.setattribute('lineItemNumber','2');
        // product tag
        lineItem2.addChildElement('urn:Product',null,null).addTextNode(str7);
        lineItem2.addChildElement('urn:ExtendedPrice',null,null).addTextNode(str8);
        
         System.debug(doc.toXmlString());
        
        
        
        //string strRes=XML;
        //doc.load(strRes);
        //system.debug(strRes);
        //insert 
        
       
        //doc.load(request1);
        //request1.XMLRequest__c=doc.load(doc.toXmlString());
        //insert request1;
       
        
        // Send the request
        HttpRequest req = new HttpRequest();
        req.setMethod('POST');
        req.setEndpoint(Endpoint);
        req.setHeader('Content-Type', 'text/xml');
        req.setBodyDocument(doc);
                
        Http http=new Http();
        HttpResponse res=http.send(req);
        System.assertEquals(200,res.getStatusCode());
        //string str=res.getBody();
        system.debug(res.getBody());
  }