From 759fe0a7557a5267e4d3384ea1c3221b279d4dd5 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Date: Wed, 12 Jan 2011 16:38:28 +0000 Subject: [PATCH] Added unit tests to document protocol recommendation: "A cache that passes through requests for methods it does not understand SHOULD invalidate any entities referred to by the Request-URI." http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.10 (Current implementation already does this, but always good to have that captured in an automated acceptance test). git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1058224 13f79535-47bb-0310-9956-ffa450edef68 --- .../cache/TestProtocolRecommendations.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java index b3c05cd12..0a3f4fc33 100644 --- a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java +++ b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java @@ -1142,4 +1142,93 @@ public class TestProtocolRecommendations extends AbstractProtocolTest { verifyMocks(); } + /* + * "A cache that passes through requests for methods it does not + * understand SHOULD invalidate any entities referred to by the + * Request-URI." + * + * http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.10 + */ + @Test + public void shouldInvalidateNonvariantCacheEntryForUnknownMethod() + throws Exception { + HttpRequest req1 = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); + HttpResponse resp1 = HttpTestUtils.make200Response(); + resp1.setHeader("Cache-Control","max-age=3600"); + + backendExpectsAnyRequest().andReturn(resp1); + + HttpRequest req2 = new BasicHttpRequest("FROB", "/", HttpVersion.HTTP_1_1); + HttpResponse resp2 = HttpTestUtils.make200Response(); + resp2.setHeader("Cache-Control","max-age=3600"); + + backendExpectsAnyRequest().andReturn(resp2); + + HttpRequest req3 = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); + HttpResponse resp3 = HttpTestUtils.make200Response(); + resp3.setHeader("ETag", "\"etag\""); + + backendExpectsAnyRequest().andReturn(resp3); + + replayMocks(); + impl.execute(host, req1); + impl.execute(host, req2); + HttpResponse result = impl.execute(host, req3); + verifyMocks(); + + assertTrue(HttpTestUtils.semanticallyTransparent(resp3, result)); + } + + @Test + public void shouldInvalidateAllVariantsForUnknownMethod() + throws Exception { + HttpRequest req1 = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); + req1.setHeader("User-Agent", "agent1"); + HttpResponse resp1 = HttpTestUtils.make200Response(); + resp1.setHeader("Cache-Control","max-age=3600"); + resp1.setHeader("Vary", "User-Agent"); + + backendExpectsAnyRequest().andReturn(resp1); + + HttpRequest req2 = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); + req2.setHeader("User-Agent", "agent2"); + HttpResponse resp2 = HttpTestUtils.make200Response(); + resp2.setHeader("Cache-Control","max-age=3600"); + resp2.setHeader("Vary", "User-Agent"); + + backendExpectsAnyRequest().andReturn(resp2); + + HttpRequest req3 = new BasicHttpRequest("FROB", "/", HttpVersion.HTTP_1_1); + req3.setHeader("User-Agent", "agent3"); + HttpResponse resp3 = HttpTestUtils.make200Response(); + resp3.setHeader("Cache-Control","max-age=3600"); + + backendExpectsAnyRequest().andReturn(resp3); + + HttpRequest req4 = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); + req4.setHeader("User-Agent", "agent1"); + HttpResponse resp4 = HttpTestUtils.make200Response(); + resp4.setHeader("ETag", "\"etag1\""); + + backendExpectsAnyRequest().andReturn(resp4); + + HttpRequest req5 = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); + req5.setHeader("User-Agent", "agent2"); + HttpResponse resp5 = HttpTestUtils.make200Response(); + resp5.setHeader("ETag", "\"etag2\""); + + backendExpectsAnyRequest().andReturn(resp5); + + replayMocks(); + impl.execute(host, req1); + impl.execute(host, req2); + impl.execute(host, req3); + HttpResponse result4 = impl.execute(host, req4); + HttpResponse result5 = impl.execute(host, req5); + verifyMocks(); + + assertTrue(HttpTestUtils.semanticallyTransparent(resp4, result4)); + assertTrue(HttpTestUtils.semanticallyTransparent(resp5, result5)); + } + }