New 2
New 2
***********************************************************************OPSORG******
******************************************************
* Name of class: UpdateAccountToMatchBillingTest cp
* Purpose: To test the class UpdateAccountToMatchBilling which is excuted by an
account trigger.
*********************
*********************
************************************************************************/
@isTest
public class UpdateAccountToMatchBillingTest {
private static RecordType createTestRecordType() {
);
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);
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();
}
}
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{
testDocument.Body = Blob.valueOf('InvalidDebtorData');
updateAccountInstance = new UpdateAccountToMatchBilling();
updateAccountInstance.processDebtorUpdate();
}
catch(Exception e)
{
system.debug('Error occured:'+e.getMessage());
}
static testmethod void testProcessAccountBillingUpdates_ProspectRecordType(){
);
insert account1;
);
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();
}
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 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};
}
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;
test.startTest();
UpdateAccountToMatchBilling updateAccountInstance=new
UpdateAccountToMatchBilling();
updateAccountInstance.processAccountBillingUpdates(new
List<Account>{account1}, beforeUpdateAccountsData);
test.stopTest();
}
//*****************************************
// * Purpose:
static testMethod void testProcessChildBillingCodeGEOTerrValues1() {
List<Legal_entities__c> childrenBillingEntities =
TestUtils.createChildBillingEntities(parentBillingEntity.NCC__c, 4);
List<Legal_entities__c> childrenBillingEntities2 =
TestUtils.createChildBillingEntities(parentBillingEntity2.NCC__c, 10);
//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];
}
//*****************************************
// * Purpose:
static testMethod void testProcessChildBillingCodeGEOTerrValues2() {
List<Legal_entities__c> childrenBillingEntities =
TestUtils.createChildBillingEntities(parentBillingEntity.NCC__c, 4);
List<Legal_entities__c> childrenBillingEntities2 =
TestUtils.createChildBillingEntities(parentBillingEntity2.NCC__c, 10);
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];
//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());
system.assertEquals(0, childrenBillingEntitiesResults2.size());
//*****************************************
// * Purpose:
static testMethod void testPushChildBillingCodeGEOTerrValues() {
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);