RTRReportResult.MockFlatlistRow
This class is used to create mock responses for the unit test execution.
Namespace
The RTRReportResult.MockFlatlistRow class extends RTRReportResult.FlatlistRow.
The supported modifiers are global and virtual.
1cgcloudSupported Methods
| Method signature | Description | Version |
|---|---|---|
| RTRReportResult.MockFlatlistRow(Map<String, Object> rowData) | The constructor for creating mock responses for the unit test execution.
rowData: Map<String, Object> . A map of String to Object that contains different values for all the columns of MockFlatlistRow. The mocked value is returned when the getColumnValue method is executed. The map must have a key called RowType, which sets the type for the row. If a map is provided without this key, this constructor throws an exception. |
60.0 |
Example Implementation
To unit test a Flatlist component in, mock the resulting report data rows with the MockFlatlist and MockFlatlistRow classes.
1@IsTest
2 public static void myTestMethod() {
3 // Setup
4
5 // Setup your required data for the test
6
7 // Expected RTR Report Filters
8 Map<String, Object> expectedReportFilters = null; //...
9
10 // Create a mock RTRReportResult
11 cgcloud.RTRReportResult.MockRTRReportResult mockReportResult = new cgcloud.RTRReportResult.MockRTRReportResult(
12 // Create a map with the returned report components
13 new Map<String, cgcloud.RTRReportResult.ReportComponent>{
14 // Flatlist component
15 'FlatList' => new cgcloud.RTRReportResult.MockFlatlist(
16 // For a flatlist, specify the mocked rows
17 new List<cgcloud.RTRReportResult.MockFlatlistRow>{
18 new cgcloud.RTRReportResult.MockFlatlistRow(
19 // For each row, set the column values
20 new Map<String, Object>{
21 'RowType' => 'Product-Promo', // RowType is required
22 'productdimension.id' => productid1,
23 'KPI1' => 123,
24 'KPI2' => 456
25 }
26 ),
27 new cgcloud.RTRReportResult.MockFlatlistRow(
28 // For each row, set the column values
29 new Map<String, Object>{
30 'RowType' => 'Product-Promo', // RowType is required
31 'productdimension.id' => productid2,
32 'KPI1' => 789,
33 'KPI2' => 123
34 }
35 )
36 }
37 )
38 }
39 );
40
41 // Set the mock in RTRReportResult.execute so the call to this method
42 // returns our mock response
43 cgcloud.RTRReportResult.setMock(new List<Object>{ mockReportResult });
44
45 // Test
46
47 // Run your code to be tested. RTRReportResult.execute call will
48 // return the mock result
49
50 // Assert
51
52 // Assert your code is working as expected.
53
54 // You can also validate RTRReportResult.execute was called with the expected
55 // parameters
56 system.assertEquals('0001', mockReportResult.getSalesOrg());
57 system.assertEquals('MySampleReport', mockReportResult.getReportName());
58 system.assertEquals(expectedReportFilters, mockReportResult.getFilters());
59 }