@Test public void test203ResponseCodeIsCacheable() { response.setCode(HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION); Assert.assertTrue(policy.isResponseCacheable("GET", response)); }
@Test public void test410ResponseCodeIsCacheable() { response.setCode(HttpStatus.SC_GONE); Assert.assertTrue(policy.isResponseCacheable("GET", response)); }
@Test public void test301ResponseCodeIsCacheable() { response.setCode(HttpStatus.SC_MOVED_PERMANENTLY); Assert.assertTrue(policy.isResponseCacheable("GET", response)); }
@Test public void test206ResponseCodeIsNotCacheable() { response.setCode(HttpStatus.SC_PARTIAL_CONTENT); Assert.assertFalse(policy.isResponseCacheable("GET", response)); }
@Test public void test300ResponseCodeIsCacheable() { response.setCode(HttpStatus.SC_MULTIPLE_CHOICES); Assert.assertTrue(policy.isResponseCacheable("GET", response)); }
@Test public void testNon206WithExplicitExpiresIsCacheable() { final int status = getRandomStatus(); response.setCode(status); response.setHeader("Expires", DateUtils.formatDate(new Date())); Assert.assertTrue(policy.isResponseCacheable("GET", response)); }
@Test public void testPlain307ResponseCodeIsNotCacheable() { response.setCode(HttpStatus.SC_TEMPORARY_REDIRECT); response.removeHeaders("Expires"); response.removeHeaders("Cache-Control"); Assert.assertFalse(policy.isResponseCacheable("GET", response)); }
@Test public void testNon206WithPublicCacheControlIsCacheable() { final int status = getRandomStatus(); response.setCode(status); response.setHeader("Cache-Control", "public"); Assert.assertTrue(policy.isResponseCacheable("GET", response)); }
@Test public void testNon206WithSMaxAgeIsCacheable() { final int status = getRandomStatus(); response.setCode(status); response.setHeader("Cache-Control", "s-maxage=0"); Assert.assertTrue(policy.isResponseCacheable("GET", response)); }
@Test public void testNon206WithProxyRevalidateIsCacheable() { final int status = getRandomStatus(); response.setCode(status); response.setHeader("Cache-Control", "proxy-revalidate"); Assert.assertTrue(policy.isResponseCacheable("GET", response)); }
@Test public void testPlain303ResponseCodeIsNotCacheableUnderDefaultBehavior() { response.setCode(HttpStatus.SC_SEE_OTHER); response.removeHeaders("Expires"); response.removeHeaders("Cache-Control"); Assert.assertFalse(policy.isResponseCacheable("GET", response)); }
@Test public void testNon206WithPrivateCacheControlIsNotCacheableBySharedCache() { final int status = getRandomStatus(); response.setCode(status); response.setHeader("Cache-Control", "private"); Assert.assertFalse(policy.isResponseCacheable("GET", response)); }
@Test public void testNon206WithMustRevalidateIsCacheable() { final int status = getRandomStatus(); response.setCode(status); response.setHeader("Cache-Control", "must-revalidate"); Assert.assertTrue(policy.isResponseCacheable("GET", response)); }
@Test public void test307WithExplicitCachingHeaders() { response.setCode(HttpStatus.SC_TEMPORARY_REDIRECT); response.setHeader("Date", DateUtils.formatDate(now)); response.setHeader("Cache-Control","max-age=300"); Assert.assertTrue(policy.isResponseCacheable(request, response)); }
@Test public void test206ResponseCodeIsNotCacheableUsingSharedPublicCache() { policy = new ResponseCachingPolicy(0, true, false, false); request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); response.setCode(HttpStatus.SC_PARTIAL_CONTENT); response.setHeader("Cache-Control", "public"); Assert.assertFalse(policy.isResponseCacheable(request, response)); }
@Test public void otherStatusCodesAreCacheableWithExplicitCachingHeaders() { response.setCode(HttpStatus.SC_NOT_FOUND); response.setHeader("Date", DateUtils.formatDate(now)); response.setHeader("Cache-Control","max-age=300"); Assert.assertTrue(policy.isResponseCacheable(request, response)); }
@Test public void test302WithExplicitCachingHeaders() { response.setCode(HttpStatus.SC_MOVED_TEMPORARILY); response.setHeader("Date", DateUtils.formatDate(now)); response.setHeader("Cache-Control","max-age=300"); Assert.assertTrue(policy.isResponseCacheable(request, response)); }
@Test public void test303WithExplicitCachingHeadersUnderDefaultBehavior() { // RFC 2616 says: 303 should not be cached response.setCode(HttpStatus.SC_SEE_OTHER); response.setHeader("Date", DateUtils.formatDate(now)); response.setHeader("Cache-Control","max-age=300"); Assert.assertFalse(policy.isResponseCacheable(request, response)); }
@Test public void testPlain303ResponseCodeIsNotCacheableEvenIf303CachingEnabled() { policy = new ResponseCachingPolicy(0, true, false, true); response.setCode(HttpStatus.SC_SEE_OTHER); response.removeHeaders("Expires"); response.removeHeaders("Cache-Control"); Assert.assertFalse(policy.isResponseCacheable("GET", response)); }
@Test public void testIsArbitraryMethodCacheableUsingSharedPublicCache() { policy = new ResponseCachingPolicy(0, true, false, false); request = new HttpOptions("http://foo.example.com/"); request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); response.setCode(HttpStatus.SC_NO_CONTENT); response.setHeader("Cache-Control", "public"); Assert.assertFalse(policy.isResponseCacheable(request, response)); }