Search in sources :

Example 81 with DataQueryParams

use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.

the class ContextUtilsTest method testConfigureAnalyticsResponseReturnsCorrectCacheHeaders.

@Test
public void testConfigureAnalyticsResponseReturnsCorrectCacheHeaders() {
    Calendar thisYear = Calendar.getInstance();
    Calendar fiveYearBack = Calendar.getInstance();
    thisYear.set(2017, 01, 01);
    fiveYearBack.set(2012, 01, 01);
    DataQueryParams withinThreshold = DataQueryParams.newBuilder().withEndDate(thisYear.getTime()).build();
    DataQueryParams outsideThreshold = DataQueryParams.newBuilder().withEndDate(fiveYearBack.getTime()).build();
    systemSettingManager.saveSystemSetting(SettingKey.CACHE_ANALYTICS_DATA_YEAR_THRESHOLD, 3);
    response.reset();
    contextUtils.configureAnalyticsResponse(response, null, CacheStrategy.CACHE_1_HOUR, null, false, withinThreshold.getLatestEndDate());
    assertEquals("no-cache", response.getHeader("Cache-Control"));
    response.reset();
    contextUtils.configureAnalyticsResponse(response, null, CacheStrategy.CACHE_1_HOUR, null, false, outsideThreshold.getLatestEndDate());
    assertEquals("max-age=3600, public", response.getHeader("Cache-Control"));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) Calendar(java.util.Calendar) Test(org.junit.Test) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest)

Aggregations

DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)81 Test (org.junit.Test)52 DhisSpringTest (org.hisp.dhis.DhisSpringTest)51 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)24 QueryPlannerParams (org.hisp.dhis.analytics.QueryPlannerParams)22 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)19 DataQueryGroups (org.hisp.dhis.analytics.DataQueryGroups)17 ArrayList (java.util.ArrayList)16 DimensionalObject (org.hisp.dhis.common.DimensionalObject)15 HashSet (java.util.HashSet)14 LinkedHashSet (java.util.LinkedHashSet)13 HashMap (java.util.HashMap)7 PeriodType.getPeriodTypeFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 List (java.util.List)6 Map (java.util.Map)6 OrganisationUnit.getParentGraphMap (org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap)6 OrganisationUnit.getParentNameGraphMap (org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap)6 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)5 Grid (org.hisp.dhis.common.Grid)5