@Test public void testDefaultCacheTtlCacheHeaderMissing() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); final Uri URL5 = Uri.parse("http://example.org/5.js"); expectGetAndReturnData(URL4, ""); expectGetAndReturnData(URL5, ""); expectRequestWithUris(Lists.newArrayList(URL4, URL5)); servlet.doGet(request, recorder); verify(); int cacheValue = getCacheControlMaxAge(recorder); // HttpResponse.defaultTtl is in msec, division by 1000 is required to convert into sec. assertEquals((int) (HttpResponse.defaultTtl / 1000), cacheValue, 10); }
@Test public void testDefaultCacheTtlCacheHeaderMissing() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); final Uri URL5 = Uri.parse("http://example.org/5.js"); expectGetAndReturnData(URL4, ""); expectGetAndReturnData(URL5, ""); expectRequestWithUris(Lists.newArrayList(URL4, URL5)); servlet.doGet(request, recorder); verify(); int cacheValue = getCacheControlMaxAge(recorder); // HttpResponse.defaultTtl is in msec, division by 1000 is required to convert into sec. assertEquals((int) (HttpResponse.defaultTtl / 1000), cacheValue, 10); }
@Test public void testMinimumCacheTtl() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); final Uri URL5 = Uri.parse("http://example.org/5.js"); final Uri URL6 = Uri.parse("http://example.org/6.js"); final Integer cacheTtl4 = Integer.MAX_VALUE; final Integer cacheTtl5 = 100000; final Integer cacheTtl6 = Integer.MAX_VALUE; expectGetAndSetCacheTtl(URL4, cacheTtl4); expectGetAndSetCacheTtl(URL5, cacheTtl5); expectGetAndSetCacheTtl(URL6, cacheTtl6); expectRequestWithUris(Lists.newArrayList(URL4, URL5, URL6)); // Run the servlet servlet.doGet(request, recorder); verify(); int cacheValue = getCacheControlMaxAge(recorder); assertEquals(cacheTtl5, cacheValue, 10); }
@Test public void testMinimumCacheTtl() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); final Uri URL5 = Uri.parse("http://example.org/5.js"); final Uri URL6 = Uri.parse("http://example.org/6.js"); final Integer cacheTtl4 = Integer.MAX_VALUE; final Integer cacheTtl5 = 100000; final Integer cacheTtl6 = Integer.MAX_VALUE; expectGetAndSetCacheTtl(URL4, cacheTtl4); expectGetAndSetCacheTtl(URL5, cacheTtl5); expectGetAndSetCacheTtl(URL6, cacheTtl6); expectRequestWithUris(Lists.newArrayList(URL4, URL5, URL6)); // Run the servlet servlet.doGet(request, recorder); verify(); int cacheValue = getCacheControlMaxAge(recorder); assertEquals(cacheTtl5, cacheValue, 10); }