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
sfdc9010sfdc9010 

need some Help in Test classes....

Hi frnds,
Need some help for me 
to write a test class for the below class 

public class EF_GetUserDetailFormOkta_Search_AC
{

       //public String apiEndpoint = OKTA_EndPoint__c.getValues('OKTA').Site_URL__c;
       //public String result      = '[]';
       //public String authToken   = OKTA_EndPoint__c.getValues('OKTA').Auth_token__c;
     
        public string apiEndpoint   = 'http://ec2-user@ec2-54-219-23-118.us-west-1.compute.amazonaws.com:8090/allergan.oktapreview.com/api/v1/';
        public string authToken     = 'SSWS 006BBGUE4NNIpFNpdqUm8EWLELIQuQu-SoasGMeWnV';
        public Integer timeoutOKTA      = 60000; 


   
   
    public string strSearchData {get; set;}
    public List<string> lstData {get; set;}
    public List<WrapUserDetail> lstWrapAllData {get; set;}
   
    public boolean isUserNameSelected{get; set;}
    public boolean isFirstNameSelected{get; set;}
    public boolean isLastNameSelected{get; set;}
    public boolean isEmailSelected{get; set;}
    public boolean isEmployeeIDSelected{get; set;}
    public boolean isCPIDSelected{get; set;}
    public boolean isManagerIDSelected{get; set;}
   
    public class WrapUserDetail
    {
        public string strUserName {get; set;}
        public string strFirstName {get; set;}
        public string strLastName {get; set;}
        public string strTitle {get; set;}
        public string strEmail {get; set;}
        public string strEmployeeID {get; set;}
        public string strCPID {get; set;}
        public string strManager {get; set;}
        public string strLocation {get; set;}
        public string strUserOktaID {get; set;}
       
       
        public WrapUserDetail(string UserOktaID,string UserName, string FirstName, string LastName, string Title, string Email, string EmployeeID, string CPID, string Manager, string Location)
        {
            strUserOktaID = UserOktaID;
            strUserName = UserName;
            strFirstName = FirstName;
            strLastName = LastName;
            strTitle = Title;
            strEmail = Email;
            strEmployeeID = EmployeeID;
            strCPID = CPID;
            strManager = Manager;
            strLocation = Location;
        }
    }
   
    public EF_GetUserDetailFormOkta_Search_AC()
    {
        lstData = new List<string>();
        strSearchData = '';
    }
    public void SearchData()
    {
        lstWrapAllData = new List<WrapUserDetail>();
        string QueryFilter  = CreateSearchString();
        string result = getUserList(QueryFilter);
        List<object> lstAllData = (List<object>)JSON.deserializeUntyped(result);
        system.debug('lstAllDatalstAllDatalstAllData:: ' + lstAllData);
        for(object obj : lstAllData)
        {
           
            Map<string, Object> mapData = (Map<string, Object>)obj;
           
            Map<string, Object> mapProfile = (Map<string, Object>)mapData.get('profile');
            //strUserOktaID
            WrapUserDetail objWrapUserDetail = new WrapUserDetail((string)mapProfile.get('id'),(string)mapProfile.get('AGNLoginID'), (string)mapProfile.get('firstName'), (string)mapProfile.get('lastName'),
                                                                    (string)mapProfile.get('title'), (string)mapProfile.get('email'), (string)mapProfile.get('employeeID'),
                                                                    (string)mapProfile.get('IDMCPID'), (string)mapProfile.get('manager'), (string)mapProfile.get('IDMCORALLocation'));
           
            lstWrapAllData.add(objWrapUserDetail);
        }
    }
   
    /**
     * @author         Krzysztof Wasniowski <k.wasniowski@polsource.com>
     * @version        1.0
     * @date           12/1/2013
     * @description    Returns list of users maching given filter defintion from OCTA API
     * @param          string filterDefinition Filter definition, f.ex: (userName pr or name.givenName eq Edward)
     * @return         string API response (json string)
     * @throws         EF_OKTA_APIException throws an exception is response is not 200 or filter definition is empty
     */
    public String getUserList(string filterDefinition)
    {
        String result       = '[]';
       
        Http h              = new Http();
        HttpRequest req     = new HttpRequest();
        String queryParams  = '?filter=' + EncodingUtil.urlEncode(filterDefinition.trim(), 'UTF-8');
       
        system.debug('queryParamsqueryParamsqueryParams::::New ' + queryParams);
       
        req.setMethod('GET');
        req.setHeader('Accept', 'application/json');
        //req.setTimeout(timeoutOKTA);
        req.setEndpoint(apiEndpoint + '/users' + queryParams);
        req.setHeader('Authorization', authToken);
       
        system.debug('reqreqreqreq:::New ' + req);
       
        HttpResponse res = h.send(req);
        system.debug('resresresres:::New ' + res);
       
        if (200 == res.getStatusCode()) {
            result = res.getBody();
        }
       
        return result;
    }
   
    public string CreateSearchString()
    {
        string strQueryStringToReturn = '';
       
        if(isUserNameSelected)
        {
            if(strQueryStringToReturn != '')
                strQueryStringToReturn += ' or ';
           
            strQueryStringToReturn += 'profile.AGNLoginID co ' + '\'' + strSearchData + '\'';
        }
        if(isFirstNameSelected)
        {   
            if(strQueryStringToReturn != '')
                strQueryStringToReturn += ' or ';
           
            strQueryStringToReturn += 'profile.firstName co ' + '\'' + strSearchData + '\'';
        }
        if(isLastNameSelected)
        {   
            if(strQueryStringToReturn != '')
                strQueryStringToReturn += ' or ';
           
            strQueryStringToReturn += 'profile.lastName co ' + '\'' + strSearchData + '\'';
        }
        if(isEmailSelected)
        {   
            if(strQueryStringToReturn != '')
                strQueryStringToReturn += ' or ';
           
            strQueryStringToReturn += 'profile.email co ' + '\'' + strSearchData + '\'';
        }
        if(isEmployeeIDSelected)
        {   
            if(strQueryStringToReturn != '')
                strQueryStringToReturn += ' or ';
           
            strQueryStringToReturn += 'profile.employeeID co ' + '\'' + strSearchData + '\'';
        }
        if(isCPIDSelected)
        {   
            if(strQueryStringToReturn != '')
                strQueryStringToReturn += ' or ';
           
            strQueryStringToReturn += 'profile.IDMCPID co ' + '\'' + strSearchData + '\'';
        }
        if(isManagerIDSelected)
        {   
            if(strQueryStringToReturn != '')
                strQueryStringToReturn += ' or ';
           
            strQueryStringToReturn += 'profile.managerID co ' + '\'' + strSearchData + '\'';
        }
       
        system.debug('strQueryStringToReturn:::: ' + strQueryStringToReturn);
        return strQueryStringToReturn;
    }
}


Thanks in Advance 
Carolina Ruiz MedinaCarolina Ruiz Medina
Hi sfdc9010,
I'm going to have a look to your class, meanwhile I leave you a video about Test and Testability that might be help you too . In the video you will see lots of different tecniches to test your Apex classes. ( hope it helps :) ) 
http://www.youtube.com/watch?v=dWertK6Legc

APN09217013342392059APN09217013342392059
Looks like your apex code is making HTTP callout.
To test apex code which is making HTTP callout, you will have to use HTTPCalloutMock interface.

Please see below link from the documentation for more details -

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_testing_httpcalloutmock.htm