Test the WaveTemplateConfigurationModifier before deploying a template that uses it.
Before you can deploy your template or package it for the Salesforce AppExchange that uses a WaveTemplateConfigurationModifier class, a unit test class must be present and all of the tests must complete successfully. The unit test is designed to call and run the modifier methods and nothing more. Use the following examples when creating your own unit test class.
Use the wavetemplate.Test helper methods for testing.
-
wavetemplate.Test.getWaveTemplateInfoForApexTesting. Retrieves the runtime template information object for testing. RequirestemplateName:getWaveTemplateInfoForApexTesting(String templateName) -
wavetemplate.Test.getDefaultAnswersForApexTesting. Retrieves the variable answers set by user selections and/or the configuration modifier methods. RequirestemplateName:getDefaultAnswersForApexTesting(String templateName)
The following code examples show how to test the methods from the Apex Examples page.
Example
Generic Test Class Example
@isTest
private class ExampleWaveTemplateConfigurationModifierTest
{
@isTest
static testMethod void testModifier()
{
// Test modifier methods
}
}
Example
beforeAppCreate Test Method Example
@isTest static testMethod void testBeforeAppCreate()
{
wavetemplate.WaveTemplateInfo template =
wavetemplate.Test.getWaveTemplateInfoForApexTesting('my_template');
wavetemplate.Answers answers =
wavetemplate.Test.getDefaultAnswersForApexTesting('my_template');
ExampleWaveTemplateConfigurationModifier mod =
new ExampleWaveTemplateConfigurationModifier();
//Test the beforeAppCreate method in your Apex Modifier Class
System.assertEquals('Yes', answers.get(Has_Product));
mod.beforeAppCreate(template, answers);
System.assertEquals('No', answers.get(Has_Product));
}
Example
beforeAppUpdate Test Method Example
@isTest static testMethod void testBeforeAppUpdate()
{
wavetemplate.WaveTemplateInfo template =
wavetemplate.Test.getWaveTemplateInfoForApexTesting('my_template');
wavetemplate.Answers answers =
wavetemplate.Test.getDefaultAnswersForApexTesting('my_template');
ExampleWaveTemplateConfigurationModifier mod =
new ExampleWaveTemplateConfigurationModifier();
//Test the beforeAppUpdate method in your Apex Modifier Class
System.assertEquals('No', answers.get(Has_Product));
mod.beforeAppUpdate(template, '2.0', answers);
System.assertEquals('Yes', answers.get(Has_Product));
}
Example
onConfigurationRetrieval Test Method Example
@isTest static testMethod void testOnConfig()
{
wavetemplate.WaveTemplateInfo template =
wavetemplate.Test.getWaveTemplateInfoForApexTesting('my_template');
ExampleWaveTemplateConfigurationModifier mod =
new ExampleWaveTemplateConfigurationModifier();
//Test the onConfigurationRetrieval method in your Apex Modifier Class
mod.onConfigurationRetrieval(template);
System.assertEquals('No',
template.getVariables().get('Has_Product').getComputedValue());
}
For complete information, see Testing Apex.