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
Allen2Allen2 

Could anyone please help me out to write test class for the following apex class.... I m unable to write test classs for this......

public class PageCountroller {
   
    public static List<SubscriptionResponse> subResList {get;set;}
    Public String Id;
    Public String Bpn {get; set;}
    Public boolean showSection {get; set;}

    Public PageCountroller() {
        Id = ApexPages.currentPage().getParameters().get('Id');
        system.debug('**********GettingCurrentPageAccountId'+Id);
        subResList = getSaasSubscription(Id);
        Bpn = [SELECT Name, AccountNumber FROM Account WHERE Id = :Id limit 1].AccountNumber;
    }
    
    public static List<SubscriptionResponse> getSaasSubscription(Id accountId) {
        
        SendS_SubscriptionC.MDMResponse responseFromMDM;
        String bpn = [SELECT Name, AccountNumber FROM Account WHERE Id = :accountId limit 1].AccountNumber;
        SendS_SubscriptionC saasCall = new SendS_SubscriptionC();     
        
        if(!String.isBlank(bpn)){
            responseFromMDM = sCall.getRowsByFilter('BPN',bpn );
            system.debug('*************ResponseFRomMDM'+ responseFromMDM);        
            return (processResponce(responseFromMDM));
        }
        else{
                return null;
            }
    }
    private static List<SubscriptionResponse> processResponce(SendS_SubscriptionC.MDMResponse response){
        List<SubscriptionResponse> subResList = new  List<SubscriptionResponse>();
        
        SubscriptionResponse subRes; 
        List<Plan> planltLocal = null;
        List<string> useridlist= new List<string>();
        Map<string,id> cntoktamap = new Map<String, id>();
        Plan planLocal = null;
        if(response != null){
            for(SendS_SubscriptionC.mdmProfile profileVar : response.profiles){              
                useridlist.add(profileVar.userId);
            }
            List<contact> cntlist=[SELECT Id,Okta_ID__c from contact WHERE Okta_ID__c= :useridlist];
            if(!cntlist.isEmpty())
            {
            for(Contact c : cntlist)
            {
                    cntoktamap.put(c.Okta_ID__c,c.id);
            }
            }
            for(SendS_SubscriptionC.mdmProfile profileVar : response.profiles){              
                        
                if(profileVar.subscriptionMemberships != null){
                    for(SendS_SubscriptionC.mdmSubscriptionMemberships subMembership : profileVar.subscriptionMemberships){
                        subRes = new SubscriptionResponse();
                        subRes.productId = subMembership.subscription.productId;
                        subRes.ariaSubscriptionAccountNum = subMembership.subscription.ariaSubscriptionAccountNum;
                        subRes.subscriptionDate = subMembership.subscription.subscriptionDate;
                        subRes.status = subMembership.subscription.status;                        
                        if(subMembership.subscription.plans != null){
                            planListLocal = new List<Plan>();
                            for(SendS_SubscriptionC.mdmPlans plan : subMembership.subscription.plans){
                                planLocal = new Plan();
                                planLocal.planId = plan.planId;
                                planLocal.status = plan.status;
                                planLocal.activationDate = plan.activationDate;
                                planListLocal.add(planLocal);
                            }
                        }
                        subRes.email = profileVar.email;
                        subRes.firstName = profileVar.firstName;
                        subRes.lastName = profileVar.lastName;
                        subRes.userId = cntoktamap.get(profileVar.userId);
                        subRes.planList = planListLocal;
                        subResList.add(subRes);
                  }
                }
               }
           }
        system.debug('**********subResList' + subResList);
        return subResList;        
    }
    
    public class SubscriptionResponse{
        public String productId {get;set;}
        public String email {get;set;}
        public String userId {get;set;}
        public String firstName{get;set;}
        public String lastName {get;set;}
        public String ariaSubscriptionAccountNum {get;set;}
        public String subscriptionDate{get;set;}
        public String status{get;set;}
        public List<Plan> planList {get;set;}              
    }
    public class Plan{
        public String planId {get;set;}
        public String status {get;set;}
        public String activationDate {get;set;}
    }
}
Raj VakatiRaj Vakati
Try this code
 
@isTest(SeeAllData=false)
private class IITUpdateInvoiceTest{
    
    static testMethod void testIITUpdateInvoice(){
        
        Account a = new Account() ;
        a.Name='sdasd';
        insert a ; 
        
        
        
        PageReference pageRef = Page.YOUR PAGE NAME;
        pageRef.getParameters().put('Id', a.Id );
        Test.setCurrentPage(pageRef);
        PageCountroller.getSaasSubscription(a.Id);
        
    }
    
}

 
Allen2Allen2
I did the same as before but it is covering only 9% of code. The getter setter method not covering at all.
Allen2Allen2
Now I modified it and able to cover all getter setter methods. Only this part of code I am unable to cover..... Please help me out.....


private static List<SubscriptionResponse> processResponce(SendS_SubscriptionC.MDMResponse response){
        List<SubscriptionResponse> subResList = new  List<SubscriptionResponse>();
        
        SubscriptionResponse subRes; 
        List<Plan> planltLocal = null;
        List<string> useridlist= new List<string>();
        Map<string,id> cntoktamap = new Map<String, id>();
        Plan planLocal = null;
        if(response != null){
            for(SendS_SubscriptionC.mdmProfile profileVar : response.profiles){              
                useridlist.add(profileVar.userId);
            }
            List<contact> cntlist=[SELECT Id,Okta_ID__c from contact WHERE Okta_ID__c= :useridlist];
            if(!cntlist.isEmpty())
            {
            for(Contact c : cntlist)
            {
                    cntoktamap.put(c.Okta_ID__c,c.id);
            }
            }
            for(SendS_SubscriptionC.mdmProfile profileVar : response.profiles){              
                        
                if(profileVar.subscriptionMemberships != null){
                    for(SendS_SubscriptionC.mdmSubscriptionMemberships subMembership : profileVar.subscriptionMemberships){
                        subRes = new SubscriptionResponse();
                        subRes.productId = subMembership.subscription.productId;
                        subRes.ariaSubscriptionAccountNum = subMembership.subscription.ariaSubscriptionAccountNum;
                        subRes.subscriptionDate = subMembership.subscription.subscriptionDate;
                        subRes.status = subMembership.subscription.status;                        
                        if(subMembership.subscription.plans != null){
                            planListLocal = new List<Plan>();
                            for(SendS_SubscriptionC.mdmPlans plan : subMembership.subscription.plans){
                                planLocal = new Plan();
                                planLocal.planId = plan.planId;
                                planLocal.status = plan.status;
                                planLocal.activationDate = plan.activationDate;
                                planListLocal.add(planLocal);
                            }
                        }
                        subRes.email = profileVar.email;
                        subRes.firstName = profileVar.firstName;
                        subRes.lastName = profileVar.lastName;
                        subRes.userId = cntoktamap.get(profileVar.userId);
                        subRes.planList = planListLocal;
                        subResList.add(subRes);
                  }
                }
               }
           }
        system.debug('**********subResList' + subResList);
        return subResList;