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
phantom1982phantom1982 

Help in testing this code

Fellas,

 

Got this piece of code that needs to be tested, am aware of unit testing to some extent but still a newbie. Can someone help me write/guide simple test class (called by a visual force page) for the code below, greatly appreciated. :)

 

 

public class PDFMerger
{
    public PDFMerger(ApexPages.StandardController controller) {

    }


    private String getXmlString(pb__InventoryItem__c c, User u)
    {
       datetime todayis = system.now();
       String s = '<?xml version="1.0" encoding="UTF-8"?>' +
           '<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">' +
           '<f href="https://*****.salesforce.com/resource/1295957476000/Work_Assurance_Inspection"/>' +
           '<fields>' +
           '<field name="property address"><value>' + c.Unit_No__c + ' ' + c.Project__c + ' '+ c.Area__c + '</value></field>' + 
           '<field name="agent name"><value>' + u.Name + '</value></field>' + 
            '<field name="Date"><value>' + todayis + '</value></field>' +
            '<field name="Property Type"><value>' + c.pb__UnitType__c + '</value></field>' +
            '<field name="Number of Bedrooms"><value>' + c.pb__UnitBedrooms__c + '</value></field>' +
           '</fields><ids original="E348711A455B6041A503958ABEF555F0" modified="D4A9F66D55B86D47A4F3991DD9F07E18"/>' +
           '</xfdf>';
                    
       return s;
    }
    
  
    public PageReference XFDFInit() 
    {
        pb__InventoryItem__c c = [SELECT Id, Ownerid, Name, pb__UnitType__c, pb__UnitBedrooms__c, Unit_No__c, Project__c, Area__c FROM pb__InventoryItem__c
        WHERE id = :ApexPages.currentPage().getParameters().get('id')];
       
        User u = [SELECT id, Name FROM User
        WHERE id = :c.Ownerid];
        String xmlContent = getXmlString(c, u);
           
        Attachment attachment = new Attachment();
        attachment.Body = Blob.valueOf(xmlContent);
        attachment.Name = c.Name + '.XFDF';
        attachment.ParentId = c.Id;
       
        insert attachment;
                        
        PageReference contactPage = new PageReference('/' + c.id);
        contactPage.setRedirect(true);
        return contactPage;
   } 
Best Answer chosen by Admin (Salesforce Developers) 
danaledanale

HI Phantom,

 

I just ran across your post after having been recently perusing the article Introducing Test Methods. Check it out:

http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods

 

Hope this helps!