@Test public void testIsError() { // These aren't all valid status codes, but they're reserved in these blocks. Changes // would be required to the HTTP standard anyway before this test would be invalid. for (int i = 100; i < 400; i += 100) { for (int j = 0; j < 10; ++j) { HttpResponse response = new HttpResponseBuilder().setHttpStatusCode(i).create(); assertFalse("Status below 400 considered to be an error", response.isError()); } } for (int i = 400; i < 600; i += 100) { for (int j = 0; j < 10; ++j) { HttpResponse response = new HttpResponseBuilder().setHttpStatusCode(i).create(); assertTrue("Status above 400 considered to be an error", response.isError()); } } }
@Test public void testIsError() { // These aren't all valid status codes, but they're reserved in these blocks. Changes // would be required to the HTTP standard anyway before this test would be invalid. for (int i = 100; i < 400; i += 100) { for (int j = 0; j < 10; ++j) { HttpResponse response = new HttpResponseBuilder().setHttpStatusCode(i).create(); assertFalse("Status below 400 considered to be an error", response.isError()); } } for (int i = 400; i < 600; i += 100) { for (int j = 0; j < 10; ++j) { HttpResponse response = new HttpResponseBuilder().setHttpStatusCode(i).create(); assertTrue("Status above 400 considered to be an error", response.isError()); } } }
@Test public void testIsError() { // These aren't all valid status codes, but they're reserved in these blocks. Changes // would be required to the HTTP standard anyway before this test would be invalid. for (int i = 100; i < 400; i += 100) { for (int j = 0; j < 10; ++j) { HttpResponse response = new HttpResponseBuilder().setHttpStatusCode(i).create(); assertFalse("Status below 400 considered to be an error", response.isError()); } } for (int i = 400; i < 600; i += 100) { for (int j = 0; j < 10; ++j) { HttpResponse response = new HttpResponseBuilder().setHttpStatusCode(i).create(); assertTrue("Status above 400 considered to be an error", response.isError()); } } }
@Test public void testStrictPragmaJunk() throws Exception { HttpResponse response = new HttpResponseBuilder() .addHeader("Pragma", "junk") .create(); assertFalse(response.isStrictNoCache()); int expected = roundToSeconds(timeSource.currentTimeMillis() + response.getDefaultTtl()); int expires = roundToSeconds(response.getCacheExpiration()); assertEquals(expected, expires); assertTrue(response.getCacheTtl() <= response.getDefaultTtl() && response.getCacheTtl() > 0); }
@Test public void testStrictPragmaJunk() throws Exception { HttpResponse response = new HttpResponseBuilder() .addHeader("Pragma", "junk") .create(); assertFalse(response.isStrictNoCache()); int expected = roundToSeconds(timeSource.currentTimeMillis() + response.getDefaultTtl()); int expires = roundToSeconds(response.getCacheExpiration()); assertEquals(expected, expires); assertTrue(response.getCacheTtl() <= response.getDefaultTtl() && response.getCacheTtl() > 0); }
@Test public void testStrictPragmaJunk() throws Exception { HttpResponse response = new HttpResponseBuilder() .addHeader("Pragma", "junk") .create(); assertFalse(response.isStrictNoCache()); int expected = roundToSeconds(timeSource.currentTimeMillis() + response.getDefaultTtl()); int expires = roundToSeconds(response.getCacheExpiration()); assertEquals(expected, expires); assertTrue(response.getCacheTtl() <= response.getDefaultTtl() && response.getCacheTtl() > 0); }
@Test public void testCachingHeadersIgnoredOnError() throws Exception { HttpResponse response = new HttpResponseBuilder() .addHeader("Cache-Control", "no-cache") .setHttpStatusCode(404) .create(); assertFalse(response.isStrictNoCache()); response = new HttpResponseBuilder() .addHeader("Cache-Control", "no-cache") .setHttpStatusCode(403) .create(); assertTrue(response.isStrictNoCache()); response = new HttpResponseBuilder() .addHeader("Cache-Control", "no-cache") .setHttpStatusCode(401) .create(); assertTrue(response.isStrictNoCache()); }
@Test public void testCachingHeadersIgnoredOnError() throws Exception { HttpResponse response = new HttpResponseBuilder() .addHeader("Cache-Control", "no-cache") .setHttpStatusCode(404) .create(); assertFalse(response.isStrictNoCache()); response = new HttpResponseBuilder() .addHeader("Cache-Control", "no-cache") .setHttpStatusCode(403) .create(); assertTrue(response.isStrictNoCache()); response = new HttpResponseBuilder() .addHeader("Cache-Control", "no-cache") .setHttpStatusCode(401) .create(); assertTrue(response.isStrictNoCache()); }
@Test public void testCachingHeadersIgnoredOnError() throws Exception { HttpResponse response = new HttpResponseBuilder() .addHeader("Cache-Control", "no-cache") .setHttpStatusCode(404) .create(); assertFalse(response.isStrictNoCache()); response = new HttpResponseBuilder() .addHeader("Cache-Control", "no-cache") .setHttpStatusCode(403) .create(); assertTrue(response.isStrictNoCache()); response = new HttpResponseBuilder() .addHeader("Cache-Control", "no-cache") .setHttpStatusCode(401) .create(); assertTrue(response.isStrictNoCache()); }