Skip to content

Commit

Permalink
New feature to allow override of generated Apex test code
Browse files Browse the repository at this point in the history
See
#1
99
  • Loading branch information
afawcettffdc committed Jul 6, 2015
1 parent 39f7f2e commit 20154da
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
8 changes: 6 additions & 2 deletions rolluptool/src/classes/RollupController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ public with sharing class RollupController
'{\n' +
' private static testmethod void testTrigger()\n' +
' {\n' +
' // Force the ' + RollupTriggerName + ' to be invoked, fails the test if org config or other Apex code prevents this.\n' +
' ' + (namespace.length() > 0 ? namespace + '.' : '') + 'RollupService.testHandler(new ' + RollupSummary.ChildObject__c + '());\n'+
((RollupSummary.TestCode__c!=null && RollupSummary.TestCode__c.length()>0) ?
RollupSummary.TestCode__c + '\n' :
(
' // Force the ' + RollupTriggerName + ' to be invoked, fails the test if org config or other Apex code prevents this.\n' +
' ' + (namespace.length() > 0 ? namespace + '.' : '') + 'RollupService.testHandler(new ' + RollupSummary.ChildObject__c + '());\n')
) +
' }\n' +
'}';
}
Expand Down
43 changes: 43 additions & 0 deletions rolluptool/src/classes/RollupControllerTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,49 @@ private class RollupControllerTest

Test.stopTest();
}

private testmethod static void testDeployedStatusWithCustomTestCode()
{
// Test supported?
if(!TestContext.isSupported())
return;

// Test data
LookupRollupSummary__c rollupSummaryA = new LookupRollupSummary__c();
rollupSummaryA.Name = 'Total Opportunities greater than 200 into Annual Revenue on Account';
rollupSummaryA.ParentObject__c = 'Account';
rollupSummaryA.ChildObject__c = 'Opportunity';
rollupSummaryA.RelationShipField__c = 'AccountId';
rollupSummaryA.RelationShipCriteria__c = null;
rollupSummaryA.FieldToAggregate__c = 'Amount';
rollupSummaryA.AggregateOperation__c = 'Sum';
rollupSummaryA.AggregateResultField__c = 'AnnualRevenue';
rollupSummaryA.Active__c = true;
rollupSummaryA.CalculationMode__c = 'Realtime';
rollupSummaryA.TestCode__c = 'System.assertEquals(1,1)';

// Assert initial state of controller when the trigger for the child object is deployed
RollupController controller = new RollupController(new ApexPages.StandardController( rollupSummaryA ));
System.assertEquals(true, controller.Deployed);
System.assertEquals('RollupServiceTestTrigger', controller.RollupTriggerName);
System.assertEquals('RollupSummariesTest', controller.RollupTriggerTestName);
System.assertEquals('RollupServiceTestTrigger', controller.RollupTrigger.Name);
System.assertEquals('RollupSummariesTest', controller.RollupTriggerTest.Name);
System.assertEquals(controller.RollupTrigger.Body, controller.getTriggerCode());
System.assertEquals(controller.RollupTriggerTest.Body, controller.getTriggerTestCode());
System.assertEquals(
'/**\n' +
' * Auto Generated and Deployed by the Declarative Lookup Rollup Summaries Tool package (dlrs)\n' +
' **/\n' +
'@IsTest\n' +
'private class ' + controller.RollupTriggerTestName + '\n' +
'{\n' +
' private static testmethod void testTrigger()\n' +
' {\n' +
'System.assertEquals(1,1)\n' +
' }\n' +
'}', controller.getTriggerTestCode());
}

/**
* Metadata API web service mock class for tests above
Expand Down
3 changes: 2 additions & 1 deletion rolluptool/src/classes/RollupSummariesSelector.cls
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public class RollupSummariesSelector extends fflib_SObjectSelector
LookupRollupSummary__c.RelationshipField__c,
LookupRollupSummary__c.CalculateJobId__c,
LookupRollupSummary__c.UniqueName__c,
LookupRollupSummary__c.CalculationSharingMode__c
LookupRollupSummary__c.CalculationSharingMode__c,
LookupRollupSummary__c.TestCode__c
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@
</layoutColumns>
<style>OneColumn</style>
</layoutSections>
<layoutSections>
<customLabel>true</customLabel>
<detailHeading>true</detailHeading>
<editHeading>true</editHeading>
<label>Advanced</label>
<layoutColumns>
<layoutItems>
<behavior>Edit</behavior>
<field>TestCode__c</field>
</layoutItems>
</layoutColumns>
<style>OneColumn</style>
</layoutSections>
<layoutSections>
<customLabel>false</customLabel>
<detailHeading>false</detailHeading>
Expand Down
11 changes: 11 additions & 0 deletions rolluptool/src/objects/LookupRollupSummary__c.object
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
</fields>
<fields>
<fullName>CalculationSharingMode__c</fullName>
<deprecated>false</deprecated>
<externalId>false</externalId>
<inlineHelpText>Determines if the Sharing Rules defined on the Child Object are considered when calculating the rollup. Default is User.</inlineHelpText>
<label>Calculation Sharing Mode</label>
Expand Down Expand Up @@ -291,6 +292,16 @@
<type>Text</type>
<unique>false</unique>
</fields>
<fields>
<fullName>TestCode__c</fullName>
<externalId>false</externalId>
<inlineHelpText>This tool utilises a dynamically generated Apex Trigger and by default a generated Apex Test. Use this field if instructed by a developer to replace the generated test code. For more information see the tools Wiki on GitHub.</inlineHelpText>
<label>Test Code</label>
<length>32768</length>
<trackTrending>false</trackTrending>
<type>LongTextArea</type>
<visibleLines>12</visibleLines>
</fields>
<fields>
<fullName>UniqueName__c</fullName>
<caseSensitive>false</caseSensitive>
Expand Down

0 comments on commit 20154da

Please sign in to comment.