-
ChatterFeed
-
0Best Answers
-
2Likes Received
-
0Likes Given
-
3Questions
-
0Replies
Please help me in Writing the Test Class Urgent
public with sharing class EF_WorkItemStatus_EmailTemplate{
public Id efid{get; set;}
public Map<String, String>userdetailsmap{get;set;}
public EF_Request__c email_ef_req = new EF_Request__c();
public EF_Requested__c email_ef_req_res = new EF_Requested__c();
public Map<EF_Application_Form_Values__c, Boolean> oktatargetmap{get; set;}
public Map<Id,Map<String, EF_Application_Form_Values__c>>finalformlist = new Map<Id,Map<String, EF_Application_Form_Values__c>>();
public Boolean oldvalpresent{get; set;}
public List<EF_Application_Form_Values__c> ef_application_formlist = new List<EF_Application_Form_Values__c>();
public String targetlist{get;set;}
public EF_WorkItemStatus_EmailTemplate()
{
}
public EF_Requested__c getemail_ef_req_res()
{
try
{
email_ef_req_res = [Select Id, EFReq_User__r.Name, EF_Resource_Metadata__r.Name, Working_by__c, Work_Item_Status__c, EF_Request_ID__c from EF_Requested__c where Id=:efid];
email_ef_req = [select id, OKTA_User_attributes__c, Submitted_By__r.Okta_Id__c, User_Name__r.Okta_Id__c, User_Name__r.ManagerId, User_Name__c, User_Name__r.Name, Submitted_By__c, Submitted_By__r.Name, Manager__c, Manager_ID__r.Name from EF_Request__c where Id=:email_ef_req_res.EF_Request_ID__c ];
}catch(Exception e)
{
ApexPages.addMessages(e);
}
return email_ef_req_res;
}
public Map<String, String>getUserdetails()
{
EF_Requested__c email_ef_requested = [Select Id, EF_Request_ID__r.OKTA_User_attributes__c from EF_Requested__c where id=:efid];
userdetailsmap = new Map<String, String>();
try
{
String oktaid = email_ef_requested.EF_Request_ID__r.OKTA_User_attributes__c;
if(oktaid != null && oktaid != '')
{
String test = oktaid.replaceAll('"','');
String test1 = test.replace('{','');
String test2 = test1.replace('}','');
List<String>strings = test2.split(',', 0);
for(Integer i=0; i<strings.size(); i++)
{
List<String>s = strings[i].split(':',2);
userdetailsmap.put(s[0], s[1]);
}
}
}
catch(Exception e)
{
ApexPages.addMessages(e);
}
if(userdetailsmap.containsKey('employeeType'))
{
if(userdetailsmap.get('employeeType')==null)
userdetailsmap.put('employeeType','');
}
else
userdetailsmap.put('employeeType','');
if(userdetailsmap.containsKey('managerID'))
{
if(userdetailsmap.get('managerID')==null)
userdetailsmap.put('managerID','');
}
else
userdetailsmap.put('managerID','');
if(userdetailsmap.containsKey('IDM_AD_MailStop'))
{
if(userdetailsmap.get('IDM_AD_MailStop')==null)
userdetailsmap.put('IDM_AD_MailStop','');
}
else
userdetailsmap.put('IDM_AD_MailStop','');
if(userdetailsmap.containsKey('AGNLoginID'))
{
if(userdetailsmap.get('AGNLoginID')==null)
userdetailsmap.put('AGNLoginID','');
}
else
userdetailsmap.put('AGNLoginID','');
if(userdetailsmap.containsKey('IDMCPID'))
{
if(userdetailsmap.get('IDMCPID')==null)
userdetailsmap.put('IDMCPID','');
}
else
userdetailsmap.put('IDMCPID','');
if(userdetailsmap.containsKey('IDMCostCenter'))
{
if(userdetailsmap.get('IDMCostCenter')==null)
userdetailsmap.put('IDMCostCenter','');
}
else
userdetailsmap.put('IDMCostCenter','');
if(userdetailsmap.containsKey('employeeID'))
{
if(userdetailsmap.get('employeeID')==null)
userdetailsmap.put('employeeID','');
}
else
userdetailsmap.put('employeeID','');
if(userdetailsmap.containsKey('IDMSAPLogon'))
{
if(userdetailsmap.get('IDMSAPLogon')==null)
userdetailsmap.put('IDMSAPLogon','');
}
else
userdetailsmap.put('IDMSAPLogon','');
if(userdetailsmap.containsKey('firstName'))
{
if(userdetailsmap.get('firstName')==null)
userdetailsmap.put('firstName','');
}
else
userdetailsmap.put('firstName','');
if(userdetailsmap.containsKey('lastName'))
{
if(userdetailsmap.get('lastName')==null)
userdetailsmap.put('lastName','');
}
else
userdetailsmap.put('lastName','');
if(userdetailsmap.containsKey('email'))
{
if(userdetailsmap.get('email')==null)
userdetailsmap.put('email','');
}
else
userdetailsmap.put('email','');
if(userdetailsmap.containsKey('telephoneNumber'))
{
if(userdetailsmap.get('telephoneNumber')==null)
userdetailsmap.put('telephoneNumber','');
}
else
userdetailsmap.put('telephoneNumber','');
if(userdetailsmap.containsKey('IDMSecureTokenSite'))
{
if(userdetailsmap.get('IDMSecureTokenSite')==null)
userdetailsmap.put('IDMSecureTokenSite','');
}
else
userdetailsmap.put('IDMSecureTokenSite','');
return userdetailsmap;
}
public Map<String, EF_Application_Form_Values__c> getFinalformlist()
{
Map<String, EF_Application_Form_Values__c> formvaluesMap = new Map<String, EF_Application_Form_Values__c>();
Map<String, EF_Application_Form_Values__c>criteria_fields = new Map<String, EF_Application_Form_Values__c>();
List<EF_Decision_Criteria__c> efdeclist = new List<EF_Decision_Criteria__c>();
EF_Application_Form_Values__c ef = new EF_Application_Form_Values__c();
oktatargetmap = new Map<EF_Application_Form_Values__c, Boolean>();
targetlist = '';
Integer j=0;
try
{
ef_application_formlist = [Select Id, Target_System_Translation__c, OKTA_Name__c, EF_Requested_Resource__r.EF_Request_ID__c, EF_Requested_Resource__r.EF_Resource_Metadata__r.Name, Form_Field_name__c, Form_Field_Old_Value__c, Form_Field_New_Value__c From EF_Application_Form_Values__c where EF_Requested_Resource__c=:efid and Form_Field_name__c != 'instructionRequired'];
//checking if old value and new value are different for oktaname 'role' and not displaying it
for(EF_Application_Form_Values__c efa: ef_application_formlist)
{
oktatargetmap.put(efa, false);
}
for(Integer i=0; i<ef_application_formlist.size(); i++)
{
if(ef_application_formlist[i].EF_Requested_Resource__r.EF_Resource_Metadata__r.Name == 'CORAL' || ef_application_formlist[i].EF_Requested_Resource__r.EF_Resource_Metadata__r.Name=='BOXI')
{
if(ef_application_formlist[i].Form_Field_New_Value__c!=ef_application_formlist[i].Form_Field_Old_Value__c && ef_application_formlist[i].OKTA_Name__c=='roles')
{
if(targetlist == '')
targetlist = ef_application_formlist[i].Target_System_Translation__c;
else
targetlist = targetlist+','+ef_application_formlist[i].Target_System_Translation__c;
if(j==1)
ef_application_formlist.remove(i);
else
ef = ef_application_formlist[i];
j=1;
}
}
//oktatargetmap.put(ef_application_formlist[i], false);
}
oktatargetmap.put(ef, true);
oldvalpresent=false;
for(EF_Application_Form_Values__c efa: ef_application_formlist)
{
String s = efa.EF_Requested_Resource__r.EF_Resource_Metadata__r.Name+'_'+efa.Form_Field_name__c;
if(efa.Form_Field_Old_Value__c != null && efa.Form_Field_Old_Value__c != '' && (efa.Form_Field_Old_Value__c != efa.Form_Field_New_Value__c))
oldvalpresent=true;
criteria_fields.put(s.toLowerCase(), efa);
s = null;
}
efdeclist = [Select Criteria__c, Form_Field_Label__c from EF_Decision_Criteria__c where Criteria__c in:criteria_fields.keySet()];
for(EF_Decision_Criteria__c e: efdeclist)
{
if(criteria_fields.containsKey(e.Criteria__c.toLowerCase()))
{
formvaluesMap.put(e.Form_Field_Label__c, criteria_fields.get(e.Criteria__c.toLowerCase()));
}
}
}catch(Exception e)
{
ApexPages.addMessages(e);
}
return formvaluesMap;
}
}
- sfdc9010
- March 17, 2014
- Like
- 0
need some help in writing Test classes
Hi friends
Plz help me out in writing test class for the below class
public class EF_UpdateOKTA
{
public EF_UpdateOKTA()
{
UpdateEFKotaQueue();
}
public void UpdateEFKotaQueue()
{
List<string> lstEF_OKTA_QueueID = new List<string>();
/*string strQuery = EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Type__c + ' ' + EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Fields__c +
EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Relationship_fields__c + ' from ' + EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Object__c +
' where ' + EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Filter__c;
system.debug('strQuery strQuery strQuery ::' + strQuery );
List <EF_OKTA_Queue__c> lstEFOKTA_Queue_QueryData = Database.Query(strQuery);*/
List <EF_OKTA_Queue__c> lstEFOKTA_Queue_QueryData = [SELECT Id, status__c, EF_Requested_Resource__c, OKTA_JSON__c,OKTA_Response__c, number_tried__c, EF_Requested_Resource__r.EF_Resource_Metadata__r.OKTA_App_ID__c, EF_Requested_Resource__r.EF_Request_ID__r.User_Name__r.Okta_Id__c, EF_Requested_Resource__r.Request_Type__c from EF_OKTA_Queue__c where status__c='Request Sent' and number_tried__c<10 limit 10];
system.debug('lstEFOKTA_Queue_QueryDatalstEFOKTA_Queue_QueryData::' + lstEFOKTA_Queue_QueryData);
for(EF_OKTA_Queue__c objEF_OKTA_Queue_Local : lstEFOKTA_Queue_QueryData)
{
lstEF_OKTA_QueueID.add(objEF_OKTA_Queue_Local.Id);
}
if(lstEF_OKTA_QueueID.size()>0)
{
list<EF_OKTA_Queue__c> lstEfOKtatoUpdate = new list<EF_OKTA_Queue__c>();
for(EF_OKTA_Queue__c oQueue: [select id, EF_Requested_Resource__r.EF_Request_ID__r.Okta_Id__c,
EF_Requested_Resource__r.EF_Request_ID__r.User_Name__r.Okta_Id__c,
OKTA_JSON__c, number_tried__c, EF_Requested_Resource__r.Request_Type__c,
EF_Requested_Resource__r.EF_Resource_Metadata__r.OKTA_App_ID__c, Status__c
from EF_OKTA_Queue__c
where id in : lstEF_OKTA_QueueID])
{
string userID = oQueue.EF_Requested_Resource__r.EF_Request_ID__r.Okta_Id__c!=''?
oQueue.EF_Requested_Resource__r.EF_Request_ID__r.Okta_Id__c:oQueue.EF_Requested_Resource__r.EF_Request_ID__r.User_Name__r.Okta_Id__c;
string appID = oQueue.EF_Requested_Resource__r.EF_Resource_Metadata__r.OKTA_App_ID__c;
string strURLEnd = OKTA_EndPoint__c.getValues('OKTA').Site_URL__c;
strURLEnd = strURLEnd + '/apps/' + appID + '/users/' + userID;
String result = '[]';
String authToken = OKTA_EndPoint__c.getValues('OKTA').Auth_token__c;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(strURLEnd);
req.setMethod('GET');
req.setHeader('Accept', 'application/json');
req.setHeader('Authorization', authToken);
HttpResponse res = h.send(req);
if (200 == res.getStatusCode())
{
result = res.getBody();
map<string, Object> mapDataToUpdate = (map<string, Object>)JSON.deserializeUntyped(result);
if(mapDataToUpdate.get('status') == 'Completed')
{
oQueue.Status__c = 'Complete';
lstEfOktatoUpdate.add(oQueue);
}
}
}
if(lstEfOKtatoUpdate.size()>0)
{
try{update lstEfOKtatoUpdate;}
catch(Exception ex){EF_Error_Log.logException('EF_OKTA_Queue', lstEfOKtatoUpdate, 'DML', 'HIGH', ex.getMessage());
}
}
}
}
}
=====================================================================
I am struggling with the Error test fail
@isTest
private class EF_UpdateOKTA_Test {
//There are three A's(Arrange, Act, Assert) that you'll need to take care of in your test class
static testMethod void testCallout() {
/* Populate Test data, in your case in EF_abc_Queue__c object and other parent object where the data is being pulled up by the SOQL you
have in actuall class satisfying the WHERE condition(where status__c='Request Sent' and number_tried__c<10)
Also you need to populate data into the custom setting abc_EndPoint__c
This is where you are arranging the test data
*/
profile p =[select id from Profile WHERE Name ='Standard User' LIMIT 1];
User user = new User();
//Populate data for rest of the fields
user.Alias = 'rrn';
user.username = 'ganga@g.com';
user.Email = 'rg@h.com';
user.CommunityNickname ='raj';
user.ProfileId = p.id;
user.LastName = 'ganga';
user.TimeZoneSidKey = 'America/Los_Angeles';
user.LocaleSidKey = 'en_US';
user.EmailEncodingKey = 'UTF-8';
user.LanguageLocaleKey = 'en_US';
user.Okta_Id__c = 'hi';
insert user;
EF_Request__c efreqobj = new EF_Request__c();
efreqobj.Okta_Id__c = 'abc';
insert efreqobj;
EF_Requested__c efreqstedobj = new EF_Requested__c();
efreqstedobj.EF_Request_ID__c = efreqobj.id ;
efreqstedobj.Request_Type__c = 'Phone';
insert efreqstedobj;
EF_Resource_Metadata__c efresourceobj = new EF_Resource_Metadata__c();
efresourceobj.Name = 'abhi';
efresourceobj.OKTA_App_ID__c ='abcd';
insert efresourceobj ;
EF_OKTA_Queue__c efoktaQ = new EF_OKTA_Queue__c ();
efoktaQ.EF_Requested_Resource__c = efreqstedobj.id;
efoktaQ.OKTA_JSON__c = 'Hi';
efoktaQ.OKTA_Response__c = 'hi this is a test';
efoktaQ.CurrencyIsoCode = 'USD';
efoktaQ.status__c = 'Request Sent';
efoktaQ.Number_Tried__c = 8;
insert efoktaQ;
OKTA_EndPoint__c customSetting = new OKTA_EndPoint__c();
//Populate data for the data set 'abc'
customSetting.Name = 'testingendpoint';
insert customSetting;
Test.setMock(HttpCalloutMock.class, new EF_UpdateOKTA_MockHttpResponseGenerator());
Test.startTest();
EF_UpdateOKTA testObj = new EF_UpdateOKTA();
Test.stopTest();
EF_OKTA_Queue__c q = [Select Status__c from EF_OKTA_Queue__c where Id = :efoktaQ.id];
System.assert(q.Status__c == 'Complete');
}
}
with one mocktest callout class written in another class already
now the Error message is
System.NullPointerException: Attempt to de-reference a null object
Class.EF_UpdateOKTA.UpdateEFKotaQueue: line 39, column 1
Class.EF_UpdateOKTA.<init>: line 5, column 1
Class.EF_UpdateOKTA_Test.testCallout: line 78, column 1
Thanks in Advance
Plz help me out in writing test class for the below class
public class EF_UpdateOKTA
{
public EF_UpdateOKTA()
{
UpdateEFKotaQueue();
}
public void UpdateEFKotaQueue()
{
List<string> lstEF_OKTA_QueueID = new List<string>();
/*string strQuery = EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Type__c + ' ' + EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Fields__c +
EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Relationship_fields__c + ' from ' + EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Object__c +
' where ' + EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Filter__c;
system.debug('strQuery strQuery strQuery ::' + strQuery );
List <EF_OKTA_Queue__c> lstEFOKTA_Queue_QueryData = Database.Query(strQuery);*/
List <EF_OKTA_Queue__c> lstEFOKTA_Queue_QueryData = [SELECT Id, status__c, EF_Requested_Resource__c, OKTA_JSON__c,OKTA_Response__c, number_tried__c, EF_Requested_Resource__r.EF_Resource_Metadata__r.OKTA_App_ID__c, EF_Requested_Resource__r.EF_Request_ID__r.User_Name__r.Okta_Id__c, EF_Requested_Resource__r.Request_Type__c from EF_OKTA_Queue__c where status__c='Request Sent' and number_tried__c<10 limit 10];
system.debug('lstEFOKTA_Queue_QueryDatalstEFOKTA_Queue_QueryData::' + lstEFOKTA_Queue_QueryData);
for(EF_OKTA_Queue__c objEF_OKTA_Queue_Local : lstEFOKTA_Queue_QueryData)
{
lstEF_OKTA_QueueID.add(objEF_OKTA_Queue_Local.Id);
}
if(lstEF_OKTA_QueueID.size()>0)
{
list<EF_OKTA_Queue__c> lstEfOKtatoUpdate = new list<EF_OKTA_Queue__c>();
for(EF_OKTA_Queue__c oQueue: [select id, EF_Requested_Resource__r.EF_Request_ID__r.Okta_Id__c,
EF_Requested_Resource__r.EF_Request_ID__r.User_Name__r.Okta_Id__c,
OKTA_JSON__c, number_tried__c, EF_Requested_Resource__r.Request_Type__c,
EF_Requested_Resource__r.EF_Resource_Metadata__r.OKTA_App_ID__c, Status__c
from EF_OKTA_Queue__c
where id in : lstEF_OKTA_QueueID])
{
string userID = oQueue.EF_Requested_Resource__r.EF_Request_ID__r.Okta_Id__c!=''?
oQueue.EF_Requested_Resource__r.EF_Request_ID__r.Okta_Id__c:oQueue.EF_Requested_Resource__r.EF_Request_ID__r.User_Name__r.Okta_Id__c;
string appID = oQueue.EF_Requested_Resource__r.EF_Resource_Metadata__r.OKTA_App_ID__c;
string strURLEnd = OKTA_EndPoint__c.getValues('OKTA').Site_URL__c;
strURLEnd = strURLEnd + '/apps/' + appID + '/users/' + userID;
String result = '[]';
String authToken = OKTA_EndPoint__c.getValues('OKTA').Auth_token__c;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(strURLEnd);
req.setMethod('GET');
req.setHeader('Accept', 'application/json');
req.setHeader('Authorization', authToken);
HttpResponse res = h.send(req);
if (200 == res.getStatusCode())
{
result = res.getBody();
map<string, Object> mapDataToUpdate = (map<string, Object>)JSON.deserializeUntyped(result);
if(mapDataToUpdate.get('status') == 'Completed')
{
oQueue.Status__c = 'Complete';
lstEfOktatoUpdate.add(oQueue);
}
}
}
if(lstEfOKtatoUpdate.size()>0)
{
try{update lstEfOKtatoUpdate;}
catch(Exception ex){EF_Error_Log.logException('EF_OKTA_Queue', lstEfOKtatoUpdate, 'DML', 'HIGH', ex.getMessage());
}
}
}
}
}
=====================================================================
I am struggling with the Error test fail
@isTest
private class EF_UpdateOKTA_Test {
//There are three A's(Arrange, Act, Assert) that you'll need to take care of in your test class
static testMethod void testCallout() {
/* Populate Test data, in your case in EF_abc_Queue__c object and other parent object where the data is being pulled up by the SOQL you
have in actuall class satisfying the WHERE condition(where status__c='Request Sent' and number_tried__c<10)
Also you need to populate data into the custom setting abc_EndPoint__c
This is where you are arranging the test data
*/
profile p =[select id from Profile WHERE Name ='Standard User' LIMIT 1];
User user = new User();
//Populate data for rest of the fields
user.Alias = 'rrn';
user.username = 'ganga@g.com';
user.Email = 'rg@h.com';
user.CommunityNickname ='raj';
user.ProfileId = p.id;
user.LastName = 'ganga';
user.TimeZoneSidKey = 'America/Los_Angeles';
user.LocaleSidKey = 'en_US';
user.EmailEncodingKey = 'UTF-8';
user.LanguageLocaleKey = 'en_US';
user.Okta_Id__c = 'hi';
insert user;
EF_Request__c efreqobj = new EF_Request__c();
efreqobj.Okta_Id__c = 'abc';
insert efreqobj;
EF_Requested__c efreqstedobj = new EF_Requested__c();
efreqstedobj.EF_Request_ID__c = efreqobj.id ;
efreqstedobj.Request_Type__c = 'Phone';
insert efreqstedobj;
EF_Resource_Metadata__c efresourceobj = new EF_Resource_Metadata__c();
efresourceobj.Name = 'abhi';
efresourceobj.OKTA_App_ID__c ='abcd';
insert efresourceobj ;
EF_OKTA_Queue__c efoktaQ = new EF_OKTA_Queue__c ();
efoktaQ.EF_Requested_Resource__c = efreqstedobj.id;
efoktaQ.OKTA_JSON__c = 'Hi';
efoktaQ.OKTA_Response__c = 'hi this is a test';
efoktaQ.CurrencyIsoCode = 'USD';
efoktaQ.status__c = 'Request Sent';
efoktaQ.Number_Tried__c = 8;
insert efoktaQ;
OKTA_EndPoint__c customSetting = new OKTA_EndPoint__c();
//Populate data for the data set 'abc'
customSetting.Name = 'testingendpoint';
insert customSetting;
Test.setMock(HttpCalloutMock.class, new EF_UpdateOKTA_MockHttpResponseGenerator());
Test.startTest();
EF_UpdateOKTA testObj = new EF_UpdateOKTA();
Test.stopTest();
EF_OKTA_Queue__c q = [Select Status__c from EF_OKTA_Queue__c where Id = :efoktaQ.id];
System.assert(q.Status__c == 'Complete');
}
}
with one mocktest callout class written in another class already
now the Error message is
System.NullPointerException: Attempt to de-reference a null object
Class.EF_UpdateOKTA.UpdateEFKotaQueue: line 39, column 1
Class.EF_UpdateOKTA.<init>: line 5, column 1
Class.EF_UpdateOKTA_Test.testCallout: line 78, column 1
Thanks in Advance
- sfdc9010
- March 13, 2014
- Like
- 1
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
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
- sfdc9010
- March 13, 2014
- Like
- 1
need some help in writing Test classes
Hi friends
Plz help me out in writing test class for the below class
public class EF_UpdateOKTA
{
public EF_UpdateOKTA()
{
UpdateEFKotaQueue();
}
public void UpdateEFKotaQueue()
{
List<string> lstEF_OKTA_QueueID = new List<string>();
/*string strQuery = EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Type__c + ' ' + EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Fields__c +
EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Relationship_fields__c + ' from ' + EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Object__c +
' where ' + EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Filter__c;
system.debug('strQuery strQuery strQuery ::' + strQuery );
List <EF_OKTA_Queue__c> lstEFOKTA_Queue_QueryData = Database.Query(strQuery);*/
List <EF_OKTA_Queue__c> lstEFOKTA_Queue_QueryData = [SELECT Id, status__c, EF_Requested_Resource__c, OKTA_JSON__c,OKTA_Response__c, number_tried__c, EF_Requested_Resource__r.EF_Resource_Metadata__r.OKTA_App_ID__c, EF_Requested_Resource__r.EF_Request_ID__r.User_Name__r.Okta_Id__c, EF_Requested_Resource__r.Request_Type__c from EF_OKTA_Queue__c where status__c='Request Sent' and number_tried__c<10 limit 10];
system.debug('lstEFOKTA_Queue_QueryDatalstEFOKTA_Queue_QueryData::' + lstEFOKTA_Queue_QueryData);
for(EF_OKTA_Queue__c objEF_OKTA_Queue_Local : lstEFOKTA_Queue_QueryData)
{
lstEF_OKTA_QueueID.add(objEF_OKTA_Queue_Local.Id);
}
if(lstEF_OKTA_QueueID.size()>0)
{
list<EF_OKTA_Queue__c> lstEfOKtatoUpdate = new list<EF_OKTA_Queue__c>();
for(EF_OKTA_Queue__c oQueue: [select id, EF_Requested_Resource__r.EF_Request_ID__r.Okta_Id__c,
EF_Requested_Resource__r.EF_Request_ID__r.User_Name__r.Okta_Id__c,
OKTA_JSON__c, number_tried__c, EF_Requested_Resource__r.Request_Type__c,
EF_Requested_Resource__r.EF_Resource_Metadata__r.OKTA_App_ID__c, Status__c
from EF_OKTA_Queue__c
where id in : lstEF_OKTA_QueueID])
{
string userID = oQueue.EF_Requested_Resource__r.EF_Request_ID__r.Okta_Id__c!=''?
oQueue.EF_Requested_Resource__r.EF_Request_ID__r.Okta_Id__c:oQueue.EF_Requested_Resource__r.EF_Request_ID__r.User_Name__r.Okta_Id__c;
string appID = oQueue.EF_Requested_Resource__r.EF_Resource_Metadata__r.OKTA_App_ID__c;
string strURLEnd = OKTA_EndPoint__c.getValues('OKTA').Site_URL__c;
strURLEnd = strURLEnd + '/apps/' + appID + '/users/' + userID;
String result = '[]';
String authToken = OKTA_EndPoint__c.getValues('OKTA').Auth_token__c;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(strURLEnd);
req.setMethod('GET');
req.setHeader('Accept', 'application/json');
req.setHeader('Authorization', authToken);
HttpResponse res = h.send(req);
if (200 == res.getStatusCode())
{
result = res.getBody();
map<string, Object> mapDataToUpdate = (map<string, Object>)JSON.deserializeUntyped(result);
if(mapDataToUpdate.get('status') == 'Completed')
{
oQueue.Status__c = 'Complete';
lstEfOktatoUpdate.add(oQueue);
}
}
}
if(lstEfOKtatoUpdate.size()>0)
{
try{update lstEfOKtatoUpdate;}
catch(Exception ex){EF_Error_Log.logException('EF_OKTA_Queue', lstEfOKtatoUpdate, 'DML', 'HIGH', ex.getMessage());
}
}
}
}
}
=====================================================================
I am struggling with the Error test fail
@isTest
private class EF_UpdateOKTA_Test {
//There are three A's(Arrange, Act, Assert) that you'll need to take care of in your test class
static testMethod void testCallout() {
/* Populate Test data, in your case in EF_abc_Queue__c object and other parent object where the data is being pulled up by the SOQL you
have in actuall class satisfying the WHERE condition(where status__c='Request Sent' and number_tried__c<10)
Also you need to populate data into the custom setting abc_EndPoint__c
This is where you are arranging the test data
*/
profile p =[select id from Profile WHERE Name ='Standard User' LIMIT 1];
User user = new User();
//Populate data for rest of the fields
user.Alias = 'rrn';
user.username = 'ganga@g.com';
user.Email = 'rg@h.com';
user.CommunityNickname ='raj';
user.ProfileId = p.id;
user.LastName = 'ganga';
user.TimeZoneSidKey = 'America/Los_Angeles';
user.LocaleSidKey = 'en_US';
user.EmailEncodingKey = 'UTF-8';
user.LanguageLocaleKey = 'en_US';
user.Okta_Id__c = 'hi';
insert user;
EF_Request__c efreqobj = new EF_Request__c();
efreqobj.Okta_Id__c = 'abc';
insert efreqobj;
EF_Requested__c efreqstedobj = new EF_Requested__c();
efreqstedobj.EF_Request_ID__c = efreqobj.id ;
efreqstedobj.Request_Type__c = 'Phone';
insert efreqstedobj;
EF_Resource_Metadata__c efresourceobj = new EF_Resource_Metadata__c();
efresourceobj.Name = 'abhi';
efresourceobj.OKTA_App_ID__c ='abcd';
insert efresourceobj ;
EF_OKTA_Queue__c efoktaQ = new EF_OKTA_Queue__c ();
efoktaQ.EF_Requested_Resource__c = efreqstedobj.id;
efoktaQ.OKTA_JSON__c = 'Hi';
efoktaQ.OKTA_Response__c = 'hi this is a test';
efoktaQ.CurrencyIsoCode = 'USD';
efoktaQ.status__c = 'Request Sent';
efoktaQ.Number_Tried__c = 8;
insert efoktaQ;
OKTA_EndPoint__c customSetting = new OKTA_EndPoint__c();
//Populate data for the data set 'abc'
customSetting.Name = 'testingendpoint';
insert customSetting;
Test.setMock(HttpCalloutMock.class, new EF_UpdateOKTA_MockHttpResponseGenerator());
Test.startTest();
EF_UpdateOKTA testObj = new EF_UpdateOKTA();
Test.stopTest();
EF_OKTA_Queue__c q = [Select Status__c from EF_OKTA_Queue__c where Id = :efoktaQ.id];
System.assert(q.Status__c == 'Complete');
}
}
with one mocktest callout class written in another class already
now the Error message is
System.NullPointerException: Attempt to de-reference a null object
Class.EF_UpdateOKTA.UpdateEFKotaQueue: line 39, column 1
Class.EF_UpdateOKTA.<init>: line 5, column 1
Class.EF_UpdateOKTA_Test.testCallout: line 78, column 1
Thanks in Advance
Plz help me out in writing test class for the below class
public class EF_UpdateOKTA
{
public EF_UpdateOKTA()
{
UpdateEFKotaQueue();
}
public void UpdateEFKotaQueue()
{
List<string> lstEF_OKTA_QueueID = new List<string>();
/*string strQuery = EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Type__c + ' ' + EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Fields__c +
EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Relationship_fields__c + ' from ' + EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Object__c +
' where ' + EF_SOQL_Statements__c.getValues('EF_OKTA_Queue_Batch_Query').Filter__c;
system.debug('strQuery strQuery strQuery ::' + strQuery );
List <EF_OKTA_Queue__c> lstEFOKTA_Queue_QueryData = Database.Query(strQuery);*/
List <EF_OKTA_Queue__c> lstEFOKTA_Queue_QueryData = [SELECT Id, status__c, EF_Requested_Resource__c, OKTA_JSON__c,OKTA_Response__c, number_tried__c, EF_Requested_Resource__r.EF_Resource_Metadata__r.OKTA_App_ID__c, EF_Requested_Resource__r.EF_Request_ID__r.User_Name__r.Okta_Id__c, EF_Requested_Resource__r.Request_Type__c from EF_OKTA_Queue__c where status__c='Request Sent' and number_tried__c<10 limit 10];
system.debug('lstEFOKTA_Queue_QueryDatalstEFOKTA_Queue_QueryData::' + lstEFOKTA_Queue_QueryData);
for(EF_OKTA_Queue__c objEF_OKTA_Queue_Local : lstEFOKTA_Queue_QueryData)
{
lstEF_OKTA_QueueID.add(objEF_OKTA_Queue_Local.Id);
}
if(lstEF_OKTA_QueueID.size()>0)
{
list<EF_OKTA_Queue__c> lstEfOKtatoUpdate = new list<EF_OKTA_Queue__c>();
for(EF_OKTA_Queue__c oQueue: [select id, EF_Requested_Resource__r.EF_Request_ID__r.Okta_Id__c,
EF_Requested_Resource__r.EF_Request_ID__r.User_Name__r.Okta_Id__c,
OKTA_JSON__c, number_tried__c, EF_Requested_Resource__r.Request_Type__c,
EF_Requested_Resource__r.EF_Resource_Metadata__r.OKTA_App_ID__c, Status__c
from EF_OKTA_Queue__c
where id in : lstEF_OKTA_QueueID])
{
string userID = oQueue.EF_Requested_Resource__r.EF_Request_ID__r.Okta_Id__c!=''?
oQueue.EF_Requested_Resource__r.EF_Request_ID__r.Okta_Id__c:oQueue.EF_Requested_Resource__r.EF_Request_ID__r.User_Name__r.Okta_Id__c;
string appID = oQueue.EF_Requested_Resource__r.EF_Resource_Metadata__r.OKTA_App_ID__c;
string strURLEnd = OKTA_EndPoint__c.getValues('OKTA').Site_URL__c;
strURLEnd = strURLEnd + '/apps/' + appID + '/users/' + userID;
String result = '[]';
String authToken = OKTA_EndPoint__c.getValues('OKTA').Auth_token__c;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(strURLEnd);
req.setMethod('GET');
req.setHeader('Accept', 'application/json');
req.setHeader('Authorization', authToken);
HttpResponse res = h.send(req);
if (200 == res.getStatusCode())
{
result = res.getBody();
map<string, Object> mapDataToUpdate = (map<string, Object>)JSON.deserializeUntyped(result);
if(mapDataToUpdate.get('status') == 'Completed')
{
oQueue.Status__c = 'Complete';
lstEfOktatoUpdate.add(oQueue);
}
}
}
if(lstEfOKtatoUpdate.size()>0)
{
try{update lstEfOKtatoUpdate;}
catch(Exception ex){EF_Error_Log.logException('EF_OKTA_Queue', lstEfOKtatoUpdate, 'DML', 'HIGH', ex.getMessage());
}
}
}
}
}
=====================================================================
I am struggling with the Error test fail
@isTest
private class EF_UpdateOKTA_Test {
//There are three A's(Arrange, Act, Assert) that you'll need to take care of in your test class
static testMethod void testCallout() {
/* Populate Test data, in your case in EF_abc_Queue__c object and other parent object where the data is being pulled up by the SOQL you
have in actuall class satisfying the WHERE condition(where status__c='Request Sent' and number_tried__c<10)
Also you need to populate data into the custom setting abc_EndPoint__c
This is where you are arranging the test data
*/
profile p =[select id from Profile WHERE Name ='Standard User' LIMIT 1];
User user = new User();
//Populate data for rest of the fields
user.Alias = 'rrn';
user.username = 'ganga@g.com';
user.Email = 'rg@h.com';
user.CommunityNickname ='raj';
user.ProfileId = p.id;
user.LastName = 'ganga';
user.TimeZoneSidKey = 'America/Los_Angeles';
user.LocaleSidKey = 'en_US';
user.EmailEncodingKey = 'UTF-8';
user.LanguageLocaleKey = 'en_US';
user.Okta_Id__c = 'hi';
insert user;
EF_Request__c efreqobj = new EF_Request__c();
efreqobj.Okta_Id__c = 'abc';
insert efreqobj;
EF_Requested__c efreqstedobj = new EF_Requested__c();
efreqstedobj.EF_Request_ID__c = efreqobj.id ;
efreqstedobj.Request_Type__c = 'Phone';
insert efreqstedobj;
EF_Resource_Metadata__c efresourceobj = new EF_Resource_Metadata__c();
efresourceobj.Name = 'abhi';
efresourceobj.OKTA_App_ID__c ='abcd';
insert efresourceobj ;
EF_OKTA_Queue__c efoktaQ = new EF_OKTA_Queue__c ();
efoktaQ.EF_Requested_Resource__c = efreqstedobj.id;
efoktaQ.OKTA_JSON__c = 'Hi';
efoktaQ.OKTA_Response__c = 'hi this is a test';
efoktaQ.CurrencyIsoCode = 'USD';
efoktaQ.status__c = 'Request Sent';
efoktaQ.Number_Tried__c = 8;
insert efoktaQ;
OKTA_EndPoint__c customSetting = new OKTA_EndPoint__c();
//Populate data for the data set 'abc'
customSetting.Name = 'testingendpoint';
insert customSetting;
Test.setMock(HttpCalloutMock.class, new EF_UpdateOKTA_MockHttpResponseGenerator());
Test.startTest();
EF_UpdateOKTA testObj = new EF_UpdateOKTA();
Test.stopTest();
EF_OKTA_Queue__c q = [Select Status__c from EF_OKTA_Queue__c where Id = :efoktaQ.id];
System.assert(q.Status__c == 'Complete');
}
}
with one mocktest callout class written in another class already
now the Error message is
System.NullPointerException: Attempt to de-reference a null object
Class.EF_UpdateOKTA.UpdateEFKotaQueue: line 39, column 1
Class.EF_UpdateOKTA.<init>: line 5, column 1
Class.EF_UpdateOKTA_Test.testCallout: line 78, column 1
Thanks in Advance
- sfdc9010
- March 13, 2014
- Like
- 1
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
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
- sfdc9010
- March 13, 2014
- Like
- 1