You need to sign in to do that
Don't have an account?
revathy
System.AssertException: Assertion Failed: Instance StatusPending: Expected: Approved, Actual: Pending
My class 0 code coverage,urgent please help on this
my class:
public with sharing class GE_LGT_EM_ApproveRejectAllRecs
{
List<PendingAppRecs>ProsInsts{get;set;}
public List<ProcessInstance>prosInslist{get;set;}
public boolean rendPgeBlock {get;set;}
public String pgMsg{get;set;}
public string comments{get;set;}
public List<GE_LGT_EM_ComplaintLineItem__c> selProsInss{get;set;}
public List<ProcessInstance> prosInsWrkItms = new List<ProcessInstance>();
private List<ProcessInstanceWorkitem> prosInsWrkItms1 = new List<ProcessInstanceWorkitem>();
public List<PendingAppRecs> selVals = new List<PendingAppRecs>();
set<string>cliids=new set<string>();
set<string>PIids=new set<string>();
private List<Id> prosInsIds = new List<Id>();
public GE_LGT_EM_ApproveRejectAllRecs()
{
prosInslist= new List<ProcessInstance>();
selProsInss = new List<GE_LGT_EM_ComplaintLineItem__c>();
prosInslist=[Select Id, TargetObjectId, isDeleted,TargetObject.Type,Status,(Select Id, ProcessInstanceId, ActorId, Actor.Name, StepStatus, Comments From StepsAndWorkItems
Where StepStatus = 'Pending')From ProcessInstance Where isDeleted = false and Status = 'Pending' and TargetObject.Type='GE_LGT_EM_ComplaintLineItem__c'];
for(ProcessInstance PIns:prosInslist){
cliids.add(PIns.TargetObject.id);
PIids.add(PIns.id);
prosInsIds.add(PIns.Id);
}
prosInsWrkItms1 = [SELECT Id, ProcessInstance.Id, ProcessInstance.Status, Actor.Id, Actor.Name, Actor.Type FROM ProcessInstanceWorkitem where ProcessInstance.Id in : prosInsIds];
}
public pagereference appPendingRecs()
{
if(!(prosInslist.size()>0))
{
pgMsg = 'There are no records submitted for approval.';
rendPgeBlock = true;
}
else
rendPgeBlock = true;
return null;
}
public void appRej(String appRej)
{
for(ProcessInstance pwi :prosInslist)
{
for(GE_LGT_EM_ComplaintLineItem__c pi :selProsInss)
{
if(pwi.TargetObject.Id==pi.Id)
{
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
req.setComments(Comments);
req.setAction(appRej);
if(appRej == 'Approve')
// req.setNextApproverIds(new Id[] {pwi.id});
req.setNextApproverIds(null); // No further approvals for this step needed.
List<ProcessInstanceWorkitem> procWrkItms = new List<ProcessInstanceWorkitem>();
procWrkItms = [Select Id from ProcessInstanceWorkitem where ProcessInstance.Id =:pwi.id];
system.debug('procWrkItms--->'+procWrkItms);
if((!(procWrkItms.isEmpty()) && procWrkItms[0].Id!=null))
{
req.setWorkitemId(procWrkItms[0].Id);
// Submit the request for approval
Approval.ProcessResult result2 = Approval.process(req);
}
}
}
}
}
public pagereference approveAll()
{
system.debug('selProsInss--->'+selProsInss.size());
system.debug('prosInsWrkItms--->'+prosInslist.size());
appRej('Approve');
system.debug('appRej--->'+'');
Pagereference pg = new pagereference('/apex/GE_LGT_EM_BulkApproveReject');
pg.setredirect(true);
return pg;
}
public pagereference rejectAll()
{
appRej('Reject');
Pagereference pg = new pagereference('/apex/GE_LGT_EM_BulkApproveReject');
pg.setredirect(true);
return pg;
}
public pagereference cancel()
{
Pagereference pg = new pagereference('/apex/GE_LGT_EM_BulkApproveReject');
pg.setredirect(true);
return pg;
}
public pagereference selRecs(){
for(PendingAppRecs pendApp:ProsInsts)
{
if(pendApp.selected == true)
{
selProsInss.add(pendApp.proInstce);
}
}
return null;
}
public List<PendingAppRecs> getProsInsts() {
if (ProsInsts== null) {
ProsInsts= new List<PendingAppRecs>();
}
else {
ProsInsts.clear();
}
for(GE_LGT_EM_ComplaintLineItem__c pins : [SELECT Id,Name,GE_LGT_EM_SAPInvoiceNumber__c,GE_LGT_EM_ApprovingFunction__c,GE_LGT_EM_Category__c,GE_LGT_EM_ApprovedQuantity__c, CreatedDate FROM GE_LGT_EM_ComplaintLineItem__c where id=:cliids])
{
ProsInsts.add(new PendingAppRecs(pins));
}
return ProsInsts;
}
//wrapper class
public class PendingAppRecs
{
public GE_LGT_EM_ComplaintLineItem__c proInstce{get; set;}
public Boolean selected {get; set;}
public PendingAppRecs(GE_LGT_EM_ComplaintLineItem__c p)
{
proInstce = p;
selected = false;
}
}
}
===============================================
my test class
@isTest(SeeAllData=true)
public class GE_LGT_EM_ApproveReject_test{
static testMethod void myUnitTest() {
Test.startTest();
Case Caseobj=new Case(GE_LGT_EM_Salesorg__c='2BE1',Subject='test sample data');
insert Caseobj;
GE_LGT_EM_InvoiceLineItem__c newrec=new GE_LGT_EM_InvoiceLineItem__c(Name='testinvoicedata',CurrencyIsoCode='USD',GE_LGT_EM_CM_DM_RO_NO__c='5000');
insert newrec;
GE_LGT_EM_ComplaintLineItem__c acc = new GE_LGT_EM_ComplaintLineItem__c(GE_LGT_EM_Category__c='118-Product Mispick-Return',GE_LGT_EM_Comments__c='sample data',GE_LGT_EM_CaseNumber__c=Caseobj.id,CurrencyIsoCode='USD',GE_LGT_EM_CM_DM_RO_Number__c='500');
insert acc ;
Test.setMock(WebServiceMock.class, new GE_LGT_EM_171WebServiceMockImpl_test());
// Create an approval request for the cli
Approval.ProcessSubmitRequest req1 =new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(acc.id);
// Submit the approval request for the cli
Approval.ProcessResult result = Approval.process(req1);
// Verify the result
System.assert(result.isSuccess());
System.assertEquals(
'Pending', result.getInstanceStatus(),
'Instance Status'+result.getInstanceStatus());
// Approve the submitted request
// First, get the ID of the newly created item
List<Id> newWorkItemIds = result.getNewWorkitemIds();
system.debug('newWorkItemIds --->'+newWorkItemIds );
// Instantiate the new ProcessWorkitemRequest object and populate it
Approval.ProcessWorkitemRequest req2 =
new Approval.ProcessWorkitemRequest();
req2.setComments('Approving request.');
req2.setAction('Approve');
// req2.setNextApproverIds(new Id[] {UserInfo.getUserId()});
req2.setNextApproverIds(new Id[] {acc.id});
// Use the ID from the newly created item to specify the item to be worked
req2.setWorkitemId(newWorkItemIds.get(0));
// Submit the request for approval
Approval.ProcessResult result2 = Approval.process(req2);
// Verify the results
system.debug('--------->'+result2);
System.assert(result2.isSuccess(), 'Result Status:'+result2.isSuccess());
System.assertEquals('Approved', result2.getInstanceStatus(),
'Instance Status'+result2.getInstanceStatus());
Test.stopTest();
}
}
my class:
public with sharing class GE_LGT_EM_ApproveRejectAllRecs
{
List<PendingAppRecs>ProsInsts{get;set;}
public List<ProcessInstance>prosInslist{get;set;}
public boolean rendPgeBlock {get;set;}
public String pgMsg{get;set;}
public string comments{get;set;}
public List<GE_LGT_EM_ComplaintLineItem__c> selProsInss{get;set;}
public List<ProcessInstance> prosInsWrkItms = new List<ProcessInstance>();
private List<ProcessInstanceWorkitem> prosInsWrkItms1 = new List<ProcessInstanceWorkitem>();
public List<PendingAppRecs> selVals = new List<PendingAppRecs>();
set<string>cliids=new set<string>();
set<string>PIids=new set<string>();
private List<Id> prosInsIds = new List<Id>();
public GE_LGT_EM_ApproveRejectAllRecs()
{
prosInslist= new List<ProcessInstance>();
selProsInss = new List<GE_LGT_EM_ComplaintLineItem__c>();
prosInslist=[Select Id, TargetObjectId, isDeleted,TargetObject.Type,Status,(Select Id, ProcessInstanceId, ActorId, Actor.Name, StepStatus, Comments From StepsAndWorkItems
Where StepStatus = 'Pending')From ProcessInstance Where isDeleted = false and Status = 'Pending' and TargetObject.Type='GE_LGT_EM_ComplaintLineItem__c'];
for(ProcessInstance PIns:prosInslist){
cliids.add(PIns.TargetObject.id);
PIids.add(PIns.id);
prosInsIds.add(PIns.Id);
}
prosInsWrkItms1 = [SELECT Id, ProcessInstance.Id, ProcessInstance.Status, Actor.Id, Actor.Name, Actor.Type FROM ProcessInstanceWorkitem where ProcessInstance.Id in : prosInsIds];
}
public pagereference appPendingRecs()
{
if(!(prosInslist.size()>0))
{
pgMsg = 'There are no records submitted for approval.';
rendPgeBlock = true;
}
else
rendPgeBlock = true;
return null;
}
public void appRej(String appRej)
{
for(ProcessInstance pwi :prosInslist)
{
for(GE_LGT_EM_ComplaintLineItem__c pi :selProsInss)
{
if(pwi.TargetObject.Id==pi.Id)
{
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
req.setComments(Comments);
req.setAction(appRej);
if(appRej == 'Approve')
// req.setNextApproverIds(new Id[] {pwi.id});
req.setNextApproverIds(null); // No further approvals for this step needed.
List<ProcessInstanceWorkitem> procWrkItms = new List<ProcessInstanceWorkitem>();
procWrkItms = [Select Id from ProcessInstanceWorkitem where ProcessInstance.Id =:pwi.id];
system.debug('procWrkItms--->'+procWrkItms);
if((!(procWrkItms.isEmpty()) && procWrkItms[0].Id!=null))
{
req.setWorkitemId(procWrkItms[0].Id);
// Submit the request for approval
Approval.ProcessResult result2 = Approval.process(req);
}
}
}
}
}
public pagereference approveAll()
{
system.debug('selProsInss--->'+selProsInss.size());
system.debug('prosInsWrkItms--->'+prosInslist.size());
appRej('Approve');
system.debug('appRej--->'+'');
Pagereference pg = new pagereference('/apex/GE_LGT_EM_BulkApproveReject');
pg.setredirect(true);
return pg;
}
public pagereference rejectAll()
{
appRej('Reject');
Pagereference pg = new pagereference('/apex/GE_LGT_EM_BulkApproveReject');
pg.setredirect(true);
return pg;
}
public pagereference cancel()
{
Pagereference pg = new pagereference('/apex/GE_LGT_EM_BulkApproveReject');
pg.setredirect(true);
return pg;
}
public pagereference selRecs(){
for(PendingAppRecs pendApp:ProsInsts)
{
if(pendApp.selected == true)
{
selProsInss.add(pendApp.proInstce);
}
}
return null;
}
public List<PendingAppRecs> getProsInsts() {
if (ProsInsts== null) {
ProsInsts= new List<PendingAppRecs>();
}
else {
ProsInsts.clear();
}
for(GE_LGT_EM_ComplaintLineItem__c pins : [SELECT Id,Name,GE_LGT_EM_SAPInvoiceNumber__c,GE_LGT_EM_ApprovingFunction__c,GE_LGT_EM_Category__c,GE_LGT_EM_ApprovedQuantity__c, CreatedDate FROM GE_LGT_EM_ComplaintLineItem__c where id=:cliids])
{
ProsInsts.add(new PendingAppRecs(pins));
}
return ProsInsts;
}
//wrapper class
public class PendingAppRecs
{
public GE_LGT_EM_ComplaintLineItem__c proInstce{get; set;}
public Boolean selected {get; set;}
public PendingAppRecs(GE_LGT_EM_ComplaintLineItem__c p)
{
proInstce = p;
selected = false;
}
}
}
===============================================
my test class
@isTest(SeeAllData=true)
public class GE_LGT_EM_ApproveReject_test{
static testMethod void myUnitTest() {
Test.startTest();
Case Caseobj=new Case(GE_LGT_EM_Salesorg__c='2BE1',Subject='test sample data');
insert Caseobj;
GE_LGT_EM_InvoiceLineItem__c newrec=new GE_LGT_EM_InvoiceLineItem__c(Name='testinvoicedata',CurrencyIsoCode='USD',GE_LGT_EM_CM_DM_RO_NO__c='5000');
insert newrec;
GE_LGT_EM_ComplaintLineItem__c acc = new GE_LGT_EM_ComplaintLineItem__c(GE_LGT_EM_Category__c='118-Product Mispick-Return',GE_LGT_EM_Comments__c='sample data',GE_LGT_EM_CaseNumber__c=Caseobj.id,CurrencyIsoCode='USD',GE_LGT_EM_CM_DM_RO_Number__c='500');
insert acc ;
Test.setMock(WebServiceMock.class, new GE_LGT_EM_171WebServiceMockImpl_test());
// Create an approval request for the cli
Approval.ProcessSubmitRequest req1 =new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(acc.id);
// Submit the approval request for the cli
Approval.ProcessResult result = Approval.process(req1);
// Verify the result
System.assert(result.isSuccess());
System.assertEquals(
'Pending', result.getInstanceStatus(),
'Instance Status'+result.getInstanceStatus());
// Approve the submitted request
// First, get the ID of the newly created item
List<Id> newWorkItemIds = result.getNewWorkitemIds();
system.debug('newWorkItemIds --->'+newWorkItemIds );
// Instantiate the new ProcessWorkitemRequest object and populate it
Approval.ProcessWorkitemRequest req2 =
new Approval.ProcessWorkitemRequest();
req2.setComments('Approving request.');
req2.setAction('Approve');
// req2.setNextApproverIds(new Id[] {UserInfo.getUserId()});
req2.setNextApproverIds(new Id[] {acc.id});
// Use the ID from the newly created item to specify the item to be worked
req2.setWorkitemId(newWorkItemIds.get(0));
// Submit the request for approval
Approval.ProcessResult result2 = Approval.process(req2);
// Verify the results
system.debug('--------->'+result2);
System.assert(result2.isSuccess(), 'Result Status:'+result2.isSuccess());
System.assertEquals('Approved', result2.getInstanceStatus(),
'Instance Status'+result2.getInstanceStatus());
Test.stopTest();
}
}