hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1058661 - /httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java
Date Thu, 13 Jan 2011 17:00:30 GMT
Author: jonm
Date: Thu Jan 13 17:00:30 2011
New Revision: 1058661

URL: http://svn.apache.org/viewvc?rev=1058661&view=rev
Log:
Capture acceptance tests for only-if-cached (implementation
already passes these).

"To do this, the client may include the only-if-cached directive
in a request. If it receives this directive, a cache SHOULD
either respond using a cached entry that is consistent with the
other constraints of the request, or respond with a 504 (Gateway
Timeout) status."

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.4

Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java?rev=1058661&r1=1058660&r2=1058661&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java
Thu Jan 13 17:00:30 2011
@@ -1374,4 +1374,91 @@ public class TestProtocolRecommendations
         assertTrue(foundNoCache);
         assertFalse(foundDisallowedDirective);
     }
+    
+    /*
+     * "To do this, the client may include the only-if-cached directive in
+     * a request. If it receives this directive, a cache SHOULD either
+     * respond using a cached entry that is consistent with the other
+     * constraints of the request, or respond with a 504 (Gateway Timeout)
+     * status."
+     * 
+     * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.4
+     */
+    @Test
+    public void cacheMissResultsIn504WithOnlyIfCached()
+        throws Exception {
+        HttpRequest req = HttpTestUtils.makeDefaultRequest();
+        req.setHeader("Cache-Control", "only-if-cached");
+        
+        replayMocks();
+        HttpResponse result = impl.execute(host, req);
+        verifyMocks();
+        
+        assertEquals(HttpStatus.SC_GATEWAY_TIMEOUT,
+                result.getStatusLine().getStatusCode());
+    }
+    
+    @Test
+    public void cacheHitOkWithOnlyIfCached()
+        throws Exception {
+        HttpRequest req1 = HttpTestUtils.makeDefaultRequest();
+        HttpResponse resp1 = HttpTestUtils.make200Response();
+        resp1.setHeader("Cache-Control","max-age=3600");
+        
+        backendExpectsAnyRequest().andReturn(resp1);
+        
+        HttpRequest req2 = HttpTestUtils.makeDefaultRequest();
+        req2.setHeader("Cache-Control", "only-if-cached");
+        
+        replayMocks();
+        impl.execute(host, req1);
+        HttpResponse result = impl.execute(host, req2);
+        verifyMocks();
+        
+        assertTrue(HttpTestUtils.semanticallyTransparent(resp1, result));
+    }
+    
+    @Test
+    public void returns504ForStaleEntryWithOnlyIfCached()
+        throws Exception {
+        HttpRequest req1 = HttpTestUtils.makeDefaultRequest();
+        HttpResponse resp1 = HttpTestUtils.make200Response();
+        resp1.setHeader("Date", formatDate(tenSecondsAgo));
+        resp1.setHeader("Cache-Control","max-age=5");
+        
+        backendExpectsAnyRequest().andReturn(resp1);
+        
+        HttpRequest req2 = HttpTestUtils.makeDefaultRequest();
+        req2.setHeader("Cache-Control", "only-if-cached");
+        
+        replayMocks();
+        impl.execute(host, req1);
+        HttpResponse result = impl.execute(host, req2);
+        verifyMocks();
+        
+        assertEquals(HttpStatus.SC_GATEWAY_TIMEOUT,
+                result.getStatusLine().getStatusCode());
+    }
+    
+    @Test
+    public void returnsStaleCacheEntryWithOnlyIfCachedAndMaxStale()
+        throws Exception {
+
+        HttpRequest req1 = HttpTestUtils.makeDefaultRequest();
+        HttpResponse resp1 = HttpTestUtils.make200Response();
+        resp1.setHeader("Date", formatDate(tenSecondsAgo));
+        resp1.setHeader("Cache-Control","max-age=5");
+        
+        backendExpectsAnyRequest().andReturn(resp1);
+        
+        HttpRequest req2 = HttpTestUtils.makeDefaultRequest();
+        req2.setHeader("Cache-Control", "max-stale=20, only-if-cached");
+        
+        replayMocks();
+        impl.execute(host, req1);
+        HttpResponse result = impl.execute(host, req2);
+        verifyMocks();
+        
+        assertTrue(HttpTestUtils.semanticallyTransparent(resp1, result));
+    }
 }



Mime
View raw message