RTRReportResult.MockRTRReportResult
This class is used to create mock responses for the unit test execution.
Namespace
The RTRReportResult.MockRTRReportResult class extends RTRReportResult.
The supported modifiers are global and virtual.
cgcloud
Supported Methods
Method signature | Description | Version |
---|---|---|
RTRReportResult.MockRTRReportResult(Map<String, RTRReportResult.ReportComponent> components) | The constructor for creating mock responses for the unit test execution.
components: Map<String, RTRReportResult.ReportComponent> . A map of a reporting component name to a mock report component instance. The mocked value is returned when the getComponent method is executed. |
60.0 |
Example Implementation
@IsTest
public static void myTestMethod() {
// Setup
// Setup your required data for the test
// Expected RTR Report Filters
Map<String, Object> expectedReportFilters = null; //...
// Create a mock RTRReportResult
cgcloud.RTRReportResult.MockRTRReportResult mockReportResult = new cgcloud.RTRReportResult.MockRTRReportResult(
// Create a map with the returned report components
new Map<String, cgcloud.RTRReportResult.ReportComponent>{
// Flatlist component
'FlatList' => new cgcloud.RTRReportResult.MockFlatlist(
// For a flatlist, specify the mocked rows
new List<cgcloud.RTRReportResult.MockFlatlistRow>{
new cgcloud.RTRReportResult.MockFlatlistRow(
// For each row, set the column values
new Map<String, Object>{
'RowType' => 'Product-Promo', // RowType is required
'productdimension.id' => productid1,
'KPI1' => 123,
'KPI2' => 456
}
),
new cgcloud.RTRReportResult.MockFlatlistRow(
// For each row, set the column values
new Map<String, Object>{
'RowType' => 'Product-Promo', // RowType is required
'productdimension.id' => productid2,
'KPI1' => 789,
'KPI2' => 123
}
)
}
)
}
);
// Set the mock in RTRReportResult.execute so the call to this method
// returns our mock response
cgcloud.RTRReportResult.setMock(new List<Object>{ mockReportResult });
// Test
// Run your code to be tested. RTRReportResult.execute call will
// return the mock result
// Assert
// Assert your code is working as expected.
// You can also validate RTRReportResult.execute was called with the expected
// parameters
system.assertEquals('0001', mockReportResult.getSalesOrg());
system.assertEquals('MySampleReport', mockReportResult.getReportName());
system.assertEquals(expectedReportFilters, mockReportResult.getFilters());
}