+ Start a Discussion
viswadaviswada 

Test Coverage of StandradSetcontroller

Hi All

 

    I am Getting problem with  Apex.pages StandardsetController My apex class is 

public class IdeaListController extends IdeaController {

    Integer IdeaCountWhenMerged = 0;
    public Idea[] mergeList {
        get {
            if (mergeList == null){
                mergeList = [select Id from Idea where ParentIdeaId!=null]; 
            }
        return mergeList; 
        }
        set;
    }
    public Idea[] ideas;  
    private static final Integer MAX_NUMBER_OF_IDEAS_PER_PAGE = 20; 

    public ApexPages.IdeaStandardSetController controller;
    public Integer total {get;set;}
    public String catName {get;set;}

    // Page number variables
    public Integer totalNumPages{get;set;}
    public Integer numPages { get; set; }

    public Boolean View {get;set;}
    public Boolean ArcView {get;set;}
    public Boolean ProView {get;set;}

    public String reqWorkspaceBtnList {get;set;}
    public String accessWorkspaceBtnList {get;set;}
    public String hasAccesstoWorkspace {get;set;}
    public Map<String,Integer> participantsList {get;set;}
    
    
    public List<Id> accessWorkspaceList {get;set;}
    
    public IdeaListController() {
        
    }

    public IdeaListController(ApexPages.IdeaStandardSetController controller) {        
        this.controller = controller; 
        accessWorkspaceBtnList = '';
        reqWorkspaceBtnList = '';
        hasAccesstoWorkspace ='';
        accessWorkspaceList = new List<Id>(); 
        participantsList = new Map<String, Integer>();    
        List<SObject> sobj = [SELECT Id,Status, (SELECT Id FROM Votes WHERE Type = 'Up' LIMIT 51),(SELECT Id,Number_Of_Participants__c  from WorkspaceList__r) 
                              FROM Idea WHERE Id IN :controller.getIdeaList() AND Categories != 'DevSummit 2012'];
        List<Idea> tempIdeaList = (List<Idea>)sobj;
        for(Idea obj: tempIdeaList) {
            String mapId = obj.Id;
            mapId = mapId.substring(0,15);              
            if (obj.Votes.size() > 50 && obj.Status == NULL) {                 
                if(obj.WorkspaceList__r.size()==0){
                    reqWorkspaceBtnList += obj.Id + ',';
                }
                else{
                    accessWorkspaceBtnList += obj.Id + ',';
                    accessWorkspaceList.add(obj.Id);                                      
                    participantsList.put(mapId,Integer.valueOf(obj.WorkspaceList__r[0].Number_Of_Participants__c));
                }
            }
            else{
                if(obj.WorkspaceList__r.size()>0){
                    accessWorkspaceBtnList += obj.Id + ',';
                    accessWorkspaceList.add(obj.Id);
                    participantsList.put(mapId,Integer.valueOf(obj.WorkspaceList__r[0].Number_Of_Participants__c));
                }
            }
        }
        List<WorkspaceUser__c> workspaceUserList = [Select WorkspaceList__c, WorkspaceList__r.Idea__c, UserName__c From WorkspaceUser__c where UserName__c = :userinfo.getUserId() and WorkspaceList__r.Idea__c IN :accessWorkspaceList];
        for(WorkspaceUser__c wu : workspaceUserList){
            hasAccesstoWorkspace += wu.WorkspaceList__r.Idea__c +',';
        }
        
    }

    public String feedName {
        get {
            if (feedName == null) {
                if (IdeaController.SORT_POPULAR.equals(sortParam)) {
                    feedName = IdeaFeedController.TYPE_POPULAR;
                    

                } else if (IdeaController.SORT_RECENT.equals(sortParam)) {
                    feedName = IdeaFeedController.TYPE_RECENT;
                  
                } else if (IdeaController.SORT_TOP.equals(sortParam)) {
                    feedName = IdeaFeedController.TYPE_TOP;
                   
                } else if (IdeaController.SORT_COMMENTS.equals(sortParam)) {
                    feedName = IdeaFeedController.TYPE_RECENT_COMMENTS;
                  
                } else {
                    feedName = IdeaFeedController.TYPE_POPULAR;
                 
                }               
            }
            return feedName;
        }
        set;
    }
   /* 
    public IdeaWithVote[] ideasWithVotes {
        get {
            if (ideasWithVotes == null) {
                ideasWithVotes = IdeaWithVote.getIdeasWithVotes(getIdeas());
                
         
            }
            return ideasWithVotes;
        }
        set;
    }
    */
    public String cat {get;set;}
    public Integer catSize {get;set;}
    
