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"));
}
Aggregations