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
rupesh ranjanrupesh ranjan 

need to Write Test class for Webservice urgent basis

I have Written Mocktest but have an error in TEST Class  (Method does not exist or incorrect signature: homeReport.getperformcallout() )
@isTest
public class homeReportTest
{
    static testmethod void Myunittest1()
    {
        // Your Standard object instance
        User a = new User();
        insert a;
        homeReport cp = new homeReport(new ApexPages.StandardController(a));
        Test.setMock(HttpCalloutMock.class, new homepageTestmock());
        HttpResponse res = homeReport.getperformcallout();
        String contentType = res.getHeader('Content-Type');
        System.assert(contentType == 'application/json');
        String actualValue = res.getBody();
        String expectedValue = '{"foo":"bar"}';
        System.assertEquals(actualValue, expectedValue);
        System.assertEquals(200, res.getStatusCode());
        cp.getperformcallout();
        res = http.send(req);
    
    }

}
Mock Class  Mock Class
@IsTest 
global class homepageTestmock implements HttpCalloutMock 
{
    global HTTPResponse respond(HTTPRequest req) {
        
            string d='eU9WzoFgU4n8Apu5PYxcNGRZswRDZJWDEMdbQVU85gw=';
      String Acode= Userinfo.getuserid();
        String Oid = UserInfo.getOrganizationId();
    Blob cryptoKey= EncodingUtil.base64Decode(d);
   
    Blob data4 = Blob.valueOf(Acode);
    Blob data5 = Blob.valueOf(Oid);
    
    Blob encryptedData4 = Crypto.encryptWithManagedIV('AES256', cryptoKey, data4 );
    Blob encryptedData5 = Crypto.encryptWithManagedIV('AES256', cryptoKey, data5 );
 
       String b64Data4 = EncodingUtil.base64Encode(encryptedData4);
       String b64Data5 = EncodingUtil.base64Encode(encryptedData5);
     
     String aucode= EncodingUtil.urlEncode(b64Data4, 'UTF-8');
    String ocode= EncodingUtil.urlEncode(b64Data5, 'UTF-8');
   
        System.assertEquals('https://www.demomail.net/sf/api/HomeVideoViewReport?AUCode='+aucode+'&SOrgID='+ocode, req.getEndpoint());
        System.assertEquals('GET', req.getMethod());
        
        // Create a fake response
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'application/json');
        res.setBody('{"foo":"bar"}');
        res.setStatusCode(200);
        return res;
    }
}

Class
public with sharing class homeReport{
private ApexPages.StandardController c;
public homeReport(ApexPages.StandardController stdController) {
        c = stdController;
        }
    public   string d='eU9WzoFgU4n8Apu5PYxcNGRZswRDZJWDEMdbQVU85gw=';
     public   String Acode= Userinfo.getuserid();
     public   String Oid = UserInfo.getOrganizationId();
    Blob cryptoKey= EncodingUtil.base64Decode(d);
   
    Blob data4 = Blob.valueOf(Acode);
    Blob data5 = Blob.valueOf(Oid);
    
    Blob encryptedData4 = Crypto.encryptWithManagedIV('AES256', cryptoKey, data4 );
    Blob encryptedData5 = Crypto.encryptWithManagedIV('AES256', cryptoKey, data5 );
 
    public    String b64Data4 = EncodingUtil.base64Encode(encryptedData4);
    public    String b64Data5 = EncodingUtil.base64Encode(encryptedData5);
    //String testurl='sessionID='+EncodingUtil.urlEncode(b64Data, 'UTF-8')+'&serverUrl='+EncodingUtil.urlEncode(b64Data1, 'UTF-8')+'&contactID='+EncodingUtil.urlEncode(b64Data2, 'UTF-8')+'&email='+EncodingUtil.urlEncode(b64Data3, 'UTF-8');
      
    public String aucode= EncodingUtil.urlEncode(b64Data4, 'UTF-8');
    public String ocode= EncodingUtil.urlEncode(b64Data5, 'UTF-8');


  public List<homeReportwrap> ConsoleWrapperList{get;set;}
  
       public List<homeReportwrap> getperformcallout(){
      ConsoleWrapperList = new List<homeReportwrap>();
       HttpRequest req = new HttpRequest(); 
       HttpResponse res = new HttpResponse();
        Http http = new Http(); 
        string url = 'https://www.demomail.net/sf/api/HomeVideoViewReport?AUCode='+aucode+'&SOrgID='+ocode;
        //System.debug('##: '+ url );
      req.setEndpoint(url);
      //s req.setEndpoint('https://www.demomail.net/sf/api/HomeVideoViewReport?AUCode=aucode&SOrgID=ocode'); 
 //req.setEndpoint('https://www.demomail.net/sf/api/HomeVideoViewReport?AUCode=04uZru9MNwFgaEdddAUOHL0Y%2FtNoWSrhDMQpMyLHbVMBBENHjxc%2B7XO1Tl4T5rA4&SOrgID=IievdI%2Fz5GQAPQEWAzN7cc45a4rUCoRqbEad1KON7DSUK%2F1pxBNzk3%2FB1JcpahR2');
        req.setMethod('GET');
        system.debug('###'+d);
         system.debug('???'+Acode);
           system.debug('***'+Oid );
         
        
        //req.setHeader('Authorization', 'OAuth '+UserInfo.getSessionId());
        res = http.send(req);
         //System.assert(false,res.getBody()+'******');
       
         if(res.getstatusCode() == 200 && res.getbody() != null)
          { 
        String replaceIllegal= res.getbody().replaceAll('\n','').replaceAll('\r','');
        ConsoleWrapperList=(List<homeReportwrap>)System.JSON.deserialize(replaceIllegal,List<homeReportwrap>.class);
        //ConsoleWrapperList1 = ConsoleWrapperList.replaceall('\r\n','');
          //System.debug('Response Checking Engine: '+ res.getBody());
          }
            return consolewrapperlist; 
             
          }
               
 
 }

 
Mahesh DMahesh D
getperformcallout() is not a static method and you are calling it using the class name.

call it using the object cp.getperformcallout();

Regards,
Mahesh