You need to sign in to do that
Don't have an account?
Priya Mishra
Help me with the test class
Hi All,Pls help me to cover the below class.
public with sharing class ESignRedirectionController_MDSR
{
private String anchor {get;set;}
public String state {get;set;}
public Boolean response {get;set;}
public PageReference recordURL {get;set;}
public string isError {get;set;}
public String res {get;set;}
public String InvoiceSelectedVal {get;set;}
public Boolean isInvoiceAuto {get;set;}
public final static String endPoint = URL.getSalesforceBaseUrl().toExternalForm().toLowerCase();
public final static String redirectUri = '/apex/EsignRedirection_MDSR';
private final static String Incorrect_Authentication = 'Incorrect_Authentication';
public String getIncorrectAuthentication()
{
return Incorrect_Authentication;
}
public MedConnect__Work_Order_Action__c woAction {get;set;}
public MedConnect__Work_Order__c workOrder {get;set;}
private ESignRedirectionController_MDSR(Boolean dummy)
{
}
public void processAnchor()
{
response = false;
state = ApexPages.currentPage().getParameters().get('state');
anchor = ApexPages.currentPage().getAnchor();
Map<String, String> parametersMap;
if(anchor != null)
parametersMap = getParametersFromAnchor(anchor);
if(state != null && anchor != null && verifyAccessToken(parametersMap.get('access_token')))
response = true;
if(response)
{
woAction = new MedConnect__Work_Order_Action__c(MedConnect__Work_Order__c = state);
recordURL = new PageReference ('/' + state);
workOrder = [SELECT Id, Name FROM MedConnect__Work_Order__c Where Id = :state];
}
}
public ESignRedirectionController_MDSR()
{
processAnchor();
}
public String integrationStatus {get;set;}
//public PageReference save()
public void save()
{
/*****************************************************************************************
Below piece of code has been added to check the Work Order's Eligibility to be sent to
ERP systems and set the Work Order as well as associated Repair Installation History Lines
Integration Status & Description accordingly - Anjali
******************************************************************************************/
Final list<Id> woId = new list<Id>();//Integration Code start
woId.add(workOrder.Id);
String retString = SetWOIntegrationStatusHandler_MDSR.getWODetails(woId);
boolean checkretString = (retString != null && !string.isblank(retString));
//AHLF-1794
if(this.InvoiceSelectedVal == null || String.isBlank(this.InvoiceSelectedVal)){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Error, 'Please select either of the Invoice creation options prior to submitting'));
return;
}
// end of AHLF-1794
if(checkretString){
//integrationStatus = retString;
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.WARNING, retString));
integrationStatus = retString;
}
else
{
integrationStatus = '';
}//Integration Code End
/* Added by sdhali for R5.3 UAT Defect Fix Start */
list<MedConnect__Work_Order__c> wolistEliUpdate= new list<MedConnect__Work_Order__c>();
list<MedConnect__Work_Order__c> wolistNEliUpdate= new list<MedConnect__Work_Order__c>();
list<MedConnect__Work_Order__c> wolistNElifrmEliUpdate= new list<MedConnect__Work_Order__c>();
wolistEliUpdate = SetWOIntegrationStatusHandlerUtil_MDSR.wolistEli;
wolistNEliUpdate =SetWOIntegrationStatusHandlerUtil_MDSR.wolistNonEli;
wolistNElifrmEliUpdate =SetWOIntegrationStatusHandlerUtil_MDSR.wolistNonEliFromEli;
boolean checkwolistEliUpdate =(!wolistEliUpdate.isEmpty());
boolean checkwolistNEliUpdate = (!wolistNEliUpdate.isEmpty());
boolean checkwolistNElifrmEliUpdate = (!wolistNElifrmEliUpdate.isEmpty());
if(checkwolistEliUpdate)
{
workOrder.ERP_Name_MDSR__c = SetWOIntegrationStatusHandlerUtil_MDSR.erpNameFinal;
workOrder.Integration_Status_ERP_MDSR__c = SetWOIntegrationStatusHandler_MDSR.inProcessStatus;
workOrder.Integration_Description_ERP_MDSR__c = '';
workOrder.Middleware_Name_MDSR__c = SetWOIntegrationStatusHandlerUtil_MDSR.mwareName;
}
else if(checkwolistNEliUpdate)
{
workOrder.Integration_Status_ERP_MDSR__c = SetWOIntegrationStatusHandler_MDSR.integStatusNA;
workOrder.Integration_Description_ERP_MDSR__c = '';
}
else if(checkwolistNElifrmEliUpdate)
{
workOrder.Integration_Status_ERP_MDSR__c = SetWOIntegrationStatusHandler_MDSR.integStatusNA;//Set WO integration status as NA
workOrder.Integration_Description_ERP_MDSR__c = '';//Anjali added no 17/10/17
workOrder.ERP_Name_MDSR__c = '';//Check if this is needed.
}
//AHLF-1794
if(this.InvoiceSelectedVal == 'True'){
this.isInvoiceAuto = true;
}
if(this.InvoiceSelectedVal == 'False'){
this.isInvoiceAuto = false;
}
//changes of AHLF-1794
/* Added for R5.3 UAT Defect Fix End */
workOrder.MedConnect__Processing_Status__c = 'Completed';
workOrder.MedConnect__Reason_For_Change__c = 'Approved';
workOrder.Auto_Create_Invoice_MDSR__c = this.isInvoiceAuto; // AHLF-1794
update workOrder;
List<MedConnect__Work_Order_Action__c> woaList = [SELECT Id, CreatedDate,Signature_Meaning_MDSR__c FROM
MedConnect__Work_Order_Action__c WHERE MedConnect__Work_Order__c =
:workOrder.Id ORDER BY CreatedDate DESC LIMIT 1];
if(!woaList.isEmpty())
{
woAction.MedConnect__Previous_Action_Date__c = woaList[0].CreatedDate;
}
woAction.MedConnect__Action_Label__c = 'Completed';
woAction.MedConnect__Action_Name__c = 'Completed';
woAction.MedConnect__Performed_By__c = UserInfo.getUserId();
woAction.MedConnect__Work_Order__c = workOrder.Id;
woAction.Electronically_Signed__c = true;
woAction.Signature_Comment_MDSR__c = woAction.Signature_Meaning_MDSR__c;
try
{
isError = 'false';
insert woAction;
}
catch(exception e)
{
isError = 'true';
}
/*****************************************************************************************
Below piece of code has been added to check the Work Order's Eligibility to be sent to
ERP systems and set the Work Order as well as associated Repair Installation History Lines
Integration Status & Description accordingly - Anjali
******************************************************************************************/
/*Final list<Id> woId = new list<Id>();//Integration Code start
woId.add(workOrder.Id);
String retString = SetWOIntegrationStatusHandler_MDSR.getWODetails(woId);
if(retString != null && !string.isblank(retString)){
//integrationStatus = retString;
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.WARNING, retString));
integrationStatus = retString;
}
else
{
integrationStatus = '';
}//Integration Code End*/
//return recordURL;
}
public String redirectParam {get;set;}
private String[] params;
public void setRedirectParam() {
params = redirectParam.split('#');
PageReference pg = ApexPages.CurrentPage();
pg.getParameters().put('state', params[0]);
pg.setAnchor(params[1]);
processAnchor();
}
public PageReference redirect() {
PageReference pg = ApexPages.CurrentPage();
pg.getParameters().put('state', params[0]);
pg.setAnchor(params[1]);
pg.setRedirect(true);
return pg;
}
public PageReference cancel()
{
return recordURL;
}
private Map<String, String> getParametersFromAnchor(String anchor)
{
Map<String, String> parametersMap = new Map<String, String>();
for(String anchorChunk : anchor.split('&'))
{
String[] parameters = anchorChunk.split('=');
if(parameters.isEmpty())
continue;
parametersMap.put(parameters[0], parameters[1]);
}
return parametersMap;
}
@RemoteAction
/*
Parsing Logic,
https://developer.pingidentity.com/en/resources/openid-connect-developers-guide/basic-client-profile.html
*/
public static String verifyAuthentication(String URL)
{
String returnValue = Incorrect_Authentication;
String[] urlChunks = url.split('#');
if(urlChunks.size() == 2)
{
ESignRedirectionController_MDSR esrCtrl = new ESignRedirectionController_MDSR(false);
String anchor = urlChunks[1];
Map<String, String> parametersMap = esrCtrl.getParametersFromAnchor(anchor);
String access_token = parametersMap.get('access_token');
if(esrCtrl.verifyAccessToken(access_token))
{
String state = parametersMap.get('state');
returnValue = state + '#' + anchor;
}
}
return returnValue;
}
private Boolean verifyAccessToken(String access_token)
{
Boolean returnValue = false;
try
{
LdapOAuth2Config__c ldapConfig = [SELECT ClientId__c, oAuth2Endpoint__c, Parameters__c,
Kid__c FROM LdapOAuth2Config__c WHERE Name = 'PingIdentity'];
User u = [SELECT Id, FederationIdentifier FROM User WHERE Id =:UserInfo.getUserId()];
String[] accessTokenUnits = access_token.split('\\.');
String headerb64 = accessTokenUnits[0];
String payloadb64 = accessTokenUnits[1];
//String digitalSignature = accessTokenUnits[2];
Header headerValue = (Header)
JSON.deserialize(EncodingUtil.base64Decode(headerb64).toString(), Header.Class);
Payload payloadValue = (Payload)
JSON.deserialize(EncodingUtil.base64Decode(payloadb64).toString(), Payload.Class);
//String algorithm = headerValue.alg;
Long expMS = payLoadValue.exp * 1000;
DateTime expiry = DateTime.newInstance(expMS);
if(ldapConfig.Kid__c != headerValue.kid ||
ldapConfig.ClientId__c != payloadValue.client_id ||
payloadValue.jnjMSUsername.toLowerCase() != u.FederationIdentifier.toLowerCase() ||
payloadValue.mail.toLowerCase() != UserInfo.getUserEmail().toLowerCase() ||
expiry < System.NOW())
{
returnValue = false;
}
else
{
returnValue = true;
}
}
catch(StringException str)
{
returnValue = false;
}
return returnValue;
}
private class Header
{
String alg {get;set;}
String kid {get;set;}
}
private class Payload
{
String jnjMSUsername {get;set;}
String cn {get;set;}
String sn {get;set;}
String mail {get;set;}
String givenName {get;set;}
Long exp {get;set;}
String [] scope {get;set;}
String client_id {get;set;}
}
}
public with sharing class ESignRedirectionController_MDSR
{
private String anchor {get;set;}
public String state {get;set;}
public Boolean response {get;set;}
public PageReference recordURL {get;set;}
public string isError {get;set;}
public String res {get;set;}
public String InvoiceSelectedVal {get;set;}
public Boolean isInvoiceAuto {get;set;}
public final static String endPoint = URL.getSalesforceBaseUrl().toExternalForm().toLowerCase();
public final static String redirectUri = '/apex/EsignRedirection_MDSR';
private final static String Incorrect_Authentication = 'Incorrect_Authentication';
public String getIncorrectAuthentication()
{
return Incorrect_Authentication;
}
public MedConnect__Work_Order_Action__c woAction {get;set;}
public MedConnect__Work_Order__c workOrder {get;set;}
private ESignRedirectionController_MDSR(Boolean dummy)
{
}
public void processAnchor()
{
response = false;
state = ApexPages.currentPage().getParameters().get('state');
anchor = ApexPages.currentPage().getAnchor();
Map<String, String> parametersMap;
if(anchor != null)
parametersMap = getParametersFromAnchor(anchor);
if(state != null && anchor != null && verifyAccessToken(parametersMap.get('access_token')))
response = true;
if(response)
{
woAction = new MedConnect__Work_Order_Action__c(MedConnect__Work_Order__c = state);
recordURL = new PageReference ('/' + state);
workOrder = [SELECT Id, Name FROM MedConnect__Work_Order__c Where Id = :state];
}
}
public ESignRedirectionController_MDSR()
{
processAnchor();
}
public String integrationStatus {get;set;}
//public PageReference save()
public void save()
{
/*****************************************************************************************
Below piece of code has been added to check the Work Order's Eligibility to be sent to
ERP systems and set the Work Order as well as associated Repair Installation History Lines
Integration Status & Description accordingly - Anjali
******************************************************************************************/
Final list<Id> woId = new list<Id>();//Integration Code start
woId.add(workOrder.Id);
String retString = SetWOIntegrationStatusHandler_MDSR.getWODetails(woId);
boolean checkretString = (retString != null && !string.isblank(retString));
//AHLF-1794
if(this.InvoiceSelectedVal == null || String.isBlank(this.InvoiceSelectedVal)){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Error, 'Please select either of the Invoice creation options prior to submitting'));
return;
}
// end of AHLF-1794
if(checkretString){
//integrationStatus = retString;
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.WARNING, retString));
integrationStatus = retString;
}
else
{
integrationStatus = '';
}//Integration Code End
/* Added by sdhali for R5.3 UAT Defect Fix Start */
list<MedConnect__Work_Order__c> wolistEliUpdate= new list<MedConnect__Work_Order__c>();
list<MedConnect__Work_Order__c> wolistNEliUpdate= new list<MedConnect__Work_Order__c>();
list<MedConnect__Work_Order__c> wolistNElifrmEliUpdate= new list<MedConnect__Work_Order__c>();
wolistEliUpdate = SetWOIntegrationStatusHandlerUtil_MDSR.wolistEli;
wolistNEliUpdate =SetWOIntegrationStatusHandlerUtil_MDSR.wolistNonEli;
wolistNElifrmEliUpdate =SetWOIntegrationStatusHandlerUtil_MDSR.wolistNonEliFromEli;
boolean checkwolistEliUpdate =(!wolistEliUpdate.isEmpty());
boolean checkwolistNEliUpdate = (!wolistNEliUpdate.isEmpty());
boolean checkwolistNElifrmEliUpdate = (!wolistNElifrmEliUpdate.isEmpty());
if(checkwolistEliUpdate)
{
workOrder.ERP_Name_MDSR__c = SetWOIntegrationStatusHandlerUtil_MDSR.erpNameFinal;
workOrder.Integration_Status_ERP_MDSR__c = SetWOIntegrationStatusHandler_MDSR.inProcessStatus;
workOrder.Integration_Description_ERP_MDSR__c = '';
workOrder.Middleware_Name_MDSR__c = SetWOIntegrationStatusHandlerUtil_MDSR.mwareName;
}
else if(checkwolistNEliUpdate)
{
workOrder.Integration_Status_ERP_MDSR__c = SetWOIntegrationStatusHandler_MDSR.integStatusNA;
workOrder.Integration_Description_ERP_MDSR__c = '';
}
else if(checkwolistNElifrmEliUpdate)
{
workOrder.Integration_Status_ERP_MDSR__c = SetWOIntegrationStatusHandler_MDSR.integStatusNA;//Set WO integration status as NA
workOrder.Integration_Description_ERP_MDSR__c = '';//Anjali added no 17/10/17
workOrder.ERP_Name_MDSR__c = '';//Check if this is needed.
}
//AHLF-1794
if(this.InvoiceSelectedVal == 'True'){
this.isInvoiceAuto = true;
}
if(this.InvoiceSelectedVal == 'False'){
this.isInvoiceAuto = false;
}
//changes of AHLF-1794
/* Added for R5.3 UAT Defect Fix End */
workOrder.MedConnect__Processing_Status__c = 'Completed';
workOrder.MedConnect__Reason_For_Change__c = 'Approved';
workOrder.Auto_Create_Invoice_MDSR__c = this.isInvoiceAuto; // AHLF-1794
update workOrder;
List<MedConnect__Work_Order_Action__c> woaList = [SELECT Id, CreatedDate,Signature_Meaning_MDSR__c FROM
MedConnect__Work_Order_Action__c WHERE MedConnect__Work_Order__c =
:workOrder.Id ORDER BY CreatedDate DESC LIMIT 1];
if(!woaList.isEmpty())
{
woAction.MedConnect__Previous_Action_Date__c = woaList[0].CreatedDate;
}
woAction.MedConnect__Action_Label__c = 'Completed';
woAction.MedConnect__Action_Name__c = 'Completed';
woAction.MedConnect__Performed_By__c = UserInfo.getUserId();
woAction.MedConnect__Work_Order__c = workOrder.Id;
woAction.Electronically_Signed__c = true;
woAction.Signature_Comment_MDSR__c = woAction.Signature_Meaning_MDSR__c;
try
{
isError = 'false';
insert woAction;
}
catch(exception e)
{
isError = 'true';
}
/*****************************************************************************************
Below piece of code has been added to check the Work Order's Eligibility to be sent to
ERP systems and set the Work Order as well as associated Repair Installation History Lines
Integration Status & Description accordingly - Anjali
******************************************************************************************/
/*Final list<Id> woId = new list<Id>();//Integration Code start
woId.add(workOrder.Id);
String retString = SetWOIntegrationStatusHandler_MDSR.getWODetails(woId);
if(retString != null && !string.isblank(retString)){
//integrationStatus = retString;
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.WARNING, retString));
integrationStatus = retString;
}
else
{
integrationStatus = '';
}//Integration Code End*/
//return recordURL;
}
public String redirectParam {get;set;}
private String[] params;
public void setRedirectParam() {
params = redirectParam.split('#');
PageReference pg = ApexPages.CurrentPage();
pg.getParameters().put('state', params[0]);
pg.setAnchor(params[1]);
processAnchor();
}
public PageReference redirect() {
PageReference pg = ApexPages.CurrentPage();
pg.getParameters().put('state', params[0]);
pg.setAnchor(params[1]);
pg.setRedirect(true);
return pg;
}
public PageReference cancel()
{
return recordURL;
}
private Map<String, String> getParametersFromAnchor(String anchor)
{
Map<String, String> parametersMap = new Map<String, String>();
for(String anchorChunk : anchor.split('&'))
{
String[] parameters = anchorChunk.split('=');
if(parameters.isEmpty())
continue;
parametersMap.put(parameters[0], parameters[1]);
}
return parametersMap;
}
@RemoteAction
/*
Parsing Logic,
https://developer.pingidentity.com/en/resources/openid-connect-developers-guide/basic-client-profile.html
*/
public static String verifyAuthentication(String URL)
{
String returnValue = Incorrect_Authentication;
String[] urlChunks = url.split('#');
if(urlChunks.size() == 2)
{
ESignRedirectionController_MDSR esrCtrl = new ESignRedirectionController_MDSR(false);
String anchor = urlChunks[1];
Map<String, String> parametersMap = esrCtrl.getParametersFromAnchor(anchor);
String access_token = parametersMap.get('access_token');
if(esrCtrl.verifyAccessToken(access_token))
{
String state = parametersMap.get('state');
returnValue = state + '#' + anchor;
}
}
return returnValue;
}
private Boolean verifyAccessToken(String access_token)
{
Boolean returnValue = false;
try
{
LdapOAuth2Config__c ldapConfig = [SELECT ClientId__c, oAuth2Endpoint__c, Parameters__c,
Kid__c FROM LdapOAuth2Config__c WHERE Name = 'PingIdentity'];
User u = [SELECT Id, FederationIdentifier FROM User WHERE Id =:UserInfo.getUserId()];
String[] accessTokenUnits = access_token.split('\\.');
String headerb64 = accessTokenUnits[0];
String payloadb64 = accessTokenUnits[1];
//String digitalSignature = accessTokenUnits[2];
Header headerValue = (Header)
JSON.deserialize(EncodingUtil.base64Decode(headerb64).toString(), Header.Class);
Payload payloadValue = (Payload)
JSON.deserialize(EncodingUtil.base64Decode(payloadb64).toString(), Payload.Class);
//String algorithm = headerValue.alg;
Long expMS = payLoadValue.exp * 1000;
DateTime expiry = DateTime.newInstance(expMS);
if(ldapConfig.Kid__c != headerValue.kid ||
ldapConfig.ClientId__c != payloadValue.client_id ||
payloadValue.jnjMSUsername.toLowerCase() != u.FederationIdentifier.toLowerCase() ||
payloadValue.mail.toLowerCase() != UserInfo.getUserEmail().toLowerCase() ||
expiry < System.NOW())
{
returnValue = false;
}
else
{
returnValue = true;
}
}
catch(StringException str)
{
returnValue = false;
}
return returnValue;
}
private class Header
{
String alg {get;set;}
String kid {get;set;}
}
private class Payload
{
String jnjMSUsername {get;set;}
String cn {get;set;}
String sn {get;set;}
String mail {get;set;}
String givenName {get;set;}
Long exp {get;set;}
String [] scope {get;set;}
String client_id {get;set;}
}
}
David Johan 4
I also facing these error but no one can helpout but youtube vanced apk (https://tspiglobal.com/troubleshooting/youtube-vanced-apk/) was helpingout and i learnd many things from here: