Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
testCanvasLifecycle(lifecycleHandler, mockRenderContext)
Signature
public static Void testCanvasLifecycle(Canvas.CanvasLifecycleHandler lifecycleHandler,Canvas.RenderContext mockRenderContext)
Parameters
-
lifecycleHandler:
Type: Canvas.CanvasLifecycleHandler
Specifies the CanvasLifecycleHandler implementation that you need to invoke.
-
mockRenderContext:
Type: Canvas.RenderContext
Specifies the RenderContext information that you need to provide to the invoked CanvasLifecycleHandler. If null is provided for this parameter, the canvas framework generates and uses a default mock RenderContext.
Return Value
Type: Void
Usage
Use this method to invoke an implementation of Canvas.CanvasLifecycleHandler.onRender(renderContext) with a mock Canvas.RenderContext that you provide.
Example
The following example creates an Apex test class that uses maps to represent mock application and environment context data. The mock RenderContext object is then used to invoke a CanvasLifecycleHandler object. In this example, the CanvasLifecycleHandler is defined as MyCanvasListener, which is example implementation provided in Canvas.RenderContext.
1@IsTest
2global class CanvasRendercontextTest {
3 @IsTest
4 static void testRenderContext(){
5 // Set some application context data in a Map
6 Map<String,String> appValues = new Map<String,String>();
7 appValues.put(Canvas.Test.KEY_NAMESPACE,'alternateNamespace');
8 appValues.put(Canvas.Test.KEY_VERSION,'3.0');
9
10 // Set some environment context data in a MAp
11 Map<String,String> envValues = new Map<String,String>();
12 envValues.put(Canvas.Test.KEY_DISPLAY_LOCATION,'Chatter');
13 envValues.put(Canvas.Test.KEY_LOCATION_URL,'https://MyDomainName.my.salesforce.com/_ui/core/chatter/ui/ChatterPage');
14
15 // Create a mock RenderContext using the test application and environment context data Maps
16 Canvas.RenderContext mock = Canvas.Test.mockRenderContext(appValues,envValues);
17
18 // Set some custom params on the mock RenderContext
19 mock.getEnvironmentContext().setParametersAsJSON('{\"param1\":1,\"boolParam\":true,\"stringParam\":\"test string\"}');
20
21 // Create a CanvasLifecycleHandler
22 MyCanvasListener handler = new MyCanvasListener();
23
24 // Use the mock RenderContext to invoke the CanvasLifecycleHandler
25 Canvas.Test.testCanvasLifecycle(handler,mock);
26 }
27}