    public Idea[] getIdeas() {
        if (ideas == null) { 
            if (controller != null) {
                ideas = controller.getIdeaList();
         
            } 
           }   
        return ideas;
    }
   
      
    public String getPageName() {
        return PAGE_LIST;
    }

   public Boolean getHasPreviousPage() {
        return getPageParamInt() > 1;
       
    }

    public Boolean getHasNextPage() {
       return (ideas.size() == MAX_NUMBER_OF_IDEAS_PER_PAGE);        
    }     
     
     public Integer getPageNumber(){
       return getPageParamInt();
     }
     
   
     
     //Caluculate total number of pages
     public Integer gettotalpages(){
         Integer tot;
         
         for(Idea I : mergeList){
             IdeaCountWhenMerged++;
         }
     
         //counting ideas for each category
          if(categoryParam=='ArcGIS Server')
         {                       
                tot =  getServerIdeas();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
         else if(categoryParam=='ArcGIS Desktop')
         {                       
                tot = getDesktopIdeas();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='ArcGIS Desktop Extensions')
         {                       
                tot = getArcGISDesktopExtensions();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='ArcGIS Engine')
         {                       
                tot = getEngineIdeas();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='ArcGIS Explorer')
         {                       
                tot = getExplorerIdeas();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          
          else if(categoryParam=='ArcGIS Online')
         {                       
                tot = getOnlineIdeas();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='ArcLogistics')
         {                       
                tot = getArcLogistics();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          
          else if(categoryParam=='Geodatabase')
         {                       
                tot = getGeoDatabase();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Imagery')
         {                       
                tot = getImagery();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Maps and Content')
         {                       
                tot = getMaps();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Mobile GIS')
         {                       
                tot = getMobilegis();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }

          else if(categoryParam=='Business Analyst')
         {                       
                tot = getBusinessAnalyst();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
         else if(categoryParam=='Esri CityEngine')
         {                       
                tot = getCityEngine();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Other Products')
         {                       
                tot = getOtherProducts ();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Web Apps and APIs')
         {                       
                tot =getWebApps();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Production Mapping (PLTS)')
         {                       
                tot = getProdMap();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Service Ideas')
         {                       
                tot = getServiceIdeas();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Defense and Intelligence')
         {                       
                tot = getDefenseandIntelligence();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Education')
         {                       
                tot =  getEducation();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Local Government')
         {                       
                tot = getLocalGovernment();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Mining')
         {                       
                tot = getMining();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Federal Government')
         {                       
                tot = getFederalGovernment();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Natural Resources')
         {                       
                tot = getNaturalResources();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
         else if(categoryParam=='Petroleum')
         {                       
                tot = getPetroleum();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }

          else if(categoryParam=='Public Safety')
         {                       
                tot = getPublicSafety();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Utilities')
         {                       
                tot = getUtilities();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
         else if(categoryParam=='Telecommunications')
         {                       
                tot = getTelecommunications();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Transportation')
         {                       
                tot = getTransportation();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Other Industries')
         {                       
                tot = getOtherIndustries();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
          else if(categoryParam=='Water and Wastewater')
         {                       
                tot = getWaterandWastewater();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize()))); 
         }
         /*else if(categoryParam=='EGUG 2010')
         {
                tot=getEGUG2010();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize())));
         }
         else if(categoryParam=='DevSummit 2012')
         {
                tot=getDevSummit();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize())));
         }*/
        else if(categoryParam=='Training Ideas')
         {
                tot=getTrainingIdeas();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize())));
         }
         else if(categoryParam=='ArcGIS Runtime')
         {
                tot=getArcGISRuntime();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize())));
         }
         else if(categoryParam=='Oceans and Maritime')
         {
                tot=getOceansMaritime();
                totalNumPages = Math.round(Math.ceil(tot / ( 1.0 * this.controller.getPageSize())));
         }
         else
         {
                totalNumPages = Math.round(Math.ceil((this.controller.getResultSize()-IdeaCountWhenMerged) / ( 1.0 * this.controller.getPageSize())));    
                 //this.controller.getResultSize() 
         }
         return totalNumPages;
     }
     public String getSort(){
         return sortParam;
     }
     
     //Do not display the page numbers for comments
     
     public Boolean getcheckSort(){
         if(sortParam=='Comments'||statusParam=='Under Consideration'||statusParam=='Implemented'||statusParam=='Deferred')
             return false;
         else
             return true;
     }
      
 /*    public integer getTest(){        
         integer intTotal ;
   
        return intTotal;
     } */
   
   /*     
     public string pNUM {get;set;}
     public String fullURL;
     public String getURL(){
         return ApexPages.CurrentPage().getURL();
     }
     public PageReference goToPage(){
         PageReference pageRef = new PageReference(ApexPages.CurrentPage().getURL());
         pageRef.getParameters().clear();
         pageRef.getParameters().put('p',pNUM);
       //  pageRef.setRedirect(true);
         return pageRef+;     
    }  */
    
}

 

 I ahve written  test class Fo that class 

 

private class IdeaListControllerTest {
static testMethod void testFeedName()
{
Idea Testidea= new idea(Status_Changed_By__c='yyyy',Tags__c='xxxx' );
ApexPages.StandardController sc = new ApexPages.StandardController(Testidea);
IdeaListController Ilc=New IdeaListController();
IdeaListController Ilc1=New IdeaListController(sc);
checkFeedName(IdeaController.SORT_POPULAR, IdeaFeedController.TYPE_POPULAR);
checkFeedName(IdeaController.SORT_RECENT, IdeaFeedController.TYPE_RECENT);
checkFeedName(IdeaController.SORT_TOP, IdeaFeedController.TYPE_TOP);
checkFeedName(IdeaController.SORT_COMMENTS, IdeaFeedController.TYPE_RECENT_COMMENTS);
checkFeedName('foo', IdeaFeedController.TYPE_POPULAR);

Ilc.getIdeas();
ILC.getPageNumber();
ILC.gettotalpages();
Ilc.getSort();
ILc.getcheckSort();
}

 

 

 .   

viswadaviswada

HI  All,

    I tried in this  way also 

 

 

@isTest
private class IdeaListControllerTest {
static testMethod void testFeedName()
{
//Idea Testidea= new idea(Status_Changed_By__c='yyyy',Tags__c='xxxx' );
List<Idea> ideas= new List<Idea>();
ApexPages.StandardsetController sc = new ApexPages.StandardsetController(ideaS);
IdeaListController Ilc=New IdeaListController();//Here  if  I pass   Sc variable  i am  getting error like Constructor not defined: [IdeaListController].<Constructor>(ApexPages.StandardSetController) at line 9 column 33 , If I don't pass any  sc , I don't  get  anany error , But  IdeaListController(ApexPages.IdeaStandardSetController controller) will be not be covering,,
checkFeedName(IdeaController.SORT_POPULAR, IdeaFeedController.TYPE_POPULAR);
checkFeedName(IdeaController.SORT_RECENT, IdeaFeedController.TYPE_RECENT);
checkFeedName(IdeaController.SORT_TOP, IdeaFeedController.TYPE_TOP);
checkFeedName(IdeaController.SORT_COMMENTS, IdeaFeedController.TYPE_RECENT_COMMENTS);
checkFeedName('foo', IdeaFeedController.TYPE_POPULAR);

Ilc.getIdeas();
ILC.getPageNumber();
ILC.gettotalpages();
Ilc.getSort();
ILc.getcheckSort();
}

 

 

Please any one help