Testing a plugin that intercepts the Response Preprocessing event
The test class has SeeAllData set to true. This is necessary for the Response Management Application to see existing configuration data. The application needs to be enabled, and the Extensibility API must be enabled (through the advanced configuration page)
@isTest (SeeAllData=True)
public class YourExtensibilityTestClass {
public static String YOUR_EXTENSIBILITY_PLUGIN_NAME = 'YourExtensibilityPluginClassName';
static testMethod void TestCampaignMemberInsert()
{
// Install plugin if it's not already installed
FCRM.FCR_ExtensibilityAPI.InstallPluginClass(YOUR_EXTENSIBILITY_PLUGIN_NAME);
// Register Plugin - must be done before any DML operations
FCRM.FCR_ExtensibilityAPI.EnablePluginsForTest = new Set<String>{YOUR_EXTENSIBILITY_PLUGIN_NAME};
// Enables repeat responses on CampaignMembers that are updated
// in the testing context
FCRM.FCR_SupportAPI.SetRepeatResponseUserForContext();
// Create CampaignMember
CampaignMember cm = createCampaignMember();
// Insert CampaignMember
Test.startTest();
insert cm1;// Plugin should be called
Test.stopTest();
// Validate your plugin's actions
// If validating field value changes on the CampaignMember,
// make sure to query the record with the modified fields
}
static testMethod void TestCampaignMemberUpdate()
{
// Install plugin if it's not already installed
FCRM.FCR_ExtensibilityAPI.InstallPluginClass(YOUR_EXTENSIBILITY_PLUGIN_NAME);
// Register Plugin - must be done before any DML operations
FCRM.FCR_ExtensibilityAPI.EnablePluginsForTest = new Set<String>{YOUR_EXTENSIBILITY_PLUGIN_NAME};
// Enables repeat responses on CampaignMembers that are updated
// in the testing context
FCRM.FCR_SupportAPI.SetRepeatResponseUserForContext();
CampaignMember cm = createCampaignMember();
// The system prevents processing the same response more than once
// in a context.
// Disabling the application upon insertion will allow the system
// to handle the update.
FCRM.FCR_SupportAPI.DisableApplicationForContext();
insert cm;// Initialize FCRM fields, because the application won't
FCRM.FCR_SupportAPI.UndoDisableApplicationForContext();
Test.startTest();
update cm;// Plugin should be called
Test.stopTest();
}
public static CampaignMember createCampaignMember()
{
// Returns a CampaignMember.
// If the application is disabled, Make sure to set Status,
// FCRM_FCR_Response_Date_c and FCRM_FCR_Response_Status_c.
// Status should equal 'Responded' in order to test inserting or
// updating a response.
}
}
Comments
0 comments
Please sign in to leave a comment.