use of org.hisp.dhis.analytics.AnalyticsManager in project dhis2-core by dhis2.
the class AnalyticsManagerTest method testReplaceDataPeriodsWithAggregationPeriods.
@Test
void testReplaceDataPeriodsWithAggregationPeriods() {
AnalyticsManager analyticsManager = new JdbcAnalyticsManager(queryPlanner, jdbcTemplate, executionPlanStore);
Period y2012 = createPeriod("2012");
AnalyticsAggregationType aggregationType = new AnalyticsAggregationType(AggregationType.SUM, AggregationType.AVERAGE, DataType.NUMERIC, true);
DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(createDataElement('A'), createDataElement('B'))).withPeriods(getList(y2012)).withOrganisationUnits(getList(createOrganisationUnit('A'))).withDataPeriodType(new YearlyPeriodType()).withAggregationType(aggregationType).build();
Map<String, Object> dataValueMap = new HashMap<>();
dataValueMap.put(BASE_UID + "A-2012-" + BASE_UID + "A", 1d);
dataValueMap.put(BASE_UID + "B-2012-" + BASE_UID + "A", 1d);
ListMap<DimensionalItemObject, DimensionalItemObject> dataPeriodAggregationPeriodMap = new ListMap<>();
dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q1"));
dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q2"));
dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q3"));
dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q4"));
analyticsManager.replaceDataPeriodsWithAggregationPeriods(dataValueMap, params, dataPeriodAggregationPeriodMap);
assertEquals(8, dataValueMap.size());
assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q1-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q2-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q3-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q4-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q1-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q2-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q3-" + BASE_UID + "A"));
assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q4-" + BASE_UID + "A"));
}
Aggregations