3

I have looked at many examples and even some questions asked in stack but I still cannot get my test class to send the Page reference over. When I look at my log, it shows that it enters my controller constructor but returns null on the reference.

Any help would be greatly appreciated.

Thanks

My Visual Force Page: Named testAssetList

 apex:page standardController="Asset" extensions="CheckBox_Class_V2" Tabstyle="Asset" readOnly="false" recordSetVar="Asset">
<!--JavaScript designed to Select All/Deselect All checkboxes at once.-->
<script type = "text/javascript">
        function checkAllBoxes()
        {
            callCheckAllBoxes(); 
        }
</script>  

  <apex:form > 
    <apex:pageBlock Title="Quote Calculator">
<!--Creating Submission and Cancellation buttons here and the bottom of the VisualForce Page-->
        <apex:pageBlockButtons > 
            <apex:commandButton action="{!getSelected}" value="Submit"/>                    
            <apex:commandButton action="{!cancel}" value="Cancel"/>                                  
        </apex:pageBlockButtons>  

My constructor of the controller:

public quoteImprove(ApexPages.StandardSetController stdcontroller)
{
    system.debug('entered constructor');
    entId = ApexPages.currentPage().getParameters().get('id'); 
    System.debug('Constructor entitlement ID is ' + entID);//this returns null when I run my test
    isrendered = true;
    userEndDay='';
    userEndMonth='';
    userEndYear='';
    utility= new QuoteCalcUtil();
    QTC = new QuoteCalculatorVThree();
getAssets();
system.debug('end of constructor');             
} //END OF PUBLIC CHECKBOX_CLASS_V2()

My test Class:

    @isTest

private class TestQuoteCalc {

  static testMethod void testQuoteCalc(){


    Profile p = [select id from profile where name='Standard User'];
    User testUser1 = new User(alias = 'standt', email='[email protected]',emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='America/Los_Angeles', username='[email protected]');    
    Account testAccount1 = TestUtil.initAccount();
    Contact testContact1 = TestUtil.initContact();
    Opportunity newtestOpp1 = TestUtil.initOpportunity(testAccount1,testContact1);
    Entitlement newtestEnt1 = TestUtil.initEntitlement(testAccount1,testUser1, newtestOpp1, testContact1);
    Asset newtestAsset1 = TestUtil.initAsset(testAccount1,newtestOpp1,newtestEnt1);

    String x = newtestEnt1.Id;
System.debug('the ent id is in string form ' + x); //This returns an Id 
    List<Asset> assetList=new List<Asset>();        
    assetList.add(newtestAsset1);     
System.debug('The list size is ' + assetList.size());        
    //ApexPages.StandardSetController cont=newApexPages.StandardSetController(assetList);
   // cont.setSelected(assetList);
    //PageReference acctPage = new ApexPages.StandardController(newtestEnt1).view();
System.debug('Starting test');
    Test.startTest();   
    Test.setCurrentPageReference(page.testAssetList);
    ApexPages.StandardSetController cont=new ApexPages.StandardSetController(assetList);
    //Test.setCurrentPageReference(acctPage);       
    cont.setSelected(assetList);  
    quoteImprove scontroller = new quoteImprove(cont);
    scontroller.userEndDay='12';
    scontroller.userEndMonth='12';
    scontroller.userEndYear='2014';
    scontroller.checkAll();
    scontroller.checkAll();
    scontroller.checkAll();
System.debug('checkAll completed');      
System.debug('The size is ' + scontroller.getAssetWrapper().size());
    try{
        scontroller.getSelected();
    }catch(DMLException d){System.debug(d);}        
    Test.stopTest();
System.debug('Test ended');
  }

}

1 Answer 1

2

It looks like you're trying to set the CurrentPageReference as PageReference acctPage = new ApexPages.StandardController(newtestEnt1).view();. By doing this, you are

Returning the PageReference object of the standard detail page. See here.

Is this the VF page you are really using? If you are building a custom VF page, make sure to use that page before you initialize the controller (which you are doing correctly), set the page reference to your custom VF page.

Ex.

Test.setCurrentPageReference(page.MyCustomVFPage);       
quoteImprove scontroller = new quoteImprove(cont);

or with using URL parameters

string myParameterValue = 'somethingSpecial';
id myObjectId = myObject.id;

Test.setCurrentPageReference('/apex/MyCustomVFPage?customParameter='+myParameterValue+'&id='+myObjectId);       
quoteImprove scontroller = new quoteImprove(cont);    
3
  • Thanks for your help amator, My custom VF page uses the reference of the entitlement.. so would i need to say that the reference of the page.myCustomVFPage is equal to the reference of the entitlement?
    – jnoel10
    Commented Jul 24, 2013 at 15:32
  • What VF page are you using the quoteImprove class as an Extension? That's the page you'll want to use. For reference on pageReferences: salesforce.com/us/developer/docs/apexcode/Content/… Commented Jul 24, 2013 at 17:21
  • I'm still not sure what I am doing wrong, I tried changing my test class to have what you suggested but I still think I am going at it the wrong way. I will post additional info, maybe it will help
    – jnoel10
    Commented Jul 24, 2013 at 18:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .