@Test public void testMaxAgeNoDate() throws Exception { int maxAge = 10; // Guess time. int expected = roundToSeconds(timeSource.currentTimeMillis()) + maxAge; HttpResponse response = new HttpResponseBuilder() .addHeader("Cache-Control", "public, max-age=" + maxAge) .create(); int expiration = roundToSeconds(response.getCacheExpiration()); assertEquals(expected, expiration); assertTtlOk(maxAge, response); }
@Test public void testMaxAgeNoDate() throws Exception { int maxAge = 10; // Guess time. int expected = roundToSeconds(timeSource.currentTimeMillis()) + maxAge; HttpResponse response = new HttpResponseBuilder() .addHeader("Cache-Control", "public, max-age=" + maxAge) .create(); int expiration = roundToSeconds(response.getCacheExpiration()); assertEquals(expected, expiration); assertTtlOk(maxAge, response); }
@Test public void testMaxAgeNoDate() throws Exception { int maxAge = 10; // Guess time. int expected = roundToSeconds(timeSource.currentTimeMillis()) + maxAge; HttpResponse response = new HttpResponseBuilder() .addHeader("Cache-Control", "public, max-age=" + maxAge) .create(); int expiration = roundToSeconds(response.getCacheExpiration()); assertEquals(expected, expiration); assertTtlOk(maxAge, response); }
@Test public void testExpires() throws Exception { int maxAge = 10; int time = roundToSeconds(timeSource.currentTimeMillis()) + maxAge; HttpResponse response = new HttpResponseBuilder() .addHeader("Expires", DateUtil.formatRfc1123Date(1000L * time)) .create(); assertEquals(time, roundToSeconds(response.getCacheExpiration())); // Second rounding makes this n-1. assertTtlOk(maxAge, response); }
@Test public void testExpires() throws Exception { int maxAge = 10; int time = roundToSeconds(timeSource.currentTimeMillis()) + maxAge; HttpResponse response = new HttpResponseBuilder() .addHeader("Expires", DateUtil.formatRfc1123Date(1000L * time)) .create(); assertEquals(time, roundToSeconds(response.getCacheExpiration())); // Second rounding makes this n-1. assertTtlOk(maxAge, response); }
@Test public void testExpires() throws Exception { int maxAge = 10; int time = roundToSeconds(timeSource.currentTimeMillis()) + maxAge; HttpResponse response = new HttpResponseBuilder() .addHeader("Expires", DateUtil.formatRfc1123Date(1000L * time)) .create(); assertEquals(time, roundToSeconds(response.getCacheExpiration())); // Second rounding makes this n-1. assertTtlOk(maxAge, response); }
@Test public void testMaxAgeInvalidDate() throws Exception { int maxAge = 10; // Guess time. int expected = roundToSeconds(timeSource.currentTimeMillis()) + maxAge; HttpResponse response = new HttpResponseBuilder() .addHeader("Date", "Wed, 09 Jul 2008 19:18:33 EDT") .addHeader("Cache-Control", "public, max-age=" + maxAge) .create(); int expiration = roundToSeconds(response.getCacheExpiration()); assertEquals(expected, expiration); assertTtlOk(maxAge, response); }
@Test public void testMaxAgeWithDate() throws Exception { int maxAge = 10; int now = roundToSeconds(timeSource.currentTimeMillis()); HttpResponse response = new HttpResponseBuilder() .addHeader("Date", DateUtil.formatRfc1123Date(1000L * now)) .addHeader("Cache-Control", "public, max-age=" + maxAge) .create(); assertEquals(now + maxAge, roundToSeconds(response.getCacheExpiration())); assertTtlOk(maxAge, response); }
@Test public void testMaxAgeInvalidDate() throws Exception { int maxAge = 10; // Guess time. int expected = roundToSeconds(timeSource.currentTimeMillis()) + maxAge; HttpResponse response = new HttpResponseBuilder() .addHeader("Date", "Wed, 09 Jul 2008 19:18:33 EDT") .addHeader("Cache-Control", "public, max-age=" + maxAge) .create(); int expiration = roundToSeconds(response.getCacheExpiration()); assertEquals(expected, expiration); assertTtlOk(maxAge, response); }
@Test public void testMaxAgeInvalidDate() throws Exception { int maxAge = 10; // Guess time. int expected = roundToSeconds(timeSource.currentTimeMillis()) + maxAge; HttpResponse response = new HttpResponseBuilder() .addHeader("Date", "Wed, 09 Jul 2008 19:18:33 EDT") .addHeader("Cache-Control", "public, max-age=" + maxAge) .create(); int expiration = roundToSeconds(response.getCacheExpiration()); assertEquals(expected, expiration); assertTtlOk(maxAge, response); }
@Test public void testMaxAgeWithDate() throws Exception { int maxAge = 10; int now = roundToSeconds(timeSource.currentTimeMillis()); HttpResponse response = new HttpResponseBuilder() .addHeader("Date", DateUtil.formatRfc1123Date(1000L * now)) .addHeader("Cache-Control", "public, max-age=" + maxAge) .create(); assertEquals(now + maxAge, roundToSeconds(response.getCacheExpiration())); assertTtlOk(maxAge, response); }
@Test public void testMaxAgeWithDate() throws Exception { int maxAge = 10; int now = roundToSeconds(timeSource.currentTimeMillis()); HttpResponse response = new HttpResponseBuilder() .addHeader("Date", DateUtil.formatRfc1123Date(1000L * now)) .addHeader("Cache-Control", "public, max-age=" + maxAge) .create(); assertEquals(now + maxAge, roundToSeconds(response.getCacheExpiration())); assertTtlOk(maxAge, response); }
@Test public void testFixedDateNew() throws Exception { int time = roundToSeconds(timeSource.currentTimeMillis()); HttpResponse response = new HttpResponseBuilder() .addHeader("Date", DateUtil.formatRfc1123Date(1000L * time + 1000 + HttpResponse.DEFAULT_DRIFT_LIMIT_MS)) .create(); // Verify that the old time is ignored: assertEquals(time + roundToSeconds(response.getDefaultTtl()), roundToSeconds(response.getCacheExpiration())); assertTtlOk(roundToSeconds(response.getDefaultTtl()), response); }
@Test public void testFixedDate() throws Exception { int time = roundToSeconds(timeSource.currentTimeMillis()); HttpResponse response = new HttpResponseBuilder() .addHeader("Date", DateUtil.formatRfc1123Date(1000L * time)) .create(); assertEquals(time + roundToSeconds(response.getDefaultTtl()), roundToSeconds(response.getCacheExpiration())); assertEquals(DateUtil.formatRfc1123Date(timeSource.currentTimeMillis()), response.getHeader("Date")); assertTtlOk(roundToSeconds(response.getDefaultTtl()), response); }
@Test public void testFixedDate() throws Exception { int time = roundToSeconds(timeSource.currentTimeMillis()); HttpResponse response = new HttpResponseBuilder() .addHeader("Date", DateUtil.formatRfc1123Date(1000L * time)) .create(); assertEquals(time + roundToSeconds(response.getDefaultTtl()), roundToSeconds(response.getCacheExpiration())); assertEquals(DateUtil.formatRfc1123Date(timeSource.currentTimeMillis()), response.getHeader("Date")); assertTtlOk(roundToSeconds(response.getDefaultTtl()), response); }
@Test public void testFixedDate() throws Exception { int time = roundToSeconds(timeSource.currentTimeMillis()); HttpResponse response = new HttpResponseBuilder() .addHeader("Date", DateUtil.formatRfc1123Date(1000L * time)) .create(); assertEquals(time + roundToSeconds(response.getDefaultTtl()), roundToSeconds(response.getCacheExpiration())); assertEquals(DateUtil.formatRfc1123Date(timeSource.currentTimeMillis()), response.getHeader("Date")); assertTtlOk(roundToSeconds(response.getDefaultTtl()), response); }
@Test public void testFixedDateOld() throws Exception { int time = roundToSeconds(timeSource.currentTimeMillis()); HttpResponse response = new HttpResponseBuilder() .addHeader("Date", DateUtil.formatRfc1123Date(1000L * time - 1000 - HttpResponse.DEFAULT_DRIFT_LIMIT_MS)) .create(); // Verify that the old time is ignored: assertEquals(time + roundToSeconds(response.getDefaultTtl()), roundToSeconds(response.getCacheExpiration())); assertEquals(DateUtil.formatRfc1123Date(timeSource.currentTimeMillis()), response.getHeader("Date")); assertTtlOk(roundToSeconds(response.getDefaultTtl()), response); }