0% found this document useful (0 votes)
9 views11 pages

New 2

The document outlines the test class 'UpdateAccountToMatchBillingTest' designed to validate the functionality of the 'UpdateAccountToMatchBilling' class, which is triggered by account updates. It includes multiple test methods to assess various operations such as account creation, updates, deletions, and processing billing updates. The tests ensure that the expected outcomes align with the actual results, confirming the integrity of the account management processes within the system.

Uploaded by

abhishek kale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

New 2

The document outlines the test class 'UpdateAccountToMatchBillingTest' designed to validate the functionality of the 'UpdateAccountToMatchBilling' class, which is triggered by account updates. It includes multiple test methods to assess various operations such as account creation, updates, deletions, and processing billing updates. The tests ensure that the expected outcomes align with the actual results, confirming the integrity of the account management processes within the system.

Uploaded by

abhishek kale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 11

/

***********************************************************************OPSORG******
******************************************************
* Name of class: UpdateAccountToMatchBillingTest cp
* Purpose: To test the class UpdateAccountToMatchBilling which is excuted by an
account trigger.
*********************
*********************

Author || Date || Change || Description of change


C.Charlton July 2014 Initial Development

************************************************************************/

@isTest
public class UpdateAccountToMatchBillingTest {
private static RecordType createTestRecordType() {

RecordType recordType=new RecordType(


SObjectType = 'Account',
DeveloperName = 'TestRecordType',
Name = 'Test RecordType'

);
return recordType;
}
static testMethod void testProcessAccount(){
List<Legal_entities__c> testBillingEntities = new
List<Legal_entities__c>();
List<Account> testAccounts = new List<Account>();
Map<Id, Legal_entities__c> beforeUpdatebillingEntityData = new Map<Id,
Legal_entities__c>();
Country__c country = new Country__c(Name = 'United States');
insert country;
for (Integer i = 1; i <= 5; i++) {
Account acc = new Account(Name = 'Test Account ' +
i,RegAddrCountry__c=country.id);
testAccounts.add(acc);

Legal_entities__c le = new Legal_entities__c(


Name = 'Test LE ' + i,
Parent__c = acc.Id,
Status_Miro__c = 'Old Status'
);
testBillingEntities.add(le);
beforeUpdatebillingEntityData.put(le.Id, le);
}

insert testAccounts;
insert testBillingEntities;
for (Legal_entities__c le : testBillingEntities) {
le.Status_Miro__c = 'New Status';
}

test.startTest();
UpdateAccountToMatchBilling updateAccountInstance=new
UpdateAccountToMatchBilling();
updateAccountInstance.processAccountStatusUpdate(testBillingEntities,
beforeUpdatebillingEntityData);
test.stopTest();

List<Account> updatedAccounts = [SELECT Id, Account_status__c FROM Account


WHERE Id IN :testAccounts];
system.debug('Updated accounts'+updatedAccounts);
system.debug('Updated accounts'+updatedAccounts.size());

System.assertEquals(5, updatedAccounts.size(), 'All Accounts should be


updated');
for (Account acc : updatedAccounts) {

}
}
static testmethod void testsampledata(){
test.starttest();
UpdateAccountToMatchBilling updateAccountInstance=new
UpdateAccountToMatchBilling();
updateAccountInstance.createSampleData();
List<Account>accounts=[select id from account];
system.assertEquals(10,accounts.size());
List<Legal_Entities__c>legalentities=[select id from Legal_Entities__c];
system.assertEquals(10,legalentities.size());
test.stoptest();
}
static testmethod void testCreateAccount() {
test.starttest();
UpdateAccountToMatchBilling updateAccountInstance=new
UpdateAccountToMatchBilling();
updateAccountInstance.createAccount('Test Account');
Integer count = [SELECT COUNT() FROM Account WHERE Name = 'Test Account'];
System.assertEquals(1, count);
test.stoptest();
}
static testmethod void testUpdateAccountName() {
Account testAccount = new Account(Name = 'Old Name');
insert testAccount;
test.starttest();
UpdateAccountToMatchBilling updateAccountInstance=new
UpdateAccountToMatchBilling();
updateAccountInstance.updateAccountName(testAccount.Id, 'New Name');
test.stoptest();
Account updatedAccount = [SELECT Name FROM Account WHERE Id
= :testAccount.Id LIMIT 1];
System.assertEquals('New Name', updatedAccount.Name);
}
static testmethod void testDeleteAccount() {
Account accountToDelete = new Account(Name = 'Account to Delete');
insert accountToDelete;
test.starttest();
UpdateAccountToMatchBilling updateAccountInstance=new
UpdateAccountToMatchBilling();
updateAccountInstance.deleteAccount(accountToDelete.Id);
test.stoptest();
List<Account> deletedAccounts = [SELECT Id FROM Account WHERE Id
= :accountToDelete.Id];
System.assertEquals(0, deletedAccounts.size());
}
static testmethod void testProcessDebtorUpdate(){
try{

Document testDocument = new Document(


Name = 'TestDocument',
DeveloperName = 'Test_Debtor_File',
FolderId = UserInfo.getUserId(),
Type='CSV',
Body = Blob.valueOf('Debtor1, Value1\nDebtor2, Value2\nDebtor3,
Value3')
);
insert testDocument;

InternalApplicationSettings__c testSettings = new


InternalApplicationSettings__c(
Name = 'Test Settings'
// DebtorFileDeveloperName = 'Test_Debtor_File'
);
insert testSettings;
InternalApplicationSettings__c testSettings2 = new
InternalApplicationSettings__c(
Name = 'DebtorFileName',
Application_Setting__c = 'Test_Debtor_File'
);
insert testSettings2;

Legal_entities__c parentBCode1 = new Legal_entities__c(NCC__c = 'NCC001');


Legal_entities__c childBCode1 = new Legal_entities__c(Parent_NCC_code__c =
'NCC001');
Legal_entities__c parentBCode2 = new Legal_entities__c(NCC__c =
'Debtor1');
Legal_entities__c childBCode2 = new Legal_entities__c(Parent_NCC_code__c =
'Debtor2');
Account account1 = new Account(Name = 'Test Account 1',
Debt_Current_Debt_Status__c = false);
Account account2 = new Account(Name = 'Test Account 2',
Debt_Current_Debt_Status__c = false);
insert new List<SObject>{parentBCode1, childBCode1, account1, account2,
parentBCode2, childBCode2};
test.startTest();
UpdateAccountToMatchBilling updateAccountInstance=new
UpdateAccountToMatchBilling();
updateAccountInstance.processDebtorUpdate();
system.debug('processdebtor executed successfully');
test.stopTest();
List<Account> updatedAccountsprocess = [SELECT Id,
Debt_Current_Debt_Status__c FROM Account WHERE Debt_Current_Debt_Status__c = true];
System.assertEquals(2, updatedAccountsprocess.size(), 'Unexpected number of updated
accounts');

testDocument.Body = Blob.valueOf('InvalidDebtorData');
updateAccountInstance = new UpdateAccountToMatchBilling();
updateAccountInstance.processDebtorUpdate();

testDocument.Body = Blob.valueOf('NewDebtor1, Value1\nNewDebtor2, Value2');


updateAccountInstance = new UpdateAccountToMatchBilling();
updateAccountInstance.processDebtorUpdate();

Account updatedAccount1 = [SELECT Id, Debt_Current_Debt_Status__c FROM


Account WHERE Name = 'Test Account 1'];

Account updatedAccount2 = [SELECT Id, Debt_Current_Debt_Status__c FROM


Account WHERE Name = 'Test Account 2'];

}
catch(Exception e)
{
system.debug('Error occured:'+e.getMessage());

}
static testmethod void testProcessAccountBillingUpdates_ProspectRecordType(){

RecordType prospectRecordType = createTestRecordType();


Country__c country = new Country__c(Name = 'United States');
insert country;
Account account1 = new Account(
Name = 'Account 1',
RegAddrCountry__c=country.id,
NCC__c = 'NCC001'//,
//RecordTypeId = '012b0000000cOtLAAU'

);
insert account1;

Map<Id, Account> beforeUpdateAccountsData = new Map<Id, Account>();


beforeUpdateAccountsData.put(account1.Id, new Account(NCC__c =
'NCC00001'));
List<Legal_entities__c> LEList = new List<Legal_entities__c>();
Legal_entities__c billingEntity001 = new Legal_entities__c(
Name = 'Billing Entity 00',
NCC__c = 'NCC0001',
Parent__c = account1.Id,
Status_Miro__c = 'Active'

);
LEList.add(billingEntity001);
Legal_entities__c billingEntity002 = new Legal_entities__c(
Name = 'Billing Entity 0025',
NCC__c = 'NCC0002',
Parent__c = account1.Id,
Status_Miro__c = 'Dead'

);
LEList.add(billingEntity002);
Legal_entities__c billingEntity003 = new Legal_entities__c(
Name = 'Billing Entity 0026',
NCC__c = 'NCC0003',
Parent__c = account1.Id,
Status_Miro__c = 'Suspended'
);
LEList.add(billingEntity003);

insert LEList;
test.startTest();
UpdateAccountToMatchBilling updateAccountInstance=new
UpdateAccountToMatchBilling();
updateAccountInstance.processAccountBillingUpdates(new
List<Account>{account1}, beforeUpdateAccountsData);
test.stopTest();

account1 = [SELECT Id, Account_status__c FROM Account WHERE Id


= :account1.Id];
System.assertNotEquals('Active', account1.Account_status__c);

}
static testmethod void testProcessAccountBillingUpdates_ChangedNCC(){
Country__c country = new Country__c(Name = 'United States');
insert country;
Id recordTypeId=[SELECT Id from RecordType WHERE SObjectType='Account' AND
DeveloperName='Prospect'LIMIT 1].id;
Legal_entities__c billingEntity1 = new Legal_entities__c(
Name = 'Billing Entity 1',
RegAddrCountry__c=country.id,
NCC__c = 'NCC001'

);
insert billingEntity1;

Account account1 = new Account(


Name = 'Account 1',
NCC__c = 'NCC001',
RegAddrCountry__c=country.id,
RecordTypeId = recordTypeId

);
Account account2 = new Account(
Name = 'Account 2',
NCC__c = 'NCC002',
RegAddrCountry__c=country.id,
RecordTypeId = recordTypeId

);
Account account3 = new Account(
Name = 'Account 3',
NCC__c = 'NCC003',
RegAddrCountry__c=country.id,
RecordTypeId = recordTypeId

);
insert new List<Account> {account1, account2, account3};

Map<Id, Account> beforeUpdateAccountsData = new Map<Id, Account>();


beforeUpdateAccountsData.put(account1.Id, new Account(NCC__c = 'NCC001'));
beforeUpdateAccountsData.put(account2.Id, new Account(NCC__c = 'NCC002'));
beforeUpdateAccountsData.put(account3.Id, new Account(NCC__c = 'NCC003'));
test.startTest();
UpdateAccountToMatchBilling updateAccountInstance=new
UpdateAccountToMatchBilling();
updateAccountInstance.processAccountBillingUpdates(new
List<Account>{account1, account2, account3}, beforeUpdateAccountsData);
test.stopTest();

account1 = [SELECT Id, Account_status__c FROM Account WHERE Id


= :account1.Id];
account2 = [SELECT Id, Account_status__c FROM Account WHERE Id
= :account2.Id];
account3 = [SELECT Id, Account_status__c FROM Account WHERE Id
= :account3.Id];
// System.assertEquals('Active', account1.Account_status__c);
// System.assertEquals('Inactive', account2.Account_status__c);
// System.assertEquals('Inactive', account3.Account_status__c);

}
static testmethod void testProcessAccountBillingUpdates_BillingEntityNotFound()
{
RecordType prospectRecordType = new RecordType(
SObjectType = 'Account',
DeveloperName = 'Prospect'
);
Country__c country = new Country__c(Name = 'United States');
insert country;
Id recordTypeId=[SELECT Id from RecordType WHERE SObjectType='Account' AND
DeveloperName='Prospect'LIMIT 1].id;
Account account1 = new Account(
Name = 'Account 1',
NCC__c = 'NCC001',
RegAddrCountry__c=country.id,
RecordTypeId = recordTypeId

);
insert account1;

Map<Id, Account> beforeUpdateAccountsData = new Map<Id, Account>();


beforeUpdateAccountsData.put(account1.Id, new Account(NCC__c = 'NCC001'));

test.startTest();
UpdateAccountToMatchBilling updateAccountInstance=new
UpdateAccountToMatchBilling();
updateAccountInstance.processAccountBillingUpdates(new
List<Account>{account1}, beforeUpdateAccountsData);
test.stopTest();

account1 = [SELECT Id, Account_status__c FROM Account WHERE Id


= :account1.Id];

}
//*****************************************
// * Purpose:
static testMethod void testProcessChildBillingCodeGEOTerrValues1() {

//create test data


Legal_entities__c parentBillingEntity =
TestUtils.createBillingEntity('1234');
Legal_entities__c parentBillingEntity2 =
TestUtils.createBillingEntity('12345');
insert parentBillingEntity;
insert parentBillingEntity2;

List<Legal_entities__c> childrenBillingEntities =
TestUtils.createChildBillingEntities(parentBillingEntity.NCC__c, 4);
List<Legal_entities__c> childrenBillingEntities2 =
TestUtils.createChildBillingEntities(parentBillingEntity2.NCC__c, 10);

List<Legal_entities__c> insertList = new List<Legal_entities__c>();


insertList.addAll(childrenBillingEntities);
insertList.addAll(childrenBillingEntities2);

for (Legal_entities__c bc : childrenBillingEntities) {


system.assertEquals(parentBillingEntity.NCC__c, bc.Parent_NCC_code__c);
system.assertEquals(NULL, bc.Parent_Code_Country__c);
system.assertNOTEquals(parentBillingEntity.RegAddrCountry__c,
bc.Parent_Code_Country__c);
}

for (Legal_entities__c bc : childrenBillingEntities2) {


system.assertEquals(parentBillingEntity2.NCC__c,
bc.Parent_NCC_code__c);
system.assertEquals(NULL, bc.Parent_Code_Country__c);
system.assertNOTEquals(parentBillingEntity2.RegAddrCountry__c,
bc.Parent_Code_Country__c);
}

//perform tests
test.startTest();

insert insertList;

test.stopTest();

//assert results
List<Legal_entities__c> childrenBillingEntitiesResults = [Select id,
Parent_Code_Country__c, Parent_NCC_Code__c
From
Legal_entities__c
Where
Parent_NCC_Code__c = :parentBillingEntity.NCC__c];

for (Legal_entities__c bc : childrenBillingEntitiesResults) {


system.assertEquals(parentBillingEntity.NCC__c, bc.Parent_NCC_code__c);
//system.assertNOTEquals(NULL, bc.Parent_Code_Country__c);
// system.assertEquals(parentBillingEntity.RegAddrCountry__c,
bc.Parent_Code_Country__c);
}

List<Legal_entities__c> childrenBillingEntitiesResults2 = [Select id,


Parent_Code_Country__c, Parent_NCC_Code__c
From
Legal_entities__c
Where
Parent_NCC_Code__c = :parentBillingEntity2.NCC__c];

for (Legal_entities__c bc : childrenBillingEntitiesResults2) {


system.assertEquals(parentBillingEntity2.NCC__c,
bc.Parent_NCC_code__c);
//system.assertNOTEquals(NULL, bc.Parent_Code_Country__c);
//system.assertEquals(parentBillingEntity2.RegAddrCountry__c,
bc.Parent_Code_Country__c);
}

}
//*****************************************
// * Purpose:
static testMethod void testProcessChildBillingCodeGEOTerrValues2() {

//create test data


Legal_entities__c parentBillingEntity =
TestUtils.createBillingEntity('1234');
Legal_entities__c parentBillingEntity2 =
TestUtils.createBillingEntity('12345');
Legal_entities__c parentBillingEntity3 =
TestUtils.createBillingEntity('123456');
Legal_entities__c parentBillingEntity4 =
TestUtils.createBillingEntity('1234567');
insert parentBillingEntity;
insert parentBillingEntity2;
insert parentBillingEntity3;
insert parentBillingEntity4;

List<Legal_entities__c> childrenBillingEntities =
TestUtils.createChildBillingEntities(parentBillingEntity.NCC__c, 4);
List<Legal_entities__c> childrenBillingEntities2 =
TestUtils.createChildBillingEntities(parentBillingEntity2.NCC__c, 10);

List<Legal_entities__c> insertList = new List<Legal_entities__c>();


insertList.addAll(childrenBillingEntities);
insertList.addAll(childrenBillingEntities2);

for (Legal_entities__c bc : childrenBillingEntities) {


system.assertEquals(parentBillingEntity.NCC__c, bc.Parent_NCC_code__c);
system.assertEquals(NULL, bc.Parent_Code_Country__c);
system.assertNOTEquals(parentBillingEntity.RegAddrCountry__c,
bc.Parent_Code_Country__c);
}

for (Legal_entities__c bc : childrenBillingEntities2) {


system.assertEquals(parentBillingEntity2.NCC__c,
bc.Parent_NCC_code__c);
system.assertEquals(NULL, bc.Parent_Code_Country__c);
system.assertNOTEquals(parentBillingEntity2.RegAddrCountry__c,
bc.Parent_Code_Country__c);
}

insert insertList;
//assert results
List<Legal_entities__c> childrenBillingEntitiesResults = [Select id,
Parent_Code_Country__c, Parent_NCC_Code__c
From
Legal_entities__c
Where
Parent_NCC_Code__c = :parentBillingEntity.NCC__c];

for (Legal_entities__c bc : childrenBillingEntitiesResults) {


system.assertEquals(parentBillingEntity.NCC__c, bc.Parent_NCC_code__c);
// system.assertNOTEquals(NULL, bc.Parent_Code_Country__c);
// system.assertEquals(parentBillingEntity.RegAddrCountry__c,
bc.Parent_Code_Country__c);
}

List<Legal_entities__c> childrenBillingEntitiesResults2 = [Select id,


Parent_Code_Country__c, Parent_NCC_Code__c
From
Legal_entities__c
Where
Parent_NCC_Code__c = :parentBillingEntity2.NCC__c];

for (Legal_entities__c bc : childrenBillingEntitiesResults2) {


system.assertEquals(parentBillingEntity2.NCC__c,
bc.Parent_NCC_code__c);
//system.assertNOTEquals(NULL, bc.Parent_Code_Country__c);
//system.assertEquals(parentBillingEntity2.RegAddrCountry__c,
bc.Parent_Code_Country__c);
}

//perform tests
test.startTest();

for(Legal_entities__c bc : childrenBillingEntities) {
bc.Parent_NCC_code__c = parentBillingEntity3.NCC__c;
}

for(Legal_entities__c bc : childrenBillingEntities2) {
bc.Parent_NCC_code__c = parentBillingEntity4.NCC__c;
}

update insertList;

test.stopTest();

//assert results
childrenBillingEntitiesResults = [Select id, Parent_Code_Country__c,
Parent_NCC_Code__c
From
Legal_entities__c
Where
Parent_NCC_Code__c = :parentBillingEntity.NCC__c];

system.assertEquals(0, childrenBillingEntitiesResults.size());

childrenBillingEntitiesResults2 = [Select id, Parent_Code_Country__c,


Parent_NCC_Code__c
From
Legal_entities__c
Where
Parent_NCC_Code__c = :parentBillingEntity2.NCC__c];

system.assertEquals(0, childrenBillingEntitiesResults2.size());

childrenBillingEntitiesResults = [Select id, Parent_Code_Country__c,


Parent_NCC_Code__c
From
Legal_entities__c
Where
Parent_NCC_Code__c = :parentBillingEntity3.NCC__c];

for (Legal_entities__c bc : childrenBillingEntitiesResults) {


system.assertEquals(parentBillingEntity3.NCC__c,
bc.Parent_NCC_code__c);
system.assertNOTEquals(NULL, bc.Parent_Code_Country__c);
system.assertEquals(parentBillingEntity3.RegAddrCountry__c,
bc.Parent_Code_Country__c);
}

childrenBillingEntitiesResults2 = [Select id, Parent_Code_Country__c,


Parent_NCC_Code__c
From
Legal_entities__c
Where
Parent_NCC_Code__c = :parentBillingEntity4.NCC__c];

for (Legal_entities__c bc : childrenBillingEntitiesResults2) {


system.assertEquals(parentBillingEntity4.NCC__c,
bc.Parent_NCC_code__c);
system.assertNOTEquals(NULL, bc.Parent_Code_Country__c);
system.assertEquals(parentBillingEntity4.RegAddrCountry__c,
bc.Parent_Code_Country__c);
}

//*****************************************
// * Purpose:
static testMethod void testPushChildBillingCodeGEOTerrValues() {

Country__c country = new Country__c(Name = 'United States');


insert country;
Legal_entities__c parent = new Legal_entities__c(
NCC__c = 'ParentNCC',
RegAddrCountry__c=country.id
);
insert parent;
Legal_entities__c child = new Legal_entities__c(
NCC__c = 'ChildNCC',
Parent_NCC_Code__c='ParentNCC'
);
insert child;
Country__c country1 = new Country__c(Name = 'India');
insert country1;
parent.RegAddrCountry__c=country1.id;
update parent;
Map<Id, Legal_entities__c> beforeUpdateData = new Map<Id,
Legal_entities__c>();
beforeUpdateData.put(parent.Id, parent);
test.startTest();
UpdateAccountToMatchBilling updateAccountInstance=new
UpdateAccountToMatchBilling();

updateAccountInstance.pushChildBillingCodeGEOTerrValues(new Map<Id,
Legal_entities__c>{parent.Id=>parent}, beforeUpdateData);
test.stopTest();
List<Legal_entities__c> updatedChild=[SELECT Id,Parent_code_Country__c FROM
Legal_entities__c WHERE Id=:child.Id];

}
static testmethod void ProspectRecordType1(){
Country__c country = new Country__c(Name = 'United States');
insert country;
Account account1 = new Account(
Name = 'Account 1',
RegAddrCountry__c=country.id,
NCC__c = 'NCC001'//,
//RecordTypeId = '012b0000000cOtLAAU'

);
Account account2 = new Account(
Name = 'Account 2',
RegAddrCountry__c=country.id,
NCC__c = 'NCC002'//,

);
insert new List<Account>{account1,account2};
Map<Id,Account>beforeUpdateAccountData=new map<Id,Account>{
account1.id=>new Account(Id=account1.Id,NCC__c='NCC1_old'),
account2.id=>new Account(Id=account2.Id,NCC__c='NCC2_old')
};
test.startTest();
UpdateAccountToMatchBilling updateAccountInstance=new
UpdateAccountToMatchBilling();
updateAccountInstance.processAccountBillingUpdates(new
List<Account>{account1,account2}, beforeUpdateAccountData);
test.stopTest();
Account updatedAccount1 = [SELECT Id,NCC__c, Account_status__c FROM Account WHERE
Id = :account1.Id];
Account updatedAccount2 = [SELECT Id,NCC__c, Account_status__c FROM Account
WHERE Id = :account2.Id];
system.assertEquals('NCC001',updatedAccount1.NCC__c);
system.assertEquals('NCC002',updatedAccount2.NCC__c);

You might also like