You need to sign in to do that
Don't have an account?

Apex Test class
Please help me with the test class for the below class,
global class Projectassignment{
Public String paymentfrequency{get;set;}
public String paymentModes{get;set;}
public String Duration{get;set;}
public Boolean isProjAssign {get; set;}
private final Preference__c obj;
Public String oppId = System.currentPageReference().getParameters().get('opportunityId');
public List<ProjectDetails> detailsList {get; set;}
public Projectassignment(ApexPages.StandardController stdController)
{
this.obj = (Preference__c)stdController.getRecord();
isProjAssign = true;
}
public class ProjectDetails
{
public String Name {get; set;}
public String id {get;set;}
public Date StartDate{get;set;}
public Date EndDate{get;set;}
public String fieldOfficier{get;set;}
public Boolean isAssign {get;set;}
}
public void getProjectCodes(){
detailsList = new List<ProjectDetails>();
String sOQL='Select id,Name,StartDate__c,EndDate__c from Project__c';
for(SObject oSobject : Database.Query(sOQL))
{
Project__c obj = (Project__c)oSobject;
ProjectDetails Oproobj = new ProjectDetails();
Oproobj.Name = obj.Name;
Oproobj.StartDate=obj.StartDate__c;
Oproobj.EndDate=obj.EndDate__c;
Oproobj.isAssign = false;
detailsList.add(Oproobj);
}
System.debug(sOQL + ' == sOQL');
//system.debug('<<<<<<<<<>>>>>>>'+detailsList);
}
public pagereference preferenceassign(){
OpportunityContactRole oRole = [Select ContactId from OpportunityContactRole Where OpportunityId=:oppId];
PageReference pageRef=New PageReference('/'+oRole.ContactId);
pageRef.setRedirect(true);
system.debug('<<<<<<<<<<arun1>>>>>>>>>>>>>');
List<Preference__c> preflst = new List<Preference__C>();
for (ProjectDetails obj : detailsList){
if (obj.isAssign)
{
Preference__c pref = new Preference__c();
//Integer DurationInt = Integer.valueof(this.Duration);
//DurationInt =this.Duration;
pref.Duration__c = this.Duration;
pref.Payment_Modes__c =this.paymentModes;
pref.Payment_Frequency__c =this.paymentfrequency;
pref.Opportunity__c = oppId;
preflst.add(pref);
}
}
if ( preflst != null && preflst.size() > 0 ){
insert preflst;
updateopportunity();
}
return pageref;
}
public void updateopportunity(){
system.debug('<<<<<<<<<<arun2>>>>>>>>>>>>>');
Preference__c prefer= new Preference__c();
prefer=[select id,name from Preference__c where Opportunity__c=:oppId];
Opportunity lst = new Opportunity();
lst=[select id, name,Preference__c from opportunity where id=:oppId];
lst.Preference__c = prefer.id;
//obj.Id = prefer.name;
if ( lst!= null){
update lst;
createcommitment();
}
}
public void createcommitment(){
String str;
system.debug('<<<<<<<<<<arun3>>>>>>>>>>>>>');
List<commitment__c>lstcom = new List<commitment__c>();
for (ProjectDetails obj : detailsList){
if(obj.isAssign){
Preference__c prefer= new Preference__c();
prefer=[select id,name,Duration__c from Preference__c where Opportunity__c=:oppId];
Commitment__c com=new Commitment__c();
com.Preference__c=prefer.id;
com.Commitment_Type__c = 'Sponsor Project';
com.Start_Date__c = Date.today();
system.debug('<<<<<<<<<<arun31>>>>>>>>>>>>>'+prefer.Duration__c);
com.End_Date__c = Date.today().addMonths(Integer.valueOf(prefer.Duration__c));
com.Project__c=obj.id;
com.Commitment_Details__c = 'Manual Assignment';
com.Status__c = 'Assigned';
//com.Project__r.name =obj.Name;
str =prefer.id;
lstcom.add(com);
}
}
if ( lstcom != null && lstcom.size() > 0 )
{
insert lstcom ;
generatePaymentSchedules(str);
}
}
public void generatePaymentSchedules(String PreferenceID){
system.debug('<<<<<<<<<<arun4>>>>>>>>>>>>>');
Integer calculateduration=0;
Opportunity oppamt =[select OppAmount__c from opportunity where id=:oppId];
Preference__c payPref = [select Payment_Frequency__c,Payment_Mode__c,Duration__c from preference__c where id=:PreferenceID];
system.debug('<<<<<<<<<<arun>>>>>>>>>>>>>');
Integer divisionRatio = 1;
Integer PayDurationInt = Integer.valueOf(payPref.Duration__c);
Integer scheduleDueDate = 0;
if (payPref.Payment_Frequency__c == 'Quarterly')
{
divisionRatio = 3;
scheduleDueDate = 3;
system.debug('<<<<<<<<<<<schedule date calculation>>>>>>>>>>');
}
if (payPref.Payment_Frequency__c == 'Half-Yearly')
{
divisionRatio = 6;
scheduleDueDate = 6;
}
if(payPref.Payment_Frequency__c =='Annually(Full Payment)')
{
calculateduration =1;
}
else
{
calculateduration =(PayDurationInt/divisionRatio);
}
List<Payment_Schedule__c> list_schedule = new List<Payment_Schedule__c>();
System.debug(divisionRatio + ' == paymentMode == ' + payPref.Payment_Mode__c);
Double scheduleAmt = oppamt.OppAmount__c/divisionRatio;
Integer temp =0;
for (Integer j = 0; j < calculateduration ; j++)
{
Payment_Schedule__c obj = new Payment_Schedule__c();
obj.opportunity__c =oppId ;
obj.Amount__c = scheduleAmt;
obj.Payment_Start_Date__c = Date.today().addMonths(scheduleDueDate);
temp+= scheduleDueDate;
list_schedule.add(obj);
}
if (list_schedule.size() > 0)
insert list_schedule;
closedOpportunity();
}
public void closedOpportunity(){
Opportunity opp = [select id,StageName from opportunity where id=:oppId ];
opp.StageName ='Closed Won';
update opp;
// EmailReportGen();
}
/*public void EmailReportGen()
{
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
String[] toAddresses = new String[] {'arunsoftviewrmd@gmail.com'};
Blob b;
Messaging.SendEmailResult [] r;
email.setSubject('Child Assigned');
email.setToAddresses(toAddresses);
email.setHtmlBody( 'Hi,<br/><br/> Commitment Details has attached for your reference <br/><br/>Thank you,<br/>');
PageReference attachPdf = Page.PDFGenratorpage;
String pageUrl=attachPdf.getUrl();
Opportunity opp=[select Preference__c from opportunity where id =:oppId];
system.debug('>>>>>>>>>>>>>>>>>>>>>prefer.id<<<<<<<<<<<'+opp.Preference__c);
pageUrl = pageUrl + '?id=' +opp.Preference__c;
PageReference pdf = new Pagereference(pageUrl);
pdf.setRedirect(true);
b = pdf.getContentAsPdf();
efa.setFileName('.pdf');
efa.setBody(b);
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
}*/
public pagereference cancelAction()
{
PageReference pageRef=New PageReference('/'+oppId);
pageRef.setRedirect(true);
return pageRef;
}}