121 lines
4.6 KiB
OpenEdge ABL
121 lines
4.6 KiB
OpenEdge ABL
/**
|
|
* @description The class will provide code coverage for the OpportunityCloneService
|
|
* @author Cloud Performer <cgary@cloupderformer.com>
|
|
* @version 1.0
|
|
* @group Opportunity Cloning
|
|
* @history 2021-04-12 - CJG - Created
|
|
*/
|
|
@isTest
|
|
private class OpportunityCloneServiceTest {
|
|
@TestSetup
|
|
static void makeData(){
|
|
List<Account> acctTests = new List<Account>();
|
|
List<Product2> productList = new List<Product2>();
|
|
List<PricebookEntry> pricebookItems = new List<PricebookEntry>();
|
|
List<Opportunity> oppTests = new List<Opportunity>();
|
|
List<OpportunityLineItem> oliTestLines = new List<OpportunityLineItem>();
|
|
//create accounts
|
|
acctTests.add(new Account(
|
|
Name = TestCloneUtility.GenerateRandomString(10),
|
|
AccountNumber = TestCloneUtility.GenerateRandomString(8).toUpperCase(),
|
|
BillingStreet = '1 ' + TestCloneUtility.GenerateRandomString(10) + ' Street',
|
|
BillingCity = 'Atlanta',
|
|
BillingState = 'Georgia',
|
|
BillingPostalCode = '30303',
|
|
BillingCountry = 'USA' ,
|
|
ShippingStreet = '2 ' + TestCloneUtility.GenerateRandomString(8) + ' Street',
|
|
ShippingCity = 'Atlanta',
|
|
ShippingState = 'Georgia',
|
|
ShippingPostalCode = '30303',
|
|
ShippingCountry = 'USA'
|
|
));
|
|
insert acctTests;
|
|
//create Products
|
|
for(Integer i=0; i < 5;i++){
|
|
productList.add(new Product2(
|
|
Name=TestCloneUtility.GenerateRandomString(5),
|
|
isActive = true,
|
|
ProductCode = TestCloneUtility.GenerateRandomString(6).toUpperCase()
|
|
));
|
|
}
|
|
insert productList;
|
|
//obtain test Pricbook
|
|
Id testPricebookId = test.getStandardPricebookId();
|
|
//create PricebookEntry records
|
|
for(Product2 prod:productList){
|
|
pricebookItems.add(new PricebookEntry(
|
|
IsActive = true,
|
|
Pricebook2Id = testPricebookId,
|
|
UnitPrice = 1.0,
|
|
Product2Id = prod.Id
|
|
));
|
|
}
|
|
insert pricebookItems;
|
|
//create test Opportunities
|
|
Schema.DescribeFieldResult fr = Schema.SObjectType.Opportunity.fields.StageName;
|
|
List<Schema.PicklistEntry> stageValues = fr.getPicklistValues();
|
|
for(Account a:acctTests){
|
|
oppTests.add(new Opportunity(
|
|
Name = TestCloneUtility.GenerateRandomString(8),
|
|
CloseDate = System.today().addDays(30),
|
|
StageName = stageValues[0].getValue()
|
|
));
|
|
}
|
|
insert oppTests;
|
|
//create OppLineItems
|
|
for(Opportunity opp:oppTests){
|
|
for(PricebookEntry pbe:pricebookItems){
|
|
oliTestLines.add(new OpportunityLineItem(PricebookEntryId=pbe.Id,Quantity=1.0,UnitPrice=pbe.UnitPrice,
|
|
OpportunityId=opp.Id));
|
|
}
|
|
}
|
|
insert oliTestLines;
|
|
}
|
|
|
|
@isTest
|
|
static void ObtainOpporunityChildRelationships(){
|
|
Test.startTest();
|
|
|
|
Map<String,String> resultMap = OpportunityCloneService.ObtainOpporunityChildRelationships();
|
|
System.assert(!resultMap.isEmpty());
|
|
|
|
Test.stopTest();
|
|
}
|
|
|
|
@isTest
|
|
static void ObtainCloneOpportunityFields(){
|
|
Test.startTest();
|
|
|
|
Map<String,Boolean> resultMap = OpportunityCloneService.ObtainCloneOpportunityFields('ClonedFields');
|
|
System.assert(!resultMap.isEmpty());
|
|
|
|
Test.stopTest();
|
|
}
|
|
|
|
@isTest
|
|
static void ObtainQueryStringForOppAndChildren(){
|
|
//get an opportunity
|
|
Opportunity testOpp = [SELECT Id FROM Opportunity LIMIT 1];
|
|
List<String> relStringList = new List<String>{'OpportunityLineItems'};
|
|
Test.startTest();
|
|
|
|
String queryStringTest = OpportunityCloneService.ObtainQueryStringForOppAndChildren(testOpp.Id, relStringList);
|
|
System.assert(String.isNotBlank(queryStringTest));
|
|
|
|
Test.stopTest();
|
|
}
|
|
@isTest
|
|
static void CloneOpportunityWithChildren(){
|
|
Opportunity testOpp = [SELECT Id, Name FROM Opportunity LIMIT 1];
|
|
Map<String,String> testReplacements = new Map<String,String>();
|
|
testReplacements.put('Name',TestCloneUtility.GenerateRandomString(10));
|
|
Test.startTest();
|
|
|
|
Id testResult = OpportunityCloneService.CloneOpportunityWithChildren(testOpp.Id, testReplacements,
|
|
new List<String>{'OpportunityLineItems'});
|
|
System.assertNotEquals(null, testResult);
|
|
|
|
Test.stopTest();
|
|
}
|
|
}
|