Untitled
unknown
plain_text
2 years ago
100 kB
12
Indexable
/*
* Unit tests for CapitalCallController Apex class.
*
* @author: Luke
* @date: Oct 2012
*/
@IsTest
public with sharing class TestCapitalCallController {
public static Boolean coverBatchStatus = false;
//Below is a method with @testsetup annotation, the name can be anything like setup(), oneTimeData(), etc.
@testSetup static void setup() {
TriggerUtil.skipAccountTriggers = true;
final ImportWizardSettings__c importWizSettings = ImportWizardSettings__c.getOrgDefaults();
importWizSettings.Record_Insertion_Batch_Size__c = 100;
upsert importWizSettings;
Account parentAccount = TestObjectFactory.getParentAccount('Test Parent LP', true);
Account investmentVehicle = TestObjectFactory.getAccount('Test Entity LP', parentAccount, true);
Account parentAccount1 = TestObjectFactory.getParentAccount('Test Parent LP 1', true);
Account investmentVehicle1 = TestObjectFactory.getAccount('Test Entity LP 1', parentAccount1, true);
Account parentAccount2 = TestObjectFactory.getParentAccount('Test Parent LP 2', true);
Account investmentVehicle2 = TestObjectFactory.getAccount('Test Entity LP 2', parentAccount2, true);
Account parentAccount3 = TestObjectFactory.getParentAccount('Test Parent LP 3', true);
Account investmentVehicle3 = TestObjectFactory.getAccount('Test Entity LP 3', parentAccount3, true);
Fund__c fund = TestObjectFactory.getFund(true);
Fund_Allocation_Parent__c fundAllocationParent1 = TestObjectFactory.getTestFundAllocationParent(fund,'LP/GP Split','Half Up',true);
Fund_Allocation_Parent__c fundAllocationParent2 = TestObjectFactory.getTestFundAllocationParent(fund,'LP/GP Adjustable Split','Half Down',true);
Fund_Allocation_Parent__c fundAllocationParent3 = TestObjectFactory.getTestFundAllocationParent(fund,'Custom','Half Down',true);
Fund_Allocation_Parent__c fundAllocationParent4 = TestObjectFactory.getTestFundAllocationParent(fund,'Fund Pro Rata','Half Up',true);
List<Allocation_Settings__c> allocList = new List<Allocation_Settings__c>();
Allocation_Settings__c alloc1 = new Allocation_Settings__c();
alloc1.Allocation_Parent_Id__c = fundAllocationParent1.Id;
alloc1.Fund_Id__c = fund.Id;
alloc1.Field_Label_Name__c = 'Capital Call Amount';
alloc1.Name = 'Test _Capital Call Amount';
allocList.add(alloc1);
Allocation_Settings__c alloc2 = new Allocation_Settings__c();
alloc2.Allocation_Parent_Id__c = fundAllocationParent1.Id;
alloc2.Fund_Id__c = fund.Id;
alloc2.Field_Label_Name__c = 'Management Fees';
alloc2.Name = 'Test _Management Fees';
allocList.add(alloc2);
Allocation_Settings__c alloc3 = new Allocation_Settings__c();
alloc3.Allocation_Parent_Id__c = fundAllocationParent1.Id;
alloc3.Fund_Id__c = fund.Id;
alloc3.Field_Label_Name__c = 'Investments';
alloc3.Name = 'Test _Investments';
allocList.add(alloc3);
Allocation_Settings__c alloc4 = new Allocation_Settings__c();
alloc4.Allocation_Parent_Id__c = fundAllocationParent1.Id;
alloc4.Fund_Id__c = fund.Id;
alloc4.Field_Label_Name__c = 'Other';
alloc4.Name = 'Test _Other';
allocList.add(alloc4);
Allocation_Settings__c alloc5 = new Allocation_Settings__c();
alloc5.Allocation_Parent_Id__c = fundAllocationParent1.Id;
alloc5.Fund_Id__c = fund.Id;
alloc5.Field_Label_Name__c = 'Expenses';
alloc5.Name = 'Test _Expenses';
allocList.add(alloc5);
Allocation_Settings__c alloc6 = new Allocation_Settings__c();
alloc6.Allocation_Parent_Id__c = fundAllocationParent1.Id;
alloc6.Fund_Id__c = fund.Id;
alloc6.Field_Label_Name__c = 'Late Admission Interest';
alloc6.Name = 'Test _Late Admission Interest';
allocList.add(alloc6);
insert allocList;
Map<String,Allocation_Settings__c> allocSetting = new Map<String,Allocation_Settings__c>();
allocSetting = Allocation_Settings__c.getAll();
TriggerUtil.skipAccountTriggers = false;
}
@IsTest
static void testSuccessCapitalCalls() {
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entityLP = [Select Id,Name from Account where Name='Test Entity LP'];
// Set up Capital Commitment 1:
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 0.0
);
insert capitalCommit2;
Fund__c fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(400.0, fund.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.callToRetrieveCommitments();
system.debug('in 87 '+controller.currentStep);
controller.next(); // get passed the selection stage
system.debug('in 89 '+controller.currentStep);
controller.previous();
system.debug('in 90 '+controller.currentStep);
controller.next();
system.debug('in 92 '+controller.currentStep);
controller.next();
system.debug('in 94 '+controller.currentStep);
controller.previous();
system.debug('in 96 '+controller.currentStep);
controller.next();
system.debug('in 98 '+controller.currentStep);
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 500.0;
controller.next(); // go to review step
system.debug('in 102 '+controller.currentStep);
System.assertEquals(CapitalCallController.Step.REVIEW, controller.currentStep);
controller.previous(); // return to previous step
System.assertNotEquals(CapitalCallController.Step.REVIEW, controller.currentStep);
controller.next(); // go back to review step
System.assertEquals(CapitalCallController.Step.REVIEW, controller.currentStep);
System.assertNotEquals(null, controller.templateUrl);
Test.startTest();
controller.isNullOrZeroCapCommitmentCheckbox = false;
controller.confirmAndSave();
Test.stopTest();
List<Capital_Call_Parent__c> parent = [SELECT Id, Fund__c FROM Capital_Call_Parent__c];
System.assertEquals(fund.Id, parent[0].Fund__c, 'Capital Call Parent should look up to Fund');
System.assertEquals(1, parent.size(), 'Expected Capital Call Parent to be generated');
List<Capital_Call__c> capitalCall1 = [SELECT Capital_Call_Amount__c, Capital_Call_Parent__c FROM Capital_Call__c WHERE Capital_Commitment__c = :capitalCommit1.Id];
System.assertEquals(1, capitalCall1.size(), 'Expected Capital Call to be generated for Capital Commitment 1');
System.assertEquals(parent[0].Id, capitalCall1[0].Capital_Call_Parent__c, 'Capital Call should look up to parent');
System.assertEquals(500.0, capitalCall1[0].Capital_Call_Amount__c);
List<Capital_Call__c> capitalCall2 = [SELECT Capital_Call_Amount__c, Capital_Call_Parent__c FROM Capital_Call__c WHERE Capital_Commitment__c = :capitalCommit2.Id];
System.assertEquals(1, capitalCall2.size(), 'Expected Capital Call to be generated for Capital Commitment 2');
System.assertEquals(parent[0].Id, capitalCall2[0].Capital_Call_Parent__c, 'Capital Call should look up to parent');
System.assertEquals(0.0, capitalCall2[0].Capital_Call_Amount__c);
//System.assertNotEquals(null, controller.templateUrl);
controller.returnToFund(); // returns page reference back to Fund
}
/*
* Perform negative test where validation should fail
*/
@IsTest
static void testCreationOfCapitalCallsWithoutDateAsInput() {
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entityLP = [Select Id,Name from Account where Name='Test Entity LP'];
// Set up Capital Commitment 1:
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit1;
fund__c fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(400.0, fund.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.callToRetrieveCommitments();
controller.next(); // get passed the selection stage
// Deliberately don't set date
// Deliberately don't set call amount
controller.next(); // go to review step
System.assertEquals(CapitalCallController.Step.REVIEW, controller.currentStep);
//System.assertEquals(null, controller.newCapitalCalls, 'Shouldn\'t create any capital calls if validation fails');
}
/**
* Scenario: No commitments are selected for prorata.
* Expected Outcome: The step remains on 'COMMITMENT_SELECTION' as no commitments were selected
*/
@IsTest
static void testAtleastOneCommitmentSelected() {
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entityLP = [Select Id,Name from Account where Name='Test Entity LP'];
// Set up Capital Commitment 1:
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit1;
Fund__c fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(400.0, fund.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund);
CapitalCallController controller = new CapitalCallController(sc);
controller.callToRetrieveCommitments();
System.assertEquals(CapitalCallController.Step.COMMITMENT_SELECTION, controller.currentStep, 'The should be kicked off in commitment selection');
for (Integer pageNumber : controller.mapOfCapitalCommitments.keyset()) {
for(CapitalCallController.CommitmentWrapper commitment: controller.mapOfCapitalCommitments.get(pageNumber)){
commitment.checked = false;
}
}
controller.next();
System.assertEquals(CapitalCallController.Step.COMMITMENT_SELECTION, controller.currentStep, 'The controller should have remained on commitment selection, since we deselected all of the commitments');
}
@IsTest
static void csvTest() {
Test.startTest();
Fund__c fund=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
Account entity2 = [Select Id,Name from Account where Name='Test Entity LP 1'];
// Set up Capital Commitment 1:
final Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entity1.Id,
Fund_Name__c = fund.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
final Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entity2.Id,
Fund_Name__c = fund.Id,
Capital_Commitment__c = 600.0
);
insert capitalCommit2;
fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund.Id];
final ApexPages.StandardController sc = new ApexPages.StandardController(fund);
final CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.callToRetrieveCommitments();
controller.next(); // get passed the selection stage
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 500.0;
controller.next(); // go to review step
controller.fileBody = Blob.valueOf(
'Investment Vehicle,Capital Call Amount\n'+
'Test Entity LP,100.00\n'+
'Test Entity LP 1,200.00'
);
controller.processCSV();
controller.confirmAndSave();
Test.stopTest();
final List<Capital_Call__c> capitalCall1 = [SELECT Capital_Call_Amount__c, Capital_Call_Parent__c FROM Capital_Call__c WHERE Capital_Commitment__c = :capitalCommit1.Id];
System.assertEquals(100.0, capitalCall1[0].Capital_Call_Amount__c);
final List<Capital_Call__c> capitalCall2 = [SELECT Capital_Call_Amount__c, Capital_Call_Parent__c FROM Capital_Call__c WHERE Capital_Commitment__c = :capitalCommit2.Id];
System.assertEquals(200.0, capitalCall2[0].Capital_Call_Amount__c);
}
/*
*This is to cover the AllocationRecordsAsyncInsert Class for > 180 records
*/
@IsTest
static void testPaginationForCapitalCommitments(){
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entityLP = [Select Id,Name from Account where Name='Test Entity LP'];
// Set up Capital Commitment 1:
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 0.0
);
insert capitalCommit2;
Fund__c fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(400.0, fund.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund);
CapitalCallController controller = new CapitalCallController(sc);
controller.capitalCommitmentPageSize = 1;
controller.init();
controller.callToRetrieveCommitments();
system.assertEquals(true,controller.getprev());
system.assertEquals(false, controller.getnxt());
system.assertEquals(1,controller.capitalCommitmentCurrentPageNumber);
controller.nextCapitalCommitmentList();
system.assertEquals(false,controller.getprev());
system.assertEquals(true, controller.getnxt());
system.assertEquals(2,controller.capitalCommitmentCurrentPageNumber);
controller.previousCapitalCommitmenttList();
system.assertEquals(1,controller.capitalCommitmentCurrentPageNumber);
}
@IsTest
static void testProcessCSVWithoutBody(){
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entityLP = [Select Id,Name from Account where Name='Test Entity LP'];
// Set up Capital Commitment 1:
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit2;
Fund__c fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(800.0, fund.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund);
CapitalCallController controller = new CapitalCallController(sc);
controller.capitalCommitmentPageSize = 1;
controller.init();
controller.callToRetrieveCommitments();
controller.next();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 100.0;
controller.next();
Test.startTest();
controller.processCSV();
Test.stopTest();
system.assertEquals(null, controller.fileBody);
}
@IsTest
static void testProcessCSVWithEmptyBody(){
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entityLP = [Select Id,Name from Account where Name='Test Entity LP'];
// Set up Capital Commitment 1:
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit2;
Fund__c fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(800.0, fund.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund);
CapitalCallController controller = new CapitalCallController(sc);
controller.capitalCommitmentPageSize = 1;
controller.init();
controller.callToRetrieveCommitments();
controller.next();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 100.0;
controller.next();
Test.startTest();
controller.fileBody = Blob.valueOf('');
controller.processCSV();
Test.stopTest();
if(ApexPages.getMessages().size()!=0){
for(ApexPages.Message msg:ApexPages.getMessages()){
System.assertEquals('The CSV file seems to be empty.', msg.getSummary());
System.assertEquals(ApexPages.Severity.ERROR, msg.getSeverity());
}
}
}
@IsTest
static void testProcessIncorrectCsv(){
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entityLP = [Select Id,Name from Account where Name='Test Entity LP'];
// Set up Capital Commitment 1:
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit2;
Fund__c fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(800.0, fund.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund);
CapitalCallController controller = new CapitalCallController(sc);
controller.capitalCommitmentPageSize = 1;
controller.init();
controller.callToRetrieveCommitments();
controller.next();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 100.0;
controller.next();
Test.startTest();
controller.fileBody = Blob.valueOf(
'Investment Vehicle,Capital Call Amount,Investments,Late Admission Interest,Expenses Outside of Commitment,Management Fees,Expenses,Other\n'+
'Test Entity LP,50.00,9,8,4,2,5,1\n'+
'Test Entity LP,50.00,test9,8,4,2,5,1'
);
controller.processCSV();
Test.stopTest();
system.debug(controller.mapOfCapitalCalls);
system.debug(apexpages.getMessages());
if(ApexPages.getMessages().size()!=0){
for(ApexPages.Message msg:ApexPages.getMessages()){
System.assertEquals('Unable to process value test9. Remove all commas from numbers prior to processing CSV file.', msg.getSummary());
System.assertEquals(ApexPages.Severity.ERROR, msg.getSeverity());
}
}
}
@IsTest
static void testPaginationForZeroCapitalCommitments(){
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entityLP = [Select Id,Name from Account where Name='Test Entity LP'];
// Set up Capital Commitment 1:
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 0.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 0.0
);
insert capitalCommit2;
Fund__c fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(0.0, fund.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund);
CapitalCallController controller = new CapitalCallController(sc);
controller.capitalCommitmentPageSize = 1;
controller.init();
controller.callToRetrieveCommitments();
system.assertEquals(true,controller.getprev());
system.assertEquals(false, controller.getnxt());
system.assertEquals(1,controller.capitalCommitmentCurrentPageNumber);
controller.nextCapitalCommitmentList();
system.assertEquals(false,controller.getprev());
system.assertEquals(true, controller.getnxt());
system.assertEquals(2,controller.capitalCommitmentCurrentPageNumber);
controller.previousCapitalCommitmenttList();
system.assertEquals(1,controller.capitalCommitmentCurrentPageNumber);
controller.next();
System.assertEquals(CapitalCallController.Step.COMMITMENT_CHECK, controller.currentStep);
system.assertEquals(0, controller.zerocapitalCommitmentCurrentPageNumber);
system.assertEquals(true, controller.getzeroprev());
system.assertEquals(false, controller.getzeronxt());
controller.nextzeroCapitalCommitmentList();
system.assertEquals(true, controller.getzeronxt());
system.assertEquals(false, controller.getzeroprev());
system.assertEquals(1, controller.zerocapitalCommitmentCurrentPageNumber);
controller.previousZeroCapitalCommitmenttList();
}
@IsTest
static void testPaginationForCapitalCalls(){
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
Account entity2 = [Select Id,Name from Account where Name='Test Entity LP 1'];
Account entity3 = [Select Id,Name from Account where Name='Test Entity LP 2'];
// Set up Capital Commitment 1:
Test.startTest();
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entity1.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entity2.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit2;
// Set up Capital Commitment 3:
Capital_Commitment__c capitalCommit3 = new Capital_Commitment__c(
LP_Entity__c = entity3.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit3;
fund1 = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(300.0, fund1.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund1);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.capitalCommitmentPageSize = 2;
controller.capitalCallPageSize = 2;
controller.callToRetrieveCommitments();
system.assertEquals(2,controller.mapOfCapitalCommitments.size());
system.assertEquals(1,controller.capitalCommitmentCurrentPageNumber);
system.assertEquals(true,controller.getprev());
system.assertEquals(false,controller.getnxt());
controller.nextCapitalCommitmentList();
system.assertEquals(2,controller.capitalCommitmentCurrentPageNumber);
system.assertEquals(false,controller.getprev());
system.assertEquals(true,controller.getnxt());
controller.previousCapitalCommitmenttList();
controller.next();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 100.0;
controller.tempCall.Investments__c = 50.00;
controller.tempCall.Management_Fees__c = 60.00;
controller.tempCall.Expenses__c = 70.00;
controller.tempCall.Other__c = 80.00;
controller.next();
system.assertEquals(2,controller.mapOfCapitalCalls.size());
system.assertEquals(1,controller.capitalCallCurrentPageNumber);
controller.confirmAndSave();
Test.stopTest();
List<Capital_Call_Parent__c> parent = [Select Id, Fund__c From Capital_Call_Parent__c];
System.assertEquals(1, parent.size());
System.assertEquals(fund1.Id, parent[0].Fund__c);
List<Capital_Call__c> capitalCall1 = [SELECT Capital_Call_Parent__c,Capital_Call_Amount__c,Investments__c,Management_Fees__c,Expenses__c,Other__c,Capital_Commitment__c FROM Capital_Call__c WHERE Capital_Commitment__c = :capitalCommit1.Id];
System.assertEquals(1, capitalCall1.size());
System.assertEquals(parent[0].Id, capitalCall1[0].Capital_Call_Parent__c);
System.assertEquals(33.33, capitalCall1[0].Capital_Call_Amount__c);
if (SObjectType.Capital_Call__c.FieldSets.getMap().containsKey('Import_Wizard_Fields')) {
FieldSet fieldSet = SObjectType.Capital_Call__c.FieldSets.Import_Wizard_Fields;
List<String> fieldNames = new List<String>();
for (FieldSetMember field : fieldSet.getFields()) {
fieldNames.add(field.getFieldPath());
}
system.debug('###fieldNames'+fieldNames);
if (fieldNames.contains('Investments__c')) {
System.assertEquals(16.67, capitalCall1[0].Investments__c);
}
if (fieldNames.contains('Management_Fees__c')) {
System.assertEquals(20.00, capitalCall1[0].Management_Fees__c);
}
if (fieldNames.contains('Expenses__c')) {
System.assertEquals(23.33, capitalCall1[0].Expenses__c);
}
if (fieldNames.contains('Other__c')) {
System.assertEquals(26.67, capitalCall1[0].Other__c);
}
}
List<Capital_Call__c> capitalCall2 = [SELECT Capital_Call_Parent__c,Capital_Call_Amount__c,Investments__c,Management_Fees__c,Expenses__c,Other__c,Capital_Commitment__c FROM Capital_Call__c WHERE Capital_Commitment__c = :capitalCommit2.Id];
System.assertEquals(1, capitalCall2.size());
System.assertEquals(parent[0].Id, capitalCall2[0].Capital_Call_Parent__c);
System.assertEquals(33.33,capitalCall2[0].Capital_Call_Amount__c);
if (SObjectType.Capital_Call__c.FieldSets.getMap().containsKey('Import_Wizard_Fields')) {
FieldSet fieldSet = SObjectType.Capital_Call__c.FieldSets.Import_Wizard_Fields;
List<String> fieldNames = new List<String>();
for (FieldSetMember field : fieldSet.getFields()) {
fieldNames.add(field.getFieldPath());
}
system.debug('###fieldNames'+fieldNames);
if (fieldNames.contains('Investments__c')) {
System.assertEquals(16.67, capitalCall1[0].Investments__c);
}
if (fieldNames.contains('Management_Fees__c')) {
System.assertEquals(20.00, capitalCall1[0].Management_Fees__c);
}
if (fieldNames.contains('Expenses__c')) {
System.assertEquals(23.33, capitalCall1[0].Expenses__c);
}
if (fieldNames.contains('Other__c')) {
System.assertEquals(26.67, capitalCall1[0].Other__c);
}
}
List<Capital_Call__c> capitalCall3 = [SELECT Capital_Call_Parent__c,Capital_Call_Amount__c,Investments__c,Management_Fees__c,Expenses__c,Other__c,Capital_Commitment__c FROM Capital_Call__c WHERE Capital_Commitment__c = :capitalCommit3.Id];
System.assertEquals(1, capitalCall3.size());
System.assertEquals(parent[0].Id, capitalCall3[0].Capital_Call_Parent__c);
System.assertEquals(33.33,capitalCall3[0].Capital_Call_Amount__c);
if (SObjectType.Capital_Call__c.FieldSets.getMap().containsKey('Import_Wizard_Fields')) {
FieldSet fieldSet = SObjectType.Capital_Call__c.FieldSets.Import_Wizard_Fields;
List<String> fieldNames = new List<String>();
for (FieldSetMember field : fieldSet.getFields()) {
fieldNames.add(field.getFieldPath());
}
system.debug('###fieldNames'+fieldNames);
if (fieldNames.contains('Investments__c')) {
System.assertEquals(16.67, capitalCall1[0].Investments__c);
}
if (fieldNames.contains('Management_Fees__c')) {
System.assertEquals(20.00, capitalCall1[0].Management_Fees__c);
}
if (fieldNames.contains('Expenses__c')) {
System.assertEquals(23.33, capitalCall1[0].Expenses__c);
}
if (fieldNames.contains('Other__c')) {
System.assertEquals(26.67, capitalCall1[0].Other__c);
}
}
system.assertEquals(2,controller.sizeOfCapitalCommitmentsMap);
}
@isTest
static void testBatchExecutionOfCapitalCalls(){
final ImportWizardSettings__c importWizSettings = ImportWizardSettings__c.getOrgDefaults();
importWizSettings.Record_Insertion_Batch_Size__c = 100;
importWizSettings.Long_Running_Batch_Time_Threshold__c = 0;//Setting this value to zero to make sure long running process gets executed for this transaction.
upsert importWizSettings;
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
Account entity2 = [Select Id,Name from Account where Name='Test Entity LP 1'];
Account entity3 = [Select Id,Name from Account where Name='Test Entity Lp 2'];
Account entity4 = [Select Id,Name from Account where Name='Test Entity Lp 3'];
Account parentLP1 = [Select Id,Name from Account where Name='Test Parent LP'];
Test.startTest();
Account parentAccount5 = TestObjectFactory.getParentAccount('Test Parent 5', true);
Account investmentVehicle5 = TestObjectFactory.getAccount('Test Entity 5', parentAccount5, true);
Account parentAccount6 = TestObjectFactory.getParentAccount('Test Parent 6', true);
Account investmentVehicle6 = TestObjectFactory.getAccount('Test Entity 6', parentAccount6, true);
Account entity5 = [Select Id,Name from Account where Name='Test Entity 5'];
Account entity6 = [Select Id,Name from Account where Name='Test Entity 6'];
// Set up Capital Commitment 1:
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entity1.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entity2.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit2;
// Set up Capital Commitment 3:
Capital_Commitment__c capitalCommit3 = new Capital_Commitment__c(
LP_Entity__c = entity3.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit3;
Capital_Commitment__c capitalCommit4 = new Capital_Commitment__c(
LP_Entity__c = entity4.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit4;
Capital_Commitment__c capitalCommit5 = new Capital_Commitment__c(
LP_Entity__c = entity5.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit5;
Capital_Commitment__c capitalCommit6 = new Capital_Commitment__c(
LP_Entity__c = entity6.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit6;
fund1 = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(600.0, fund1.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund1);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.capitalCommitmentPageSize = 2;
controller.capitalCallPageSize = 2;
controller.capitalCallsSuccessPageSize = 2;
controller.capitalCallfailurePageSize = 2;
controller.callToRetrieveCommitments();
system.assertEquals(3,controller.mapOfCapitalCommitments.size());
system.assertEquals(1,controller.capitalCommitmentCurrentPageNumber);
system.assertEquals(true,controller.getprev());
system.assertEquals(false,controller.getnxt());
controller.nextCapitalCommitmentList();
system.assertEquals(2,controller.capitalCommitmentCurrentPageNumber);
system.assertEquals(false,controller.getprev());
system.assertEquals(false,controller.getnxt());
controller.nextCapitalCommitmentList();
system.assertEquals(3,controller.capitalCommitmentCurrentPageNumber);
system.assertEquals(false,controller.getprev());
system.assertEquals(true,controller.getnxt());
controller.previousCapitalCommitmenttList();
controller.next();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 300.0;
controller.next();
system.assertEquals(3,controller.mapOfCapitalCalls.size());
system.assertEquals(1,controller.capitalCallCurrentPageNumber);
coverBatchStatus = True;
upsert controller.parent;
for (Integer pageNum : Controller.mapOfCapitalCalls.keySet()) {
for (CapitalCallController.CapitalCallWrapper wrapped : Controller.mapOfCapitalCalls.get(pageNum)) {
if(wrapped.record.Capital_Commitment__c == capitalCommit2.Id || wrapped.record.Capital_Commitment__c == capitalCommit4.Id || wrapped.record.Capital_Commitment__c == capitalCommit6.Id){
wrapped.record.LP_Entity__c = parentLP1.Id;
}
wrapped.record.Capital_Call_Parent__c = Controller.parent.Id;
Controller.capitalCallRecords.add(wrapped.record);
}
}
controller.confirmAndSave();
Boolean batchOnHold = false;
Boolean batchOnPreparing = false;
Boolean batchOnQueued = false;
Boolean batchOnProcessesing = false;
Boolean batchOnCompleted = false;
Boolean batchLongRunning = false;
controller.BatchJobStatus = 'Holding';
controller.executionStatusOfBatch();
controller.BatchJobStatus = 'Preparing';
controller.executionStatusOfBatch();
controller.BatchJobStatus = 'Queued';
controller.executionStatusOfBatch();
controller.BatchJobStatus = 'Processing';
controller.executionStatusOfBatch();
Test.stopTest();
controller.BatchJobStatus = 'Completed';
controller.executionStatusOfBatch();
List<Apexpages.Message> msgs = ApexPages.getMessages();
for(Apexpages.Message msg:msgs){
if (msg.getDetail().contains('Batch has been started execution please wait...')){
batchOnHold = true;
}
if (msg.getDetail().contains('Successfully initiated process to create Capital calls. \n Please followup with \'Capital calls Update Status\' & \'Capital calls Last Updated Date\' fields to know the status.')){
batchOnPreparing = true;
}
if (msg.getDetail().contains('Batch has been queued please wait for the batch to start execution...')){
batchOnQueued = true;
}
if (msg.getDetail().contains('Batch has started proccessing the records please wait while we show you the capital calls that are successfully created')){
batchOnProcessesing = true;
}
if (msg.getDetail().contains('Batch has finished creating capital calls successfully')){
batchOnCompleted = true;
}
if (msg.getDetail().contains('The server is experiencing unusually high traffic.This job is in queue and will be completed.')){
batchLongRunning = true;
}
}
system.assertEquals(true, batchLongRunning);
system.assertEquals(true, batchOnHold);
system.assertEquals(true, batchOnPreparing);
system.assertEquals(true, batchOnQueued);
system.assertEquals(true, batchOnProcessesing);
system.assertEquals(true, batchOnCompleted);
List<Capital_Call_Parent__c> parent = [Select Id,Capital_Call_Update_Status__c,Fund__c From Capital_Call_Parent__c];
system.assertEquals(2,controller.mapOfCapitalCallSuccess.size());
system.assertEquals(true,controller.getcapitalcallsuccessprev());
system.assertEquals(false,controller.getcapitalcallssuccessnxt());
system.assertEquals(1,controller.capitalSuccessCurrentPageNumber);
controller.nextCapitalCallSuccessList();
system.assertEquals(false,controller.getcapitalcallsuccessprev());
system.assertEquals(true,controller.getcapitalcallssuccessnxt());
system.assertEquals(2,controller.capitalSuccessCurrentPageNumber);
controller.previousCapitalCallSuccessList();
system.assertEquals(2,controller.mapOfFailureCapitalCommitments.size());
system.assertEquals(true,controller.getcapitalcallsfailureprev());
system.assertEquals(false,controller.getcapitalcallsfailurenxt());
system.assertEquals(1,controller.failureCapitalCommitCurrentPageNumber);
controller.nexttCapitalCallFailureList();
system.assertEquals(false,controller.getcapitalcallsfailureprev());
system.assertEquals(true,controller.getcapitalcallsfailurenxt());
system.assertEquals(2,controller.failureCapitalCommitCurrentPageNumber);
controller.previoustCapitalCallFailureList();
System.assertEquals(1, parent.size());
System.assertEquals(fund1.Id, parent[0].Fund__c);
List<Capital_Call__c> capitalCall1 = [SELECT Capital_Call_Parent__c,Capital_Call_Amount__c,Investments__c,Management_Fees__c,Expenses__c,Other__c,Capital_Commitment__c FROM Capital_Call__c WHERE Capital_Commitment__c = :capitalCommit1.Id];
System.assertEquals(1, capitalCall1.size());
System.assertEquals(parent[0].Id, capitalCall1[0].Capital_Call_Parent__c);
List<Capital_Call__c> capitalCall2 = [SELECT Capital_Call_Parent__c,Capital_Call_Amount__c,Investments__c,Management_Fees__c,Expenses__c,Other__c,Capital_Commitment__c FROM Capital_Call__c WHERE Capital_Commitment__c = :capitalCommit2.Id];
System.assertEquals(0, capitalCall2.size());
List<Capital_Call__c> capitalCall3 = [SELECT Capital_Call_Parent__c,Capital_Call_Amount__c,Investments__c,Management_Fees__c,Expenses__c,Other__c,Capital_Commitment__c FROM Capital_Call__c WHERE Capital_Commitment__c = :capitalCommit3.Id];
System.assertEquals(1, capitalCall3.size());
System.assertEquals(parent[0].Id, capitalCall3[0].Capital_Call_Parent__c);
List<Capital_Call__c> capitalCall4 = [SELECT Capital_Call_Parent__c,Capital_Call_Amount__c,Investments__c,Management_Fees__c,Expenses__c,Other__c,Capital_Commitment__c FROM Capital_Call__c WHERE Capital_Commitment__c = :capitalCommit4.Id];
System.assertEquals(0, capitalCall4.size());
List<Capital_Call__c> capitalCall5 = [SELECT Capital_Call_Parent__c,Capital_Call_Amount__c,Investments__c,Management_Fees__c,Expenses__c,Other__c,Capital_Commitment__c FROM Capital_Call__c WHERE Capital_Commitment__c = :capitalCommit5.Id];
System.assertEquals(1, capitalCall5.size());
System.assertEquals(parent[0].Id, capitalCall5[0].Capital_Call_Parent__c);
List<Capital_Call__c> capitalCall6 = [SELECT Capital_Call_Parent__c,Capital_Call_Amount__c,Investments__c,Management_Fees__c,Expenses__c,Other__c,Capital_Commitment__c FROM Capital_Call__c WHERE Capital_Commitment__c = :capitalCommit6.Id];
System.assertEquals(0, capitalCall6.size());
controller.returnToFund(); // returns page reference back to Fund
system.assertEquals(3,controller.sizeOfCapitalCommitmentsMap);
system.assertEquals(2,controller.sizeOfCapitalCallsSuccesssMap);
system.assertEquals(2,controller.sizeOfFailureCapitalCommitMap);
system.assertEquals('Completed',parent[0].Capital_Call_Update_Status__c);
system.assertEquals(3,controller.TotalNumberOfCapitalCallsProccessed);
system.assertEquals(3,controller.TotalNumberOfCapitalCallsFailed);
}
/*
* Test for batch of distribution with Aborted as status
*/
@IsTest
static void testBatchWithAbortedStatusForCapitalCalls(){
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
Account entity2 = [Select Id,Name from Account where Name='Test Entity LP 1'];
Account entity3 = [Select Id,Name from Account where Name='Test Entity LP 2'];
// Set up Capital Commitment 1:
Test.startTest();
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entity1.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entity2.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit2;
// Set up Capital Commitment 3:
Capital_Commitment__c capitalCommit3 = new Capital_Commitment__c(
LP_Entity__c = entity3.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit3;
fund1 = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(300.0, fund1.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund1);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.capitalCommitmentPageSize = 2;
controller.capitalCallPageSize = 2;
controller.callToRetrieveCommitments();
system.assertEquals(2,controller.mapOfCapitalCommitments.size());
system.assertEquals(1,controller.capitalCommitmentCurrentPageNumber);
system.assertEquals(true,controller.getprev());
system.assertEquals(false,controller.getnxt());
controller.nextCapitalCommitmentList();
system.assertEquals(2,controller.capitalCommitmentCurrentPageNumber);
system.assertEquals(false,controller.getprev());
system.assertEquals(true,controller.getnxt());
controller.previousCapitalCommitmenttList();
controller.next();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 300.0;
controller.next();
system.assertEquals(2,controller.mapOfCapitalCalls.size());
system.assertEquals(1,controller.capitalCallCurrentPageNumber);
controller.confirmAndSave();
AsyncApexJob batchJob = [SELECT Id, Status, JobItemsProcessed, TotalJobItems, NumberOfErrors ,CreatedDate,ExtendedStatus
FROM AsyncApexJob WHERE ID =: controller.BatchId ];
system.abortJob(controller.BatchId);
Test.stopTest();
controller.executionStatusOfBatch();
List<Capital_Call_Parent__c> parent = [Select Id,Capital_Call_Update_Status__c,Fund__c From Capital_Call_Parent__c];
System.assertEquals(1, parent.size());
System.assertEquals(fund1.Id, parent[0].Fund__c);
List<Distribution__c> listOfdistributions = [SELECT Distribution_Amount__c, Gain_Loss__c, Distribution_Parent__c FROM Distribution__c WHERE Distribution_Parent__c = :parent[0].Id];
System.assertEquals(0, listOfdistributions.size());
controller.returnToFund(); // returns page reference back to Fund
system.assertEquals(2,controller.sizeOfCapitalCommitmentsMap);
system.assertEquals('Aborted',parent[0].Capital_Call_Update_Status__c);
}
@isTest
static void testShowPopup() {
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entityLP = [Select Id,Name from Account where Name='Test Entity LP'];
// Set up Capital Commitment 1:
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 0.0
);
insert capitalCommit2;
Fund__c fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(400.0, fund.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund);
CapitalCallController controller = new CapitalCallController(sc);
test.startTest();
String fullName = 'Capital_Call__c.Import_Wizard_Fields';
Boolean success = true;
String field1 = 'Management_Fees__c';
String field2 = 'Expenses_Outside_of_Commitment__c';
MetadataServiceHelperMock mockImpl = new MetadataServiceHelperMock(fullName, success, field1,field2);
System.Test.setMock(WebServiceMock.class, mockImpl);
test.stopTest();
controller.showPopup();
System.assertEquals(true, controller.displayPopup);
System.assertNotEquals(null, controller.leftOptions);
System.assertNotEquals(null, controller.rightOptions);
}
@isTest
static void testClosePopup() {
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entityLP = [Select Id,Name from Account where Name='Test Entity LP'];
// Set up Capital Commitment 1:
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 0.0
);
insert capitalCommit2;
Fund__c fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(400.0, fund.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund);
CapitalCallController controller = new CapitalCallController(sc);
test.startTest();
String fullName = 'Capital_Call__c.Import_Wizard_Fields';
Boolean success = true;
String field1 = 'Management_Fees__c';
String field2 = 'Expenses_Outside_of_Commitment__c';
MetadataServiceHelperMock mockImpl = new MetadataServiceHelperMock(fullName, success,field1,field2);
System.Test.setMock(WebServiceMock.class, mockImpl);
test.stopTest();
controller.closePopup();
System.assertEquals(false, controller.displayPopUp);
}
@isTest
static void TestupdateFieldsOfFieldset() {
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entityLP = [Select Id,Name from Account where Name='Test Entity LP'];
// Set up Capital Commitment 1:
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 0.0
);
insert capitalCommit2;
Fund__c fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(400.0, fund.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund);
CapitalCallController controller = new CapitalCallController(sc);
test.startTest();
String fullName = 'Capital_Call__c.Import_Wizard_Fields';
Boolean success = true;
String field1 = 'Management_Fees__c';
String field2 = 'Expenses_Outside_of_Commitment__c';
MetadataServiceHelperMock mockImpl = new MetadataServiceHelperMock(fullName, success, field1,field2);
System.Test.setMock(WebServiceMock.class, mockImpl);
test.stopTest();
controller.showPopup();
controller.updateFieldsOfFieldset();
System.assertEquals(true, controller.updateFieldset);
System.assertEquals(1, controller.updateFieldsetcounter);
}
@isTest
static void testupdateFieldsOfFieldset_Failure() {
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entityLP = [Select Id,Name from Account where Name='Test Entity LP'];
// Set up Capital Commitment 1:
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 400.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entityLP.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 0.0
);
insert capitalCommit2;
Fund__c fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(400.0, fund.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund);
CapitalCallController controller = new CapitalCallController(sc);
test.startTest();
String fullName = 'Capital_Call__c.Import_Wizard_Fields';
Boolean success = false;
String field1 = 'Management_Fees__c';
String field2 = 'Expenses_Outside_of_Commitment__c';
MetadataServiceHelperMock mockImpl = new MetadataServiceHelperMock(fullName, success,field1,field2);
System.Test.setMock(WebServiceMock.class, mockImpl);
test.stopTest();
controller.showPopup();
controller.updateFieldsOfFieldset();
System.assertEquals(false, controller.updateFieldset);
}
//Test to check error message gets displayed on Capital Call
@isTest
static void testBatchForErrorMsgOnCapitalCalls(){
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
fund1.Capital_Calls_Update_Status__c = 'In Progress';
update fund1;
Test.startTest();
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
fund1 = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
ApexPages.StandardController sc = new ApexPages.StandardController(fund1);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.callToRetrieveCommitments();
List<ApexPages.Message> msgList = ApexPages.getMessages();
for(ApexPages.Message msg : ApexPages.getMessages()){
System.assertEquals(true, msg.getDetail().contains('A batch is already in progress! You cannot create new Capital Calls while the batch is in progress.'));
System.assertEquals(ApexPages.Severity.ERROR, msg.getSeverity());
}
}
@isTest
Static void testvalidateFieldValues_TRUE(){
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
Account entity2 = [Select Id,Name from Account where Name='Test Entity LP 1'];
Account entity3 = [Select Id,Name from Account where Name='Test Entity LP 2'];
// Set up Capital Commitment 1:
Test.startTest();
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entity1.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entity2.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit2;
// Set up Capital Commitment 3:
Capital_Commitment__c capitalCommit3 = new Capital_Commitment__c(
LP_Entity__c = entity3.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit3;
fund1 = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(300.0, fund1.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund1);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.capitalCommitmentPageSize = 2;
controller.capitalCallPageSize = 2;
controller.callToRetrieveCommitments();
system.assertEquals(2,controller.mapOfCapitalCommitments.size());
system.assertEquals(1,controller.capitalCommitmentCurrentPageNumber);
system.assertEquals(true,controller.getprev());
system.assertEquals(false,controller.getnxt());
controller.nextCapitalCommitmentList();
system.assertEquals(2,controller.capitalCommitmentCurrentPageNumber);
system.assertEquals(false,controller.getprev());
system.assertEquals(true,controller.getnxt());
controller.previousCapitalCommitmenttList();
controller.next();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 100.0;
controller.tempCall.Investments__c = 50.00;
controller.tempCall.Management_Fees__c = 60.00;
controller.tempCall.Expenses__c = 70.00;
controller.tempCall.Other__c = 80.00;
controller.isNullOrZeroCapCommitmentCheckbox = true;
controller.next();
Integer sizeOfCapitalCallsSaved = 0;
for (Integer pageNum : controller.mapOfCapitalCalls.keySet()) {
for (CapitalCallController.CapitalCallWrapper capCallRecord : controller.mapOfCapitalCalls.get(pageNum)) {
sizeOfCapitalCallsSaved = sizeOfCapitalCallsSaved+1;
}
}
system.assertEquals(2,controller.mapOfCapitalCalls.size());
system.assertEquals(1,controller.capitalCallCurrentPageNumber);
controller.confirmAndSave();
Test.stopTest();
system.assert(true,controller.isNullOrZeroCapCommitmentCheckbox);
List<Capital_Call_Parent__c> parent = [Select Id, Fund__c,(Select Id From Capital_Calls__r) From Capital_Call_Parent__c WHERE Id =:controller.parent.Id];
System.assertEquals(sizeOfCapitalCallsSaved, parent[0].Capital_Calls__r.size());
System.assertEquals(1, parent.size());
System.assertEquals(fund1.Id, parent[0].Fund__c);
}
@isTest
static void testvalidateFieldValues_withAllZerosTRUECase(){
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
Account entity2 = [Select Id,Name from Account where Name='Test Entity LP 1'];
Account entity3 = [Select Id,Name from Account where Name='Test Entity LP 2'];
// Set up Capital Commitment 1:
Test.startTest();
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entity1.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entity2.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit2;
// Set up Capital Commitment 3:
Capital_Commitment__c capitalCommit3 = new Capital_Commitment__c(
LP_Entity__c = entity3.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit3;
fund1 = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(300.0, fund1.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund1);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.capitalCommitmentPageSize = 2;
controller.capitalCallPageSize = 2;
controller.callToRetrieveCommitments();
system.assertEquals(2,controller.mapOfCapitalCommitments.size());
system.assertEquals(1,controller.capitalCommitmentCurrentPageNumber);
system.assertEquals(true,controller.getprev());
system.assertEquals(false,controller.getnxt());
controller.nextCapitalCommitmentList();
system.assertEquals(2,controller.capitalCommitmentCurrentPageNumber);
system.assertEquals(false,controller.getprev());
system.assertEquals(true,controller.getnxt());
controller.previousCapitalCommitmenttList();
controller.next();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 0.00;
controller.tempCall.Investments__c = 00.00;
controller.tempCall.Management_Fees__c = 00.00;
controller.tempCall.Expenses__c = 00.00;
controller.tempCall.Other__c = 00.00;
controller.isNullOrZeroCapCommitmentCheckbox = true;
controller.next();
Integer sizeOfCapitalCallsSaved = 0;
for (Integer pageNum : controller.mapOfCapitalCalls.keySet()) {
for (CapitalCallController.CapitalCallWrapper capCallRecord : controller.mapOfCapitalCalls.get(pageNum)) {
sizeOfCapitalCallsSaved = sizeOfCapitalCallsSaved+1;
}
}
controller.confirmAndSave();
Test.stopTest();
system.assert(true,controller.isNullOrZeroCapCommitmentCheckbox);
List<Capital_Call_Parent__c> parent = [Select Id, Fund__c,(Select Id From Capital_Calls__r) From Capital_Call_Parent__c WHERE Id =:controller.parent.Id];
System.assertNotEquals(sizeOfCapitalCallsSaved, parent[0].Capital_Calls__r.size());
System.assertEquals(1, parent.size());
System.assertEquals(fund1.Id, parent[0].Fund__c);
}
@isTest
Static void testvalidateFieldValues_withAllZerosFalseCase(){
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
Account entity2 = [Select Id,Name from Account where Name='Test Entity LP 1'];
Account entity3 = [Select Id,Name from Account where Name='Test Entity LP 2'];
// Set up Capital Commitment 1:
Test.startTest();
Capital_Commitment__c capitalCommit1 = new Capital_Commitment__c(
LP_Entity__c = entity1.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit1;
// Set up Capital Commitment 2:
Capital_Commitment__c capitalCommit2 = new Capital_Commitment__c(
LP_Entity__c = entity2.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit2;
// Set up Capital Commitment 3:
Capital_Commitment__c capitalCommit3 = new Capital_Commitment__c(
LP_Entity__c = entity3.Id,
Fund_Name__c = fund1.Id,
Capital_Commitment__c = 100.0
);
insert capitalCommit3;
fund1 = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(300.0, fund1.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund1);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.capitalCommitmentPageSize = 2;
controller.capitalCallPageSize = 2;
controller.callToRetrieveCommitments();
system.assertEquals(2,controller.mapOfCapitalCommitments.size());
system.assertEquals(1,controller.capitalCommitmentCurrentPageNumber);
system.assertEquals(true,controller.getprev());
system.assertEquals(false,controller.getnxt());
controller.nextCapitalCommitmentList();
system.assertEquals(2,controller.capitalCommitmentCurrentPageNumber);
system.assertEquals(false,controller.getprev());
system.assertEquals(true,controller.getnxt());
controller.previousCapitalCommitmenttList();
controller.next();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 0.0;
controller.tempCall.Investments__c = 0.00;
controller.tempCall.Management_Fees__c = 0.00;
controller.tempCall.Expenses__c = 0.00;
controller.tempCall.Other__c = 0.00;
controller.isNullOrZeroCapCommitmentCheckbox = false;
controller.next();
Integer sizeOfCapitalCallsSaved = 0;
for (Integer pageNum : controller.mapOfCapitalCalls.keySet()) {
for (CapitalCallController.CapitalCallWrapper capCallRecord : controller.mapOfCapitalCalls.get(pageNum)) {
sizeOfCapitalCallsSaved = sizeOfCapitalCallsSaved+1;
}
}
controller.confirmAndSave();
Test.stopTest();
system.assertEquals(false,controller.isNullOrZeroCapCommitmentCheckbox);
List<Capital_Call_Parent__c> parent = [Select Id, Fund__c,(Select Id From Capital_Calls__r) From Capital_Call_Parent__c WHERE Id =:controller.parent.Id];
System.assertEquals(sizeOfCapitalCallsSaved, parent[0].Capital_Calls__r.size());
System.assertEquals(1, parent.size());
System.assertEquals(fund1.Id, parent[0].Fund__c);
}
// Scenario 1 : Creating a fund allocation parent with allocType = 'LP/GP Split' with all the metrics allocated and rounding type as Half-Up
@isTest
static void testAllocationLPGPSplit_HalfUp(){
Fund__c fund1=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
Account entity2 = [Select Id,Name from Account where Name='Test Entity LP 1'];
Account entity3 = [Select Id,Name from Account where Name='Test Entity LP 2'];
Test.startTest();
Capital_Commitment__c capitalCommitment1 = TestObjectFactory.getCapitalCommitment(true, entity1.Id, fund1.Id);
Capital_Commitment__c capitalCommitment2 = TestObjectFactory.getCapitalCommitment(true, entity2.Id, fund1.Id);
Capital_Commitment__c capitalCommitment3 = TestObjectFactory.getCapitalCommitment(true, entity3.Id, fund1.Id);
ImportWizardSettings__c impWizSetting = new ImportWizardSettings__c();
impWizSetting.Enable_Allocation_Feature__c = true;
impWizSetting.Record_Insertion_Batch_Size__c = 100;
impWizSetting.Long_Running_Batch_Time_Threshold__c =35;
insert impWizSetting;
List<String> fundAllocFieldsList = new List<String>{'Capital Call Amount','Management Fees','Expenses','Other','Late Admission Interest','Investments'};
List<Fund_Allocation_Parent__c> fundAllocParentList = [SELECT Id, Name,Allocation_Type__c,Fund_to_Allocate__c, Metrics_to_Allocate__c,Rounding_Type__c FROM Fund_Allocation_Parent__c WHERE Allocation_Type__c = 'LP/GP Split' AND Rounding_Type__c = 'Half Up' LIMIT 1];
Map<String,String> metricToFundAllocMap = new Map<String,String>{'Capital Call Amount' => fundAllocParentList[0].Id, 'Management Fees' => fundAllocParentList[0].Id,'Expenses' => fundAllocParentList[0].Id,'Other' => fundAllocParentList[0].Id,'Late Admission Interest' => fundAllocParentList[0].Id,'Investments' => fundAllocParentList[0].Id};
Fund_Allocation__c fundAlloc = TestObjectFactory.getTestFundAllocation(true,fundAllocParentList[0],fund1);
Fund_Allocation_Member__c fundAllocMember1 = TestObjectFactory.getTestFundAllocationMember(true,fundAlloc,fundAllocParentList[0],capitalCommitment1);
Fund_Allocation_Member__c fundAllocMember2 = TestObjectFactory.getTestFundAllocationMember(true,fundAlloc,fundAllocParentList[0],capitalCommitment2);
Fund_Allocation_Member__c fundAllocMember3 = TestObjectFactory.getTestFundAllocationMember(true,fundAlloc,fundAllocParentList[0],capitalCommitment3);
List<Allocation_Settings__c> allocSettingList = [Select Id,Name,Field_Label_Name__c,Allocation_Parent_Id__c from Allocation_Settings__c];
List<Allocation_Settings__c> updatedAllocSetttingList = new List<Allocation_Settings__c>();
for(Allocation_Settings__c alloc : allocSettingList){
alloc.Allocation_Parent_Id__c = fundAllocParentList[0].Id;
updatedAllocSetttingList.add(alloc);
}
update updatedAllocSetttingList;
fund1 = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(300.0, fund1.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund1);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.capitalCommitmentPageSize = 2;
controller.capitalCallPageSize = 2;
controller.callToRetrieveCommitments();
controller.nextCapitalCommitmentList();
controller.previousCapitalCommitmenttList();
controller.next();
controller.assignmentCallToAllocationSettings();
controller.defaultProRataFlag = false;
controller.setDefaultCalculationToMap();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 115.00;
controller.tempCall.Investments__c = 215.00;
controller.tempCall.Management_Fees__c = 315.00;
controller.tempCall.Expenses__c = 415.00;
controller.tempCall.Other__c = 515.00;
controller.tempCall.Late_Admission_Interest__c = 615.00;
controller.isNullOrZeroCapCommitmentCheckbox = true;
controller.next();
controller.getCurrentStepName();
Integer sizeOfCapitalCallsSaved = 0;
System.debug('controller.mapOfCapitalCalls.keySet(): '+controller.mapOfCapitalCalls.keySet());
for (Integer pageNum : controller.mapOfCapitalCalls.keySet()) {
for (CapitalCallController.CapitalCallWrapper capCallRecord : controller.mapOfCapitalCalls.get(pageNum)) {
sizeOfCapitalCallsSaved = sizeOfCapitalCallsSaved+1;
}
}
controller.closeAllocSettPopup();
controller.confirmAndSave();
controller.saveSettings();
Test.stopTest();
system.assert(true,controller.isNullOrZeroCapCommitmentCheckbox);
List<Capital_Call_Parent__c> parent = [Select Id, Fund__c,(Select Id,Management_Fees__c,Late_Admission_Interest__c,Capital_Call_Amount__c,Expenses__c,Other__c,Investments__c From Capital_Calls__r) From Capital_Call_Parent__c WHERE Id =:controller.parent.Id];
for(Capital_Call__c capCall : parent[0].Capital_Calls__r){
System.assertEquals(84.00,capCall.Management_Fees__c);
System.assertEquals(30.67,capCall.Capital_Call_Amount__c);
System.assertEquals(57.33,capCall.Investments__c);
System.assertEquals(137.33,capCall.Other__c);
System.assertEquals(110.67,capCall.Expenses__c);
System.assertEquals(164,capCall.Late_Admission_Interest__c);
}
}
//Scenario2 : Creating a fund allocation parent with allocType = 'LP/GP Split Adjustable' with all the metrics allocated and rounding type as Half-Down
@isTest
static void testAllocationLPGPSplitAdjustable_HalfDown(){
Fund__c fund1 = [Select Id,Name from Fund__c where Name='Test Fund'];
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
Account entity2 = [Select Id,Name from Account where Name='Test Entity LP 1'];
Account entity3 = [Select Id,Name from Account where Name='Test Entity LP 2'];
Test.startTest();
Capital_Commitment__c capitalCommitment1 = TestObjectFactory.getCapitalCommitment(true, entity1.Id, fund1.Id);
Capital_Commitment__c capitalCommitment2 = TestObjectFactory.getCapitalCommitment(true, entity2.Id, fund1.Id);
Capital_Commitment__c capitalCommitment3 = TestObjectFactory.getCapitalCommitment(true, entity3.Id, fund1.Id);
ImportWizardSettings__c impWizSetting = new ImportWizardSettings__c();
impWizSetting.Enable_Allocation_Feature__c = true;
impWizSetting.Record_Insertion_Batch_Size__c = 100;
impWizSetting.Long_Running_Batch_Time_Threshold__c =35;
insert impWizSetting;
List<String> fundAllocFieldsList = new List<String>{'Capital Call Amount','Management Fees','Expenses','Other','Late Admission Interest','Investments'};
List<Fund_Allocation_Parent__c> fundAllocParentList = [SELECT Id, Name,Allocation_Type__c,Fund_to_Allocate__c, Metrics_to_Allocate__c,Rounding_Type__c FROM Fund_Allocation_Parent__c WHERE Allocation_Type__c = 'LP/GP Adjustable Split' AND Rounding_Type__c = 'Half Down' LIMIT 1];
Map<String,String> metricToFundAllocMap = new Map<String,String>{'Capital Call Amount' => fundAllocParentList[0].Id, 'Management Fees' => fundAllocParentList[0].Id,'Expenses' => fundAllocParentList[0].Id,'Other' => fundAllocParentList[0].Id,'Late Admission Interest' => fundAllocParentList[0].Id,'Investments' => fundAllocParentList[0].Id};
Fund_Allocation__c fundAlloc = TestObjectFactory.getTestFundAllocation(true,fundAllocParentList[0],fund1);
Fund_Allocation_Member__c fundAllocMember1 = TestObjectFactory.getTestFundAllocationMember(true,fundAlloc,fundAllocParentList[0],capitalCommitment1);
Fund_Allocation_Member__c fundAllocMember2 = TestObjectFactory.getTestFundAllocationMember(true,fundAlloc,fundAllocParentList[0],capitalCommitment2);
Fund_Allocation_Member__c fundAllocMember3 = TestObjectFactory.getTestFundAllocationMember(true,fundAlloc,fundAllocParentList[0],capitalCommitment3);
List<Allocation_Settings__c> allocSettingList = [Select Id,Name,Field_Label_Name__c,Allocation_Parent_Id__c from Allocation_Settings__c];
List<Allocation_Settings__c> updatedAllocSetttingList = new List<Allocation_Settings__c>();
for(Allocation_Settings__c alloc : allocSettingList){
alloc.Allocation_Parent_Id__c = fundAllocParentList[0].Id;
updatedAllocSetttingList.add(alloc);
}
update updatedAllocSetttingList;
fund1 = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(300.0, fund1.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund1);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.capitalCommitmentPageSize = 2;
controller.capitalCallPageSize = 2;
controller.callToRetrieveCommitments();
controller.nextCapitalCommitmentList();
controller.previousCapitalCommitmenttList();
controller.next();
controller.assignmentCallToAllocationSettings();
controller.defaultProRataFlag = false;
controller.setDefaultCalculationToMap();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 115.00;
controller.tempCall.Investments__c = 215.00;
controller.tempCall.Management_Fees__c = 315.00;
controller.tempCall.Expenses__c = 415.00;
controller.tempCall.Other__c = 515.00;
controller.tempCall.Late_Admission_Interest__c = 615.00;
controller.isNullOrZeroCapCommitmentCheckbox = true;
controller.next();
controller.getCurrentStepName();
Integer sizeOfCapitalCallsSaved = 0;
System.debug('controller.mapOfCapitalCalls.keySet(): '+controller.mapOfCapitalCalls.keySet());
for (Integer pageNum : controller.mapOfCapitalCalls.keySet()) {
for (CapitalCallController.CapitalCallWrapper capCallRecord : controller.mapOfCapitalCalls.get(pageNum)) {
sizeOfCapitalCallsSaved = sizeOfCapitalCallsSaved+1;
}
}
controller.closeAllocSettPopup();
controller.confirmAndSave();
controller.saveSettings();
Test.stopTest();
system.assert(true,controller.isNullOrZeroCapCommitmentCheckbox);
List<Capital_Call_Parent__c> parent = [Select Id, Fund__c,(Select Id,Management_Fees__c,Capital_Call_Amount__c,Expenses__c,Other__c,Investments__c From Capital_Calls__r) From Capital_Call_Parent__c WHERE Id =:controller.parent.Id];
for(Capital_Call__c capCall : parent[0].Capital_Calls__r){
System.assertEquals(78.75,capCall.Management_Fees__c);
System.assertEquals(28.75,capCall.Capital_Call_Amount__c);
System.assertEquals(103.75,capCall.Expenses__c);
System.assertEquals(128.75,CapCall.Other__c);
System.assertEquals(53.75,CapCall.Investments__c);
System.assertEquals(153.75,CapCall.Late_Admission_Interest__c);
}
}
//Scenario3 : Creating a fund allocation parent with allocType = 'Fund Pro Rata' with all the metrics allocated and rounding type as Half-Up
@isTest
static void testAllocationFundProRata_HalfUp(){
Fund__c fund1 = [Select Id,Name from Fund__c where Name='Test Fund'];
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
Account entity2 = [Select Id,Name from Account where Name='Test Entity LP 1'];
Account entity3 = [Select Id,Name from Account where Name='Test Entity LP 2'];
Test.startTest();
Capital_Commitment__c capitalCommitment1 = TestObjectFactory.getCapitalCommitment(true, entity1.Id, fund1.Id);
Capital_Commitment__c capitalCommitment2 = TestObjectFactory.getCapitalCommitment(true, entity2.Id, fund1.Id);
Capital_Commitment__c capitalCommitment3 = TestObjectFactory.getCapitalCommitment(true, entity3.Id, fund1.Id);
ImportWizardSettings__c impWizSetting = new ImportWizardSettings__c();
impWizSetting.Enable_Allocation_Feature__c = true;
impWizSetting.Record_Insertion_Batch_Size__c = 100;
impWizSetting.Long_Running_Batch_Time_Threshold__c =35;
insert impWizSetting;
List<String> fundAllocFieldsList = new List<String>{'Capital Call Amount','Management Fees','Expenses','Other','Late Admission Interest','Investments'};
System.debug('parentList: '+[SELECT Id, Name,Allocation_Type__c,Fund_to_Allocate__c, Metrics_to_Allocate__c,Rounding_Type__c FROM Fund_Allocation_Parent__c WHERE Allocation_Type__c = 'Fund Pro Rata' AND Rounding_Type__c = 'Half Up' LIMIT 1]);
List<Fund_Allocation_Parent__c> fundAllocParentList = [SELECT Id, Name,Allocation_Type__c,Fund_to_Allocate__c, Metrics_to_Allocate__c,Rounding_Type__c FROM Fund_Allocation_Parent__c WHERE Allocation_Type__c = 'Fund Pro Rata' AND Rounding_Type__c = 'Half Up' LIMIT 1];
Map<String,String> metricToFundAllocMap = new Map<String,String>{'Capital Call Amount' => fundAllocParentList[0].Id, 'Management Fees' => fundAllocParentList[0].Id,'Expenses' => fundAllocParentList[0].Id,'Other' => fundAllocParentList[0].Id,'Late Admission Interest' => fundAllocParentList[0].Id,'Investments' => fundAllocParentList[0].Id};
Fund_Allocation__c fundAlloc = TestObjectFactory.getTestFundAllocation(true,fundAllocParentList[0],fund1);
Fund_Allocation_Member__c fundAllocMember1 = TestObjectFactory.getTestFundAllocationMember(true,fundAlloc,fundAllocParentList[0],capitalCommitment1);
Fund_Allocation_Member__c fundAllocMember2 = TestObjectFactory.getTestFundAllocationMember(true,fundAlloc,fundAllocParentList[0],capitalCommitment2);
Fund_Allocation_Member__c fundAllocMember3 = TestObjectFactory.getTestFundAllocationMember(true,fundAlloc,fundAllocParentList[0],capitalCommitment3);
List<Allocation_Settings__c> allocSettingList = [Select Id,Name,Field_Label_Name__c,Allocation_Parent_Id__c from Allocation_Settings__c];
List<Allocation_Settings__c> updatedAllocSetttingList = new List<Allocation_Settings__c>();
for(Allocation_Settings__c alloc : allocSettingList){
alloc.Allocation_Parent_Id__c = fundAllocParentList[0].Id;
updatedAllocSetttingList.add(alloc);
}
update updatedAllocSetttingList;
fund1 = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(300.0, fund1.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund1);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.enableAllocationFeature = true;
controller.capitalCommitmentPageSize = 2;
controller.capitalCallPageSize = 2;
controller.callToRetrieveCommitments();
controller.nextCapitalCommitmentList();
controller.previousCapitalCommitmenttList();
controller.next();
controller.assignmentCallToAllocationSettings();
controller.defaultProRataFlag = false;
controller.setDefaultCalculationToMap();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 115.00;
controller.tempCall.Investments__c = 215.00;
controller.tempCall.Management_Fees__c = 315.00;
controller.tempCall.Expenses__c = 415.00;
controller.tempCall.Other__c = 515.00;
controller.tempCall.Late_Admission_Interest__c = 615.00;
controller.isNullOrZeroCapCommitmentCheckbox = true;
controller.next();
controller.getCurrentStepName();
Integer sizeOfCapitalCallsSaved = 0;
System.debug('controller.mapOfCapitalCalls.keySet(): '+controller.mapOfCapitalCalls.keySet());
for (Integer pageNum : controller.mapOfCapitalCalls.keySet()) {
for (CapitalCallController.CapitalCallWrapper capCallRecord : controller.mapOfCapitalCalls.get(pageNum)) {
sizeOfCapitalCallsSaved = sizeOfCapitalCallsSaved+1;
}
}
controller.closeAllocSettPopup();
controller.confirmAndSave();
controller.saveSettings();
Test.stopTest();
List<Capital_Call_Parent__c> parent = [Select Id, Fund__c,(Select Id,Management_Fees__c,Capital_Call_Amount__c,Expenses__c,Other__c,Investments__c,Late_Admission_Interest__c From Capital_Calls__r) From Capital_Call_Parent__c WHERE Id =:controller.parent.Id];
for(Capital_Call__c capCall : parent[0].Capital_Calls__r){
System.assertEquals(105.00,capCall.Management_Fees__c);
System.assertEquals(38.33,capCall.Capital_Call_Amount__c);
System.assertEquals(138.33,capCall.Expenses__c);
System.assertEquals(171.67,CapCall.Other__c);
System.assertEquals(71.67,CapCall.Investments__c);
System.assertEquals(205.00,CapCall.Late_Admission_Interest__c);
}
}
//Scenario 4: Creating a fund allocation parent with allocType = 'Custom' and rounding type as 'Half down'
@isTest
static void testAllocationCustom_HalfDown(){
Fund__c fund1 = [Select Id,Name from Fund__c where Name='Test Fund'];
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
Account entity2 = [Select Id,Name from Account where Name='Test Entity LP 1'];
Account entity3 = [Select Id,Name from Account where Name='Test Entity LP 2'];
Test.startTest();
Capital_Commitment__c capitalCommitment1 = TestObjectFactory.getCapitalCommitment(true, entity1.Id, fund1.Id);
Capital_Commitment__c capitalCommitment2 = TestObjectFactory.getCapitalCommitment(true, entity2.Id, fund1.Id);
Capital_Commitment__c capitalCommitment3 = TestObjectFactory.getCapitalCommitment(true, entity3.Id, fund1.Id);
ImportWizardSettings__c impWizSetting = new ImportWizardSettings__c();
impWizSetting.Enable_Allocation_Feature__c = true;
impWizSetting.Record_Insertion_Batch_Size__c = 100;
impWizSetting.Long_Running_Batch_Time_Threshold__c =35;
insert impWizSetting;
List<String> fundAllocFieldsList = new List<String>{'Capital Call Amount','Management Fees','Expenses','Other','Late Admission Interest','Investments'};
List<Fund_Allocation_Parent__c> fundAllocParentList = [SELECT Id, Name,Allocation_Type__c,Fund_to_Allocate__c, Metrics_to_Allocate__c,Rounding_Type__c FROM Fund_Allocation_Parent__c WHERE Allocation_Type__c = 'Fund Pro Rata' AND Rounding_Type__c = 'Half Up' LIMIT 1];
Map<String,String> metricToFundAllocMap = new Map<String,String>{'Capital Call Amount' => fundAllocParentList[0].Id, 'Management Fees' => fundAllocParentList[0].Id,'Expenses' => fundAllocParentList[0].Id,'Other' => fundAllocParentList[0].Id,'Late Admission Interest' => fundAllocParentList[0].Id,'Investments' => fundAllocParentList[0].Id};
Fund_Allocation__c fundAlloc = TestObjectFactory.getTestFundAllocation(true,fundAllocParentList[0],fund1);
Fund_Allocation_Member__c fundAllocMember1 = TestObjectFactory.getTestFundAllocationMember(true,fundAlloc,fundAllocParentList[0],capitalCommitment1);
Fund_Allocation_Member__c fundAllocMember2 = TestObjectFactory.getTestFundAllocationMember(true,fundAlloc,fundAllocParentList[0],capitalCommitment2);
Fund_Allocation_Member__c fundAllocMember3 = TestObjectFactory.getTestFundAllocationMember(true,fundAlloc,fundAllocParentList[0],capitalCommitment3);
List<Allocation_Settings__c> allocSettingList = [Select Id,Name,Field_Label_Name__c,Allocation_Parent_Id__c from Allocation_Settings__c];
List<Allocation_Settings__c> updatedAllocSetttingList = new List<Allocation_Settings__c>();
for(Allocation_Settings__c alloc : allocSettingList){
alloc.Allocation_Parent_Id__c = fundAllocParentList[0].Id;
updatedAllocSetttingList.add(alloc);
}
update updatedAllocSetttingList;
fund1 = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(300.0, fund1.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund1);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.capitalCommitmentPageSize = 2;
controller.capitalCallPageSize = 2;
controller.callToRetrieveCommitments();
controller.nextCapitalCommitmentList();
controller.previousCapitalCommitmenttList();
controller.next();
controller.assignmentCallToAllocationSettings();
controller.defaultProRataFlag = false;
controller.setDefaultCalculationToMap();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 115.00;
controller.tempCall.Investments__c = 215.00;
controller.tempCall.Management_Fees__c = 315.00;
controller.tempCall.Expenses__c = 415.00;
controller.tempCall.Other__c = 515.00;
controller.tempCall.Late_Admission_Interest__c = 615.00;
controller.isNullOrZeroCapCommitmentCheckbox = true;
controller.next();
controller.getCurrentStepName();
Integer sizeOfCapitalCallsSaved = 0;
System.debug('controller.mapOfCapitalCalls.keySet(): '+controller.mapOfCapitalCalls.keySet());
for (Integer pageNum : controller.mapOfCapitalCalls.keySet()) {
for (CapitalCallController.CapitalCallWrapper capCallRecord : controller.mapOfCapitalCalls.get(pageNum)) {
sizeOfCapitalCallsSaved = sizeOfCapitalCallsSaved+1;
}
}
controller.closeAllocSettPopup();
controller.confirmAndSave();
controller.saveSettings();
Test.stopTest();
List<Capital_Call_Parent__c> parent = [Select Id, Fund__c,(Select Id,Management_Fees__c,Capital_Call_Amount__c,Expenses__c,Other__c,Investments__c,Late_Admission_Interest__c From Capital_Calls__r) From Capital_Call_Parent__c WHERE Id =:controller.parent.Id];
Integer temp = 1;
for(Capital_Call__c capCall: parent[0].Capital_Calls__r)
if(temp == 1){
System.assertEquals(85.05,capCall.Management_Fees__c);
System.assertEquals(31.05,parent[0].Capital_Calls__r[0].Capital_Call_Amount__c);
System.assertEquals(112.05,parent[0].Capital_Calls__r[0].Expenses__c);
System.assertEquals(139.05,parent[0].Capital_Calls__r[0].Other__c);
System.assertEquals(58.05,parent[0].Capital_Calls__r[0].Investments__c);
System.assertEquals(166.05,parent[0].Capital_Calls__r[0].Late_Admission_Interest__c);
temp+=1;
}else if(temp == 2){
System.assertEquals(127.57,parent[0].Capital_Calls__r[1].Management_Fees__c);
System.assertEquals(46.57,parent[0].Capital_Calls__r[1].Capital_Call_Amount__c);
System.assertEquals(168.07,parent[0].Capital_Calls__r[1].Expenses__c);
System.assertEquals(208.57,parent[0].Capital_Calls__r[1].Other__c);
System.assertEquals(87.07,parent[0].Capital_Calls__r[1].Investments__c);
System.assertEquals(249.08,parent[0].Capital_Calls__r[1].Late_Admission_Interest__c);
temp+=1;
}else if(temp == 3){
System.assertEquals(42.52,parent[0].Capital_Calls__r[2].Management_Fees__c);
System.assertEquals(15.52,parent[0].Capital_Calls__r[2].Capital_Call_Amount__c);
System.assertEquals(56.02,parent[0].Capital_Calls__r[2].Expenses__c);
System.assertEquals(69.52,parent[0].Capital_Calls__r[2].Other__c);
System.assertEquals(29.02,parent[0].Capital_Calls__r[2].Investments__c);
System.assertEquals(83.038,parent[0].Capital_Calls__r[2].Late_Admission_Interest__c);
}
}
//Scenario5 : Testing the functionality of allocations using Csv method
@IsTest
static void csvForAllocationsTest() {
Fund__c fund=[Select Id,Name from Fund__c where Name='Test Fund'];
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
Account entity2 = [Select Id,Name from Account where Name='Test Entity LP 1'];
Account entity3 = [Select Id,Name from Account where Name='Test Entity LP 2'];
Capital_Commitment__c capitalCommitment1 = TestObjectFactory.getCapitalCommitment(true, entity1.Id, fund.Id);
Capital_Commitment__c capitalCommitment2 = TestObjectFactory.getCapitalCommitment(true, entity2.Id, fund.Id);
Capital_Commitment__c capitalCommitment3 = TestObjectFactory.getCapitalCommitment(true, entity3.Id, fund.Id);
ImportWizardSettings__c impWizSetting = new ImportWizardSettings__c();
impWizSetting.Enable_Allocation_Feature__c = true;
impWizSetting.Record_Insertion_Batch_Size__c = 100;
impWizSetting.Long_Running_Batch_Time_Threshold__c =35;
insert impWizSetting;
Test.startTest();
List<String> fundAllocFieldsList = new List<String>{'Capital Call Amount','Management Fees','Expenses','Other','Late Admission Interest','Investments'};
List<Fund_Allocation_Parent__c> fundAllocParentList = [SELECT Id, Name,Allocation_Type__c,Fund_to_Allocate__c, Metrics_to_Allocate__c,Rounding_Type__c FROM Fund_Allocation_Parent__c WHERE Allocation_Type__c = 'LP/GP Split' AND Rounding_Type__c = 'Half Up' LIMIT 1];
Map<String,String> metricToFundAllocMap = new Map<String,String>{'Capital Call Amount' => fundAllocParentList[0].Id, 'Management Fees' => fundAllocParentList[0].Id,'Expenses' => fundAllocParentList[0].Id,'Other' => fundAllocParentList[0].Id,'Late Admission Interest' => fundAllocParentList[0].Id,'Investments' => fundAllocParentList[0].Id};
fund = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund.Id];
final ApexPages.StandardController sc = new ApexPages.StandardController(fund);
final CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.capitalCommitmentPageSize = 2;
controller.capitalCallPageSize = 2;
controller.callToRetrieveCommitments();
controller.nextCapitalCommitmentList();
controller.previousCapitalCommitmenttList();
controller.next();
controller.assignmentCallToAllocationSettings();
controller.defaultProRataFlag = false;
controller.setDefaultCalculationToMap();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 115.00;
controller.tempCall.Investments__c = 215.00;
controller.tempCall.Management_Fees__c = 315.00;
controller.tempCall.Expenses__c = 415.00;
controller.tempCall.Other__c = 515.00;
controller.tempCall.Late_Admission_Interest__c = 615.00;
controller.isNullOrZeroCapCommitmentCheckbox = true;
controller.next();
controller.fileBody = Blob.valueOf(
'Investment Vehicle,Capital Call Amount,Investments,Management Fees,Expenses,Other,Late Admission Interest,Due Date\n'+
'Investment Vehicle 1,30.67,57.33,84.00,110.67,137.33,164.00\n'+
'Investment Vehicle 2,30.67,57.33,84.00,110.67,137.33,164.00\n'+
'Investment Vehicle 3,30.67,57.33,84.00,110.67,137.33,164.00\n'
);
controller.processCSV();
controller.confirmAndSave();
Test.stopTest();
}
@isTest static void testAllocation_withDefaultProRataFlagTrue(){
Fund__c fund1 = [Select Id,Name from Fund__c where Name='Test Fund'];
Account entity1 = [Select Id,Name from Account where Name='Test Entity LP'];
Account entity2 = [Select Id,Name from Account where Name='Test Entity LP 1'];
Account entity3 = [Select Id,Name from Account where Name='Test Entity LP 2'];
Test.startTest();
Capital_Commitment__c capitalCommitment1 = TestObjectFactory.getCapitalCommitment(true, entity1.Id, fund1.Id);
Capital_Commitment__c capitalCommitment2 = TestObjectFactory.getCapitalCommitment(true, entity2.Id, fund1.Id);
Capital_Commitment__c capitalCommitment3 = TestObjectFactory.getCapitalCommitment(true, entity3.Id, fund1.Id);
ImportWizardSettings__c impWizSetting = new ImportWizardSettings__c();
impWizSetting.Enable_Allocation_Feature__c = true;
impWizSetting.Record_Insertion_Batch_Size__c = 100;
impWizSetting.Long_Running_Batch_Time_Threshold__c =35;
insert impWizSetting;
List<Allocation_Settings__c> allocSettingList = [Select Id,Name,Field_Label_Name__c,Allocation_Parent_Id__c from Allocation_Settings__c where Field_Label_Name__c = 'Other'];
allocSettingList[0].Name = 'Test_Other';
Update allocSettingList;
List<String> fundAllocFieldsList = new List<String>{'Capital Call Amount','Management Fees','Expenses','Other','Late Admission Interest','Investments'};
Map<String,String> metricToFundAllocMap = new Map<String,String>{'Capital Call Amount' => 'Pro-Rata', 'Management Fees' => 'Pro-Rata','Expenses' => 'Pro-Rata','Other' => 'Pro-Rata','Late Admission Interest' => 'Pro-Rata','Investments' => 'Pro-Rata'};
fund1 = [SELECT Total_Committed_Capital__c FROM Fund__c WHERE Id = :fund1.Id];
System.assertEquals(300.0, fund1.Total_Committed_Capital__c);
ApexPages.StandardController sc = new ApexPages.StandardController(fund1);
CapitalCallController controller = new CapitalCallController(sc);
controller.init();
controller.enableAllocationFeature = true;
controller.capitalCommitmentPageSize = 2;
controller.capitalCallPageSize = 2;
controller.callToRetrieveCommitments();
controller.nextCapitalCommitmentList();
controller.previousCapitalCommitmenttList();
controller.next();
controller.assignmentCallToAllocationSettings();
controller.defaultProRataFlag = true;
controller.setDefaultCalculationToMap();
controller.tempCall.Due_Date__c = Date.today();
controller.tempCall.Capital_Call_Amount__c = 115.00;
controller.tempCall.Investments__c = 215.00;
controller.tempCall.Management_Fees__c = 315.00;
controller.tempCall.Expenses__c = 415.00;
controller.tempCall.Other__c = 515.00;
controller.tempCall.Late_Admission_Interest__c = 615.00;
controller.isNullOrZeroCapCommitmentCheckbox = true;
controller.next();
controller.getCurrentStepName();
Integer sizeOfCapitalCallsSaved = 0;
System.debug('controller.mapOfCapitalCalls.keySet(): '+controller.mapOfCapitalCalls.keySet());
for (Integer pageNum : controller.mapOfCapitalCalls.keySet()) {
for (CapitalCallController.CapitalCallWrapper capCallRecord : controller.mapOfCapitalCalls.get(pageNum)) {
sizeOfCapitalCallsSaved = sizeOfCapitalCallsSaved+1;
}
}
controller.closeAllocSettPopup();
controller.confirmAndSave();
controller.saveSettings();
Test.stopTest();
List<Capital_Call_Parent__c> parent = [Select Id, Fund__c,(Select Id,Management_Fees__c,Capital_Call_Amount__c,Expenses__c,Other__c,Investments__c,Late_Admission_Interest__c From Capital_Calls__r) From Capital_Call_Parent__c WHERE Id =:controller.parent.Id];
for(Capital_Call__c capCall : parent[0].Capital_Calls__r){
System.assertEquals(105.00,capCall.Management_Fees__c);
System.assertEquals(38.33,capCall.Capital_Call_Amount__c);
System.assertEquals(138.33,capCall.Expenses__c);
System.assertEquals(171.67,CapCall.Other__c);
System.assertEquals(71.67,CapCall.Investments__c);
System.assertEquals(205.00,CapCall.Late_Admission_Interest__c);
}
}
}Editor is loading...