hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1494755 [2/4] - in /httpcomponents/httpclient/trunk/httpclient-cache: ./ src/test/java/org/apache/http/impl/client/cache/
Date Wed, 19 Jun 2013 19:50:03 GMT
Copied: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java (from r1494747, httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java?p2=httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java&p1=httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java&r1=1494747&r2=1494755&rev=1494755&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingExecChain.java Wed Jun 19 19:50:02 2013
@@ -32,8 +32,6 @@ import static org.easymock.EasyMock.expe
 import static org.easymock.EasyMock.expectLastCall;
 import static org.easymock.EasyMock.isA;
 import static org.easymock.EasyMock.isNull;
-import static org.easymock.EasyMock.same;
-import static org.easymock.classextension.EasyMock.createMockBuilder;
 import static org.easymock.classextension.EasyMock.createNiceMock;
 import static org.easymock.classextension.EasyMock.replay;
 import static org.easymock.classextension.EasyMock.verify;
@@ -48,9 +46,7 @@ import java.net.SocketException;
 import java.net.SocketTimeoutException;
 import java.util.ArrayList;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import junit.framework.AssertionFailedError;
 
@@ -88,47 +84,35 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-public class TestCachingExec {
+public abstract class TestCachingExecChain {
 
-    private static final String GET_CURRENT_DATE = "getCurrentDate";
+    private ClientExecChain impl;
 
-    private static final String HANDLE_BACKEND_RESPONSE = "handleBackendResponse";
-
-    private static final String CALL_BACKEND = "callBackend";
-
-    private static final String REVALIDATE_CACHE_ENTRY = "revalidateCacheEntry";
-
-    private CachingExec impl;
-    private boolean mockedImpl;
-
-    private CacheValidityPolicy mockValidityPolicy;
-    private CacheableRequestPolicy mockRequestPolicy;
-    private ClientExecChain mockBackend;
-    private HttpCache mockCache;
+    protected CacheValidityPolicy mockValidityPolicy;
+    protected CacheableRequestPolicy mockRequestPolicy;
+    protected ClientExecChain mockBackend;
+    protected HttpCache mockCache;
     private HttpCacheStorage mockStorage;
-    private CachedResponseSuitabilityChecker mockSuitabilityChecker;
-    private ResponseCachingPolicy mockResponsePolicy;
-    private CloseableHttpResponse mockBackendResponse;
-    private HttpCacheEntry mockCacheEntry;
-    private CachedHttpResponseGenerator mockResponseGenerator;
+    protected CachedResponseSuitabilityChecker mockSuitabilityChecker;
+    protected ResponseCachingPolicy mockResponsePolicy;
+    protected HttpCacheEntry mockCacheEntry;
+    protected CachedHttpResponseGenerator mockResponseGenerator;
     private ResponseHandler<Object> mockHandler;
     private HttpUriRequest mockUriRequest;
     private CloseableHttpResponse mockCachedResponse;
-    private ConditionalRequestBuilder mockConditionalRequestBuilder;
+    protected ConditionalRequestBuilder mockConditionalRequestBuilder;
     private HttpRequest mockConditionalRequest;
     private StatusLine mockStatusLine;
-    private ResponseProtocolCompliance mockResponseProtocolCompliance;
-    private RequestProtocolCompliance mockRequestProtocolCompliance;
-    private CacheConfig config;
-    private AsynchronousValidator asyncValidator;
-
-    private Date requestDate;
-    private Date responseDate;
-    private HttpRoute route;
-    private HttpHost host;
-    private HttpRequestWrapper request;
-    private HttpCacheContext context;
-    private HttpCacheEntry entry;
+    protected ResponseProtocolCompliance mockResponseProtocolCompliance;
+    protected RequestProtocolCompliance mockRequestProtocolCompliance;
+    protected CacheConfig config;
+    protected AsynchronousValidator asyncValidator;
+
+    protected HttpRoute route;
+    protected HttpHost host;
+    protected HttpRequestWrapper request;
+    protected HttpCacheContext context;
+    protected HttpCacheEntry entry;
 
     @SuppressWarnings("unchecked")
     @Before
@@ -140,7 +124,6 @@ public class TestCachingExec {
         mockSuitabilityChecker = createNiceMock(CachedResponseSuitabilityChecker.class);
         mockResponsePolicy = createNiceMock(ResponseCachingPolicy.class);
         mockHandler = createNiceMock(ResponseHandler.class);
-        mockBackendResponse = createNiceMock(CloseableHttpResponse.class);
         mockUriRequest = createNiceMock(HttpUriRequest.class);
         mockCacheEntry = createNiceMock(HttpCacheEntry.class);
         mockResponseGenerator = createNiceMock(CachedHttpResponseGenerator.class);
@@ -154,15 +137,13 @@ public class TestCachingExec {
         config = CacheConfig.DEFAULT;
         asyncValidator = new AsynchronousValidator(config);
 
-        requestDate = new Date(System.currentTimeMillis() - 1000);
-        responseDate = new Date();
         host = new HttpHost("foo.example.com");
         route = new HttpRoute(host);
         request = HttpRequestWrapper.wrap(
                 new BasicHttpRequest("GET", "/stuff", HttpVersion.HTTP_1_1));
         context = HttpCacheContext.create();
         entry = HttpTestUtils.makeCacheEntry();
-        impl = new CachingExec(
+        impl = createCachingExecChain(
                 mockBackend,
                 mockCache,
                 mockValidityPolicy,
@@ -177,7 +158,32 @@ public class TestCachingExec {
                 asyncValidator);
     }
 
-    private void replayMocks() {
+    public abstract ClientExecChain createCachingExecChain(
+            ClientExecChain backend, HttpCache responseCache,
+            CacheValidityPolicy validityPolicy,
+            ResponseCachingPolicy responseCachingPolicy,
+            CachedHttpResponseGenerator responseGenerator,
+            CacheableRequestPolicy cacheableRequestPolicy,
+            CachedResponseSuitabilityChecker suitabilityChecker,
+            ConditionalRequestBuilder conditionalRequestBuilder,
+            ResponseProtocolCompliance responseCompliance,
+            RequestProtocolCompliance requestCompliance, CacheConfig config,
+            AsynchronousValidator asynchRevalidator);
+
+    public abstract ClientExecChain createCachingExecChain(
+            ClientExecChain backend, HttpCache cache, CacheConfig config);
+
+    public static HttpRequestWrapper eqRequest(final HttpRequestWrapper in) {
+        EasyMock.reportMatcher(new RequestEquivalent(in));
+        return null;
+    }
+
+    public static <R extends HttpResponse> R eqResponse(final R in) {
+        EasyMock.reportMatcher(new ResponseEquivalent(in));
+        return null;
+    }
+
+    protected void replayMocks() {
         replay(mockRequestPolicy);
         replay(mockValidityPolicy);
         replay(mockSuitabilityChecker);
@@ -187,7 +193,6 @@ public class TestCachingExec {
         replay(mockBackend);
         replay(mockCache);
         replay(mockHandler);
-        replay(mockBackendResponse);
         replay(mockUriRequest);
         replay(mockCachedResponse);
         replay(mockConditionalRequestBuilder);
@@ -196,12 +201,9 @@ public class TestCachingExec {
         replay(mockResponseProtocolCompliance);
         replay(mockRequestProtocolCompliance);
         replay(mockStorage);
-        if (mockedImpl) {
-            replay(impl);
-        }
     }
 
-    private void verifyMocks() {
+    protected void verifyMocks() {
         verify(mockRequestPolicy);
         verify(mockValidityPolicy);
         verify(mockSuitabilityChecker);
@@ -211,7 +213,6 @@ public class TestCachingExec {
         verify(mockBackend);
         verify(mockCache);
         verify(mockHandler);
-        verify(mockBackendResponse);
         verify(mockUriRequest);
         verify(mockCachedResponse);
         verify(mockConditionalRequestBuilder);
@@ -220,14 +221,11 @@ public class TestCachingExec {
         verify(mockResponseProtocolCompliance);
         verify(mockRequestProtocolCompliance);
         verify(mockStorage);
-        if (mockedImpl) {
-            verify(impl);
-        }
     }
 
     @Test
     public void testCacheableResponsesGoIntoCache() throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
 
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
         final HttpResponse resp1 = HttpTestUtils.make200Response();
@@ -238,14 +236,14 @@ public class TestCachingExec {
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
 
         replayMocks();
-        impl.execute(route, req1);
-        impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        impl.execute(route, req2, context, null);
         verifyMocks();
     }
 
     @Test
     public void testOlderCacheableResponsesDoNotGoIntoCache() throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
         final Date fiveSecondsAgo = new Date(now.getTime() - 5 * 1000L);
 
@@ -269,9 +267,9 @@ public class TestCachingExec {
         final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
 
         replayMocks();
-        impl.execute(route, req1);
-        impl.execute(route, req2);
-        final HttpResponse result = impl.execute(route, req3);
+        impl.execute(route, req1, context, null);
+        impl.execute(route, req2, context, null);
+        final HttpResponse result = impl.execute(route, req3, context, null);
         verifyMocks();
 
         assertEquals("\"new-etag\"", result.getFirstHeader("ETag").getValue());
@@ -279,7 +277,7 @@ public class TestCachingExec {
 
     @Test
     public void testNewerCacheableResponsesReplaceExistingCacheEntry() throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
         final Date fiveSecondsAgo = new Date(now.getTime() - 5 * 1000L);
 
@@ -303,181 +301,25 @@ public class TestCachingExec {
         final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
 
         replayMocks();
-        impl.execute(route, req1);
-        impl.execute(route, req2);
-        final HttpResponse result = impl.execute(route, req3);
+        impl.execute(route, req1, context, null);
+        impl.execute(route, req2, context, null);
+        final HttpResponse result = impl.execute(route, req3, context, null);
         verifyMocks();
 
         assertEquals("\"new-etag\"", result.getFirstHeader("ETag").getValue());
     }
 
-
-    @Test
-    public void testRequestThatCannotBeServedFromCacheCausesBackendRequest() throws Exception {
-        cacheInvalidatorWasCalled();
-        requestPolicyAllowsCaching(false);
-        mockImplMethods(CALL_BACKEND);
-
-        implExpectsAnyRequestAndReturn(mockBackendResponse);
-        requestIsFatallyNonCompliant(null);
-
-        replayMocks();
-        final HttpResponse result = impl.execute(route, request, context);
-        verifyMocks();
-
-        Assert.assertSame(mockBackendResponse, result);
-    }
-
-    private void requestIsFatallyNonCompliant(final RequestProtocolError error) {
+    protected void requestIsFatallyNonCompliant(final RequestProtocolError error) {
         final List<RequestProtocolError> errors = new ArrayList<RequestProtocolError>();
         if (error != null) {
             errors.add(error);
         }
         expect(
-                mockRequestProtocolCompliance.requestIsFatallyNonCompliant(request)).andReturn(
+                mockRequestProtocolCompliance.requestIsFatallyNonCompliant(eqRequest(request))).andReturn(
                 errors);
     }
 
     @Test
-    public void testCacheMissCausesBackendRequest() throws Exception {
-        mockImplMethods(CALL_BACKEND);
-        cacheInvalidatorWasCalled();
-        requestPolicyAllowsCaching(true);
-        getCacheEntryReturns(null);
-        getVariantCacheEntriesReturns(new HashMap<String,Variant>());
-
-        requestIsFatallyNonCompliant(null);
-
-        implExpectsAnyRequestAndReturn(mockBackendResponse);
-
-        replayMocks();
-        final HttpResponse result = impl.execute(route, request, context);
-        verifyMocks();
-
-        Assert.assertSame(mockBackendResponse, result);
-        Assert.assertEquals(1, impl.getCacheMisses());
-        Assert.assertEquals(0, impl.getCacheHits());
-        Assert.assertEquals(0, impl.getCacheUpdates());
-    }
-
-    @Test
-    public void testUnsuitableUnvalidatableCacheEntryCausesBackendRequest() throws Exception {
-        mockImplMethods(CALL_BACKEND);
-        cacheInvalidatorWasCalled();
-        requestPolicyAllowsCaching(true);
-        requestIsFatallyNonCompliant(null);
-
-        getCacheEntryReturns(mockCacheEntry);
-        cacheEntrySuitable(false);
-        cacheEntryValidatable(false);
-        implExpectsAnyRequestAndReturn(mockBackendResponse);
-
-        replayMocks();
-        final HttpResponse result = impl.execute(route, request, context);
-        verifyMocks();
-
-        Assert.assertSame(mockBackendResponse, result);
-        Assert.assertEquals(0, impl.getCacheMisses());
-        Assert.assertEquals(1, impl.getCacheHits());
-        Assert.assertEquals(0, impl.getCacheUpdates());
-    }
-
-    @Test
-    public void testUnsuitableValidatableCacheEntryCausesRevalidation() throws Exception {
-        mockImplMethods(REVALIDATE_CACHE_ENTRY);
-        cacheInvalidatorWasCalled();
-        requestPolicyAllowsCaching(true);
-        requestIsFatallyNonCompliant(null);
-
-        getCacheEntryReturns(mockCacheEntry);
-        cacheEntrySuitable(false);
-        cacheEntryValidatable(true);
-        cacheEntryMustRevalidate(false);
-        cacheEntryProxyRevalidate(false);
-        mayReturnStaleWhileRevalidating(false);
-
-        expect(impl.revalidateCacheEntry(
-                isA(HttpRoute.class),
-                isA(HttpRequestWrapper.class),
-                isA(HttpClientContext.class),
-                (HttpExecutionAware) isNull(),
-                isA(HttpCacheEntry.class))).andReturn(mockBackendResponse);
-
-        replayMocks();
-        final HttpResponse result = impl.execute(route, request, context);
-        verifyMocks();
-
-        Assert.assertSame(mockBackendResponse, result);
-        Assert.assertEquals(0, impl.getCacheMisses());
-        Assert.assertEquals(1, impl.getCacheHits());
-        Assert.assertEquals(0, impl.getCacheUpdates());
-    }
-
-    @Test
-    public void testRevalidationCallsHandleBackEndResponseWhenNot200Or304() throws Exception {
-        mockImplMethods(GET_CURRENT_DATE, HANDLE_BACKEND_RESPONSE);
-
-        final HttpRequestWrapper validate = HttpRequestWrapper.wrap(
-                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
-        final CloseableHttpResponse originResponse = Proxies.enhanceResponse(
-                new BasicHttpResponse(HttpVersion.HTTP_1_1,  HttpStatus.SC_NOT_FOUND, "Not Found"));
-        final CloseableHttpResponse finalResponse = Proxies.enhanceResponse(
-                HttpTestUtils.make200Response());
-
-        conditionalRequestBuilderReturns(validate);
-        getCurrentDateReturns(requestDate);
-        backendExpectsRequestAndReturn(validate, originResponse);
-        getCurrentDateReturns(responseDate);
-        expect(impl.handleBackendResponse(
-                eq(route),
-                same(validate),
-                same(context),
-                (HttpExecutionAware) isNull(),
-                eq(requestDate),
-                eq(responseDate),
-                same(originResponse))).andReturn(finalResponse);
-
-        replayMocks();
-        final HttpResponse result =
-            impl.revalidateCacheEntry(route, request, context, null, entry);
-        verifyMocks();
-
-        Assert.assertSame(finalResponse, result);
-    }
-
-    @Test
-    public void testRevalidationUpdatesCacheEntryAndPutsItToCacheWhen304ReturningCachedResponse()
-            throws Exception {
-
-        mockImplMethods(GET_CURRENT_DATE);
-
-        final HttpRequestWrapper validate = HttpRequestWrapper.wrap(
-                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
-        final HttpResponse originResponse = Proxies.enhanceResponse(
-            new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not Modified"));
-        final HttpCacheEntry updatedEntry = HttpTestUtils.makeCacheEntry();
-
-        conditionalRequestBuilderReturns(validate);
-        getCurrentDateReturns(requestDate);
-        backendExpectsRequestAndReturn(validate, originResponse);
-        getCurrentDateReturns(responseDate);
-        expect(mockCache.updateCacheEntry(
-                eq(host),
-                same(request),
-                same(entry),
-                same(originResponse),
-                eq(requestDate),
-                eq(responseDate)))
-            .andReturn(updatedEntry);
-        expect(mockSuitabilityChecker.isConditional(request)).andReturn(false);
-        responseIsGeneratedFromCache();
-
-        replayMocks();
-        impl.revalidateCacheEntry(route, request, context, null, entry);
-        verifyMocks();
-    }
-
-    @Test
     public void testSuitableCacheEntryDoesNotCauseBackendRequest() throws Exception {
         cacheInvalidatorWasCalled();
         requestPolicyAllowsCaching(true);
@@ -488,34 +330,16 @@ public class TestCachingExec {
         entryHasStaleness(0L);
 
         replayMocks();
-        final HttpResponse result = impl.execute(route, request, context);
+        final HttpResponse result = impl.execute(route, request, context, null);
         verifyMocks();
 
         Assert.assertSame(mockCachedResponse, result);
     }
 
     @Test
-    public void testCallBackendMakesBackEndRequestAndHandlesResponse() throws Exception {
-        mockImplMethods(GET_CURRENT_DATE, HANDLE_BACKEND_RESPONSE);
-        final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
-        getCurrentDateReturns(requestDate);
-        backendExpectsRequestAndReturn(request, resp);
-        getCurrentDateReturns(responseDate);
-        handleBackendResponseReturnsResponse(request, resp);
-
-        replayMocks();
-
-        impl.callBackend(route, request, context, null);
-
-        verifyMocks();
-    }
-
-    @Test
     public void testNonCacheableResponseIsNotCachedAndIsReturnedAsIs() throws Exception {
         final CacheConfig config = CacheConfig.DEFAULT;
-        impl = new CachingExec(mockBackend,
-                new BasicHttpCache(new HeapResourceFactory(), mockStorage, config),
-                config);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(new HeapResourceFactory(), mockStorage, config), config);
 
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
         final HttpResponse resp1 = HttpTestUtils.make200Response();
@@ -527,7 +351,7 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp1);
 
         replayMocks();
-        final HttpResponse result = impl.execute(route, req1);
+        final HttpResponse result = impl.execute(route, req1, context, null);
         verifyMocks();
 
         assertTrue(HttpTestUtils.semanticallyTransparent(resp1, result));
@@ -545,7 +369,7 @@ public class TestCachingExec {
         entryHasStaleness(0L);
 
         replayMocks();
-        impl.execute(route, request, context);
+        impl.execute(route, request, context, null);
         verifyMocks();
     }
 
@@ -561,7 +385,7 @@ public class TestCachingExec {
         boolean gotException = false;
         replayMocks();
         try {
-            impl.execute(route, request, context);
+            impl.execute(route, request, context, null);
         } catch (final ClientProtocolException ex) {
             Assert.assertSame(expected, ex);
             gotException = true;
@@ -573,11 +397,11 @@ public class TestCachingExec {
     @Test
     public void testSetsModuleGeneratedResponseContextForCacheOptionsResponse()
         throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req = HttpRequestWrapper.wrap(new BasicHttpRequest("OPTIONS","*",HttpVersion.HTTP_1_1));
         req.setHeader("Max-Forwards","0");
 
-        impl.execute(route, req, context);
+        impl.execute(route, req, context, null);
         Assert.assertEquals(CacheResponseStatus.CACHE_MODULE_RESPONSE,
                 context.getCacheResponseStatus());
     }
@@ -585,12 +409,12 @@ public class TestCachingExec {
     @Test
     public void testSetsModuleGeneratedResponseContextForFatallyNoncompliantRequest()
         throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         req.setHeader("Range","bytes=0-50");
         req.setHeader("If-Range","W/\"weak-etag\"");
 
-        impl.execute(route, req, context);
+        impl.execute(route, req, context, null);
         Assert.assertEquals(CacheResponseStatus.CACHE_MODULE_RESPONSE,
                 context.getCacheResponseStatus());
     }
@@ -598,7 +422,7 @@ public class TestCachingExec {
     @Test
     public void testRecordsClientProtocolInViaHeaderIfRequestNotServableFromCache()
         throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req = HttpRequestWrapper.wrap(
                 new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_0));
         req.setHeader("Cache-Control","no-cache");
@@ -608,7 +432,7 @@ public class TestCachingExec {
         backendCaptureRequestAndReturn(cap, resp);
 
         replayMocks();
-        impl.execute(route, req, context);
+        impl.execute(route, req, context, null);
         verifyMocks();
 
         final HttpRequest captured = cap.getValue();
@@ -621,7 +445,7 @@ public class TestCachingExec {
     @Test
     public void testSetsCacheMissContextIfRequestNotServableFromCache()
         throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         req.setHeader("Cache-Control","no-cache");
         final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NO_CONTENT, "No Content");
@@ -629,7 +453,7 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp);
 
         replayMocks();
-        impl.execute(route, req, context);
+        impl.execute(route, req, context, null);
         verifyMocks();
         Assert.assertEquals(CacheResponseStatus.CACHE_MISS,
                 context.getCacheResponseStatus());
@@ -638,7 +462,7 @@ public class TestCachingExec {
     @Test
     public void testSetsViaHeaderOnResponseIfRequestNotServableFromCache()
             throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         req.setHeader("Cache-Control","no-cache");
         final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NO_CONTENT, "No Content");
@@ -646,7 +470,7 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp);
 
         replayMocks();
-        final HttpResponse result = impl.execute(route, req);
+        final HttpResponse result = impl.execute(route, req, context, null);
         verifyMocks();
         Assert.assertNotNull(result.getFirstHeader("Via"));
     }
@@ -654,7 +478,7 @@ public class TestCachingExec {
     @Test
     public void testSetsViaHeaderOnResponseForCacheMiss()
         throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
         resp1.setEntity(HttpTestUtils.makeBody(128));
@@ -666,7 +490,7 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp1);
 
         replayMocks();
-        final HttpResponse result = impl.execute(route, req1);
+        final HttpResponse result = impl.execute(route, req1, context, null);
         verifyMocks();
         Assert.assertNotNull(result.getFirstHeader("Via"));
     }
@@ -674,7 +498,7 @@ public class TestCachingExec {
     @Test
     public void testSetsCacheHitContextIfRequestServedFromCache()
         throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
@@ -687,8 +511,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp1);
 
         replayMocks();
-        impl.execute(route, req1);
-        impl.execute(route, req2, context);
+        impl.execute(route, req1, context, null);
+        impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertEquals(CacheResponseStatus.CACHE_HIT,
                 context.getCacheResponseStatus());
@@ -697,7 +521,7 @@ public class TestCachingExec {
     @Test
     public void testSetsViaHeaderOnResponseIfRequestServedFromCache()
         throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
@@ -710,8 +534,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp1);
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertNotNull(result.getFirstHeader("Via"));
     }
@@ -721,7 +545,7 @@ public class TestCachingExec {
             throws Exception {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         req2.addHeader("If-Modified-Since", DateUtils.formatDate(now));
@@ -737,8 +561,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp1);
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertEquals(HttpStatus.SC_NOT_MODIFIED, result.getStatusLine().getStatusCode());
 
@@ -749,7 +573,7 @@ public class TestCachingExec {
         final Date now = new Date();
         final Date oneHourAgo = new Date(now.getTime() - 3600 * 1000L);
         final Date inTenMinutes = new Date(now.getTime() + 600 * 1000L);
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         req1.addHeader("If-Modified-Since", DateUtils.formatDate(oneHourAgo));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
@@ -761,21 +585,21 @@ public class TestCachingExec {
         resp1.setHeader("Expires", DateUtils.formatDate(inTenMinutes));
 
         expect(mockBackend.execute(
-            same(route),
+            eq(route),
             isA(HttpRequestWrapper.class),
             isA(HttpClientContext.class),
             (HttpExecutionAware) isNull())).andReturn(Proxies.enhanceResponse(resp1)).once();
 
         expect(mockBackend.execute(
-            same(route),
+            eq(route),
             isA(HttpRequestWrapper.class),
             isA(HttpClientContext.class),
             (HttpExecutionAware) isNull())).andThrow(
                 new AssertionFailedError("Should have reused cached 304 response")).anyTimes();
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertEquals(HttpStatus.SC_NOT_MODIFIED, result.getStatusLine().getStatusCode());
         Assert.assertFalse(result.containsHeader("Last-Modified"));
@@ -785,7 +609,7 @@ public class TestCachingExec {
     public void testReturns200ForIfModifiedSinceDateIsLess() throws Exception {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
 
@@ -808,8 +632,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp2);
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertEquals(HttpStatus.SC_OK, result.getStatusLine().getStatusCode());
 
@@ -820,7 +644,7 @@ public class TestCachingExec {
             throws Exception {
         final Date now = new Date();
         final Date tenSecondsAfter = new Date(now.getTime() + 10 * 1000L);
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
 
@@ -840,8 +664,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp1).times(2);
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertEquals(HttpStatus.SC_OK, result.getStatusLine().getStatusCode());
 
@@ -850,7 +674,7 @@ public class TestCachingExec {
     @Test
     public void testReturns304ForIfNoneMatchHeaderIfRequestServedFromCache()
             throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         req2.addHeader("If-None-Match", "*");
@@ -865,8 +689,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp1);
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertEquals(HttpStatus.SC_NOT_MODIFIED, result.getStatusLine().getStatusCode());
 
@@ -874,7 +698,7 @@ public class TestCachingExec {
 
     @Test
     public void testReturns200ForIfNoneMatchHeaderFails() throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
 
@@ -894,8 +718,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp2);
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertEquals(200, result.getStatusLine().getStatusCode());
 
@@ -904,7 +728,7 @@ public class TestCachingExec {
     @Test
     public void testReturns304ForIfNoneMatchHeaderAndIfModifiedSinceIfRequestServedFromCache()
             throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
@@ -925,8 +749,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp1);
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertEquals(HttpStatus.SC_NOT_MODIFIED, result.getStatusLine().getStatusCode());
 
@@ -935,7 +759,7 @@ public class TestCachingExec {
     @Test
     public void testReturns200ForIfNoneMatchHeaderFailsIfModifiedSinceIgnored()
             throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
@@ -955,8 +779,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp1);
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertEquals(200, result.getStatusLine().getStatusCode());
 
@@ -968,7 +792,7 @@ public class TestCachingExec {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
 
@@ -990,8 +814,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp2);
 
         replayMocks();
-        impl.execute(route, req1);
-        impl.execute(route, req2, context);
+        impl.execute(route, req1, context, null);
+        impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertEquals(CacheResponseStatus.VALIDATED,
                 context.getCacheResponseStatus());
@@ -1003,7 +827,7 @@ public class TestCachingExec {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
 
@@ -1025,8 +849,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp2);
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2, context);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertNotNull(result.getFirstHeader("Via"));
     }
@@ -1038,7 +862,7 @@ public class TestCachingExec {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
 
@@ -1053,8 +877,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndThrows(new IOException());
 
         replayMocks();
-        impl.execute(route, req1);
-        impl.execute(route, req2, context);
+        impl.execute(route, req1, context, null);
+        impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertEquals(CacheResponseStatus.CACHE_MODULE_RESPONSE,
                 context.getCacheResponseStatus());
@@ -1066,7 +890,7 @@ public class TestCachingExec {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
 
@@ -1081,8 +905,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndThrows(new IOException());
 
         replayMocks();
-        impl.execute(route, req1);
-        impl.execute(route, req2, context);
+        impl.execute(route, req1, context, null);
+        impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertEquals(CacheResponseStatus.CACHE_HIT,
                 context.getCacheResponseStatus());
@@ -1094,7 +918,7 @@ public class TestCachingExec {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
 
@@ -1109,8 +933,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndThrows(new IOException());
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2, context);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
         Assert.assertNotNull(result.getFirstHeader("Via"));
     }
@@ -1122,7 +946,7 @@ public class TestCachingExec {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
 
@@ -1144,8 +968,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp1);
         backendExpectsAnyRequestAndReturn(resp2);
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
 
         Assert.assertEquals(HttpStatus.SC_NOT_MODIFIED, result.getStatusLine().getStatusCode());
@@ -1158,7 +982,7 @@ public class TestCachingExec {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
 
@@ -1183,8 +1007,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp2);
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
 
         Assert.assertEquals(HttpStatus.SC_OK, result.getStatusLine().getStatusCode());
@@ -1193,7 +1017,7 @@ public class TestCachingExec {
     @Test
     public void testReturns304ForIfModifiedSincePassesIfRequestServedFromOrigin()
             throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
 
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
@@ -1222,8 +1046,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp2);
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
 
         Assert.assertEquals(HttpStatus.SC_NOT_MODIFIED, result.getStatusLine().getStatusCode());
@@ -1232,7 +1056,7 @@ public class TestCachingExec {
     @Test
     public void testReturns200ForIfModifiedSinceFailsIfRequestServedFromOrigin()
             throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
@@ -1262,8 +1086,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp2);
 
         replayMocks();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
 
         Assert.assertEquals(HttpStatus.SC_OK, result.getStatusLine().getStatusCode());
@@ -1271,7 +1095,7 @@ public class TestCachingExec {
 
     @Test
     public void testVariantMissServerIfReturns304CacheReturns200() throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
 
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com"));
@@ -1320,11 +1144,11 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp3);
 
         replayMocks();
-        final HttpResponse result1 = impl.execute(route, req1);
+        final HttpResponse result1 = impl.execute(route, req1, context, null);
 
-        final HttpResponse result2 = impl.execute(route, req2);
+        final HttpResponse result2 = impl.execute(route, req2, context, null);
 
-        final HttpResponse result3 = impl.execute(route, req3);
+        final HttpResponse result3 = impl.execute(route, req3, context, null);
 
         verifyMocks();
         Assert.assertEquals(HttpStatus.SC_OK, result1.getStatusLine().getStatusCode());
@@ -1334,7 +1158,7 @@ public class TestCachingExec {
 
     @Test
     public void testVariantsMissServerReturns304CacheReturns304() throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
 
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com"));
@@ -1382,11 +1206,11 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp4);
 
         replayMocks();
-        final HttpResponse result1 = impl.execute(route, req1);
+        final HttpResponse result1 = impl.execute(route, req1, context, null);
 
-        final HttpResponse result2 = impl.execute(route, req2);
+        final HttpResponse result2 = impl.execute(route, req2, context, null);
 
-        final HttpResponse result4 = impl.execute(route, req4);
+        final HttpResponse result4 = impl.execute(route, req4, context, null);
         verifyMocks();
         Assert.assertEquals(HttpStatus.SC_OK, result1.getStatusLine().getStatusCode());
         Assert.assertEquals(HttpStatus.SC_OK, result2.getStatusLine().getStatusCode());
@@ -1397,8 +1221,7 @@ public class TestCachingExec {
     @Test
     public void testSocketTimeoutExceptionIsNotSilentlyCatched()
             throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(),
-                CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final Date now = new Date();
 
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
@@ -1428,7 +1251,7 @@ public class TestCachingExec {
 
         replayMocks();
         try {
-            final HttpResponse result1 = impl.execute(route, req1);
+            final HttpResponse result1 = impl.execute(route, req1, context, null);
             EntityUtils.toString(result1.getEntity());
             Assert.fail("We should have had a SocketTimeoutException");
         } catch (final SocketTimeoutException e) {
@@ -1446,42 +1269,42 @@ public class TestCachingExec {
     public void testTreatsCacheIOExceptionsAsCacheMiss()
         throws Exception {
 
-        impl = new CachingExec(mockBackend, mockCache, CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, mockCache, CacheConfig.DEFAULT);
         final CloseableHttpResponse resp = Proxies.enhanceResponse(HttpTestUtils.make200Response());
 
         mockCache.flushInvalidatedCacheEntriesFor(host, request);
         expectLastCall().andThrow(new IOException()).anyTimes();
         mockCache.flushInvalidatedCacheEntriesFor(isA(HttpHost.class), isA(HttpRequest.class), isA(HttpResponse.class));
         expectLastCall().anyTimes();
-        expect(mockCache.getCacheEntry(same(host),
+        expect(mockCache.getCacheEntry(eq(host),
                 isA(HttpRequest.class)))
             .andThrow(new IOException()).anyTimes();
-        expect(mockCache.getVariantCacheEntriesWithEtags(same(host),
+        expect(mockCache.getVariantCacheEntriesWithEtags(eq(host),
                 isA(HttpRequest.class)))
             .andThrow(new IOException()).anyTimes();
-        expect(mockCache.cacheAndReturnResponse(same(host),
+        expect(mockCache.cacheAndReturnResponse(eq(host),
                 isA(HttpRequest.class), isA(HttpResponse.class),
                 isA(Date.class), isA(Date.class)))
             .andReturn(resp).anyTimes();
         expect(mockBackend.execute(
-                same(route),
+                eq(route),
                 isA(HttpRequestWrapper.class),
                 isA(HttpClientContext.class),
                 (HttpExecutionAware) isNull())).andReturn(resp);
 
         replayMocks();
-        final HttpResponse result = impl.execute(route, request);
+        final HttpResponse result = impl.execute(route, request, context, null);
         verifyMocks();
         Assert.assertSame(resp, result);
     }
 
     @Test
     public void testIfOnlyIfCachedAndNoCacheEntryBackendNotCalled() throws Exception {
-        impl = new CachingExec(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
 
         request.addHeader("Cache-Control", "only-if-cached");
 
-        final HttpResponse resp = impl.execute(route, request);
+        final HttpResponse resp = impl.execute(route, request, context, null);
 
         Assert.assertEquals(HttpStatus.SC_GATEWAY_TIMEOUT, resp.getStatusLine().getStatusCode());
     }
@@ -1500,7 +1323,7 @@ public class TestCachingExec {
         cacheEntrySuitable(false);
 
         replayMocks();
-        final HttpResponse resp = impl.execute(route, request);
+        final HttpResponse resp = impl.execute(route, request, context, null);
         verifyMocks();
 
         Assert.assertEquals(HttpStatus.SC_GATEWAY_TIMEOUT, resp.getStatusLine().getStatusCode());
@@ -1520,7 +1343,7 @@ public class TestCachingExec {
         entryHasStaleness(0);
 
         replayMocks();
-        final HttpResponse resp = impl.execute(route, request);
+        final HttpResponse resp = impl.execute(route, request, context, null);
         verifyMocks();
 
         Assert.assertSame(mockCachedResponse, resp);
@@ -1532,10 +1355,10 @@ public class TestCachingExec {
         final HttpResponse response = HttpTestUtils.make200Response();
         response.setHeader("Cache-Control", "max-age=3600");
         backend.setResponse(response);
-        impl = new CachingExec(backend);
+        impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpClientContext ctx = HttpClientContext.create();
-        impl.execute(route, request);
-        impl.execute(route, request, ctx);
+        impl.execute(route, request, context, null);
+        impl.execute(route, request, ctx, null);
         assertNull(ctx.getConnection());
     }
 
@@ -1545,10 +1368,10 @@ public class TestCachingExec {
         final HttpResponse response = HttpTestUtils.make200Response();
         response.setHeader("Cache-Control", "max-age=3600");
         backend.setResponse(response);
-        impl = new CachingExec(backend);
+        impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpClientContext ctx = HttpClientContext.create();
-        impl.execute(route, request);
-        impl.execute(route, request, ctx);
+        impl.execute(route, request, context, null);
+        impl.execute(route, request, ctx, null);
         assertSame(host, ctx.getTargetHost());
     }
 
@@ -1558,11 +1381,11 @@ public class TestCachingExec {
         final HttpResponse response = HttpTestUtils.make200Response();
         response.setHeader("Cache-Control", "max-age=3600");
         backend.setResponse(response);
-        impl = new CachingExec(backend);
+        impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpClientContext ctx = HttpClientContext.create();
-        impl.execute(route, request);
-        impl.execute(route, request, ctx);
-        assertSame(route, ctx.getHttpRoute());
+        impl.execute(route, request, context, null);
+        impl.execute(route, request, ctx, null);
+        assertEquals(route, ctx.getHttpRoute());
     }
 
     @Test
@@ -1571,11 +1394,13 @@ public class TestCachingExec {
         final HttpResponse response = HttpTestUtils.make200Response();
         response.setHeader("Cache-Control", "max-age=3600");
         backend.setResponse(response);
-        impl = new CachingExec(backend);
+        impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpClientContext ctx = HttpClientContext.create();
-        impl.execute(route, request);
-        impl.execute(route, request, ctx);
-        assertSame(request, ctx.getRequest());
+        impl.execute(route, request, context, null);
+        impl.execute(route, request, ctx, null);
+        if (!HttpTestUtils.equivalent(request, ctx.getRequest())) {
+            assertSame(request, ctx.getRequest());
+        }
     }
 
     @Test
@@ -1584,11 +1409,13 @@ public class TestCachingExec {
         final HttpResponse response = HttpTestUtils.make200Response();
         response.setHeader("Cache-Control", "max-age=3600");
         backend.setResponse(response);
-        impl = new CachingExec(backend);
+        impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpClientContext ctx = HttpClientContext.create();
-        impl.execute(route, request);
-        final HttpResponse result = impl.execute(route, request, ctx);
-        assertSame(result, ctx.getResponse());
+        impl.execute(route, request, context, null);
+        final HttpResponse result = impl.execute(route, request, ctx, null);
+        if (!HttpTestUtils.equivalent(result, ctx.getResponse())) {
+            assertSame(result, ctx.getResponse());
+        }
     }
 
     @Test
@@ -1597,10 +1424,10 @@ public class TestCachingExec {
         final HttpResponse response = HttpTestUtils.make200Response();
         response.setHeader("Cache-Control", "max-age=3600");
         backend.setResponse(response);
-        impl = new CachingExec(backend);
+        impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpClientContext ctx = HttpClientContext.create();
-        impl.execute(route, request);
-        impl.execute(route, request, ctx);
+        impl.execute(route, request, context, null);
+        impl.execute(route, request, ctx, null);
         assertTrue(ctx.isRequestSent());
     }
 
@@ -1611,9 +1438,9 @@ public class TestCachingExec {
         response.setHeader("Cache-Control","max-age=300");
         final DummyBackend backend = new DummyBackend();
         backend.setResponse(response);
-        impl = new CachingExec(backend);
-        impl.execute(route, request);
-        impl.execute(route, request);
+        impl = createCachingExecChain(backend, new BasicHttpCache(), CacheConfig.DEFAULT);
+        impl.execute(route, request, context, null);
+        impl.execute(route, request, context, null);
         assertEquals(1, backend.getExecutions());
     }
 
@@ -1623,8 +1450,7 @@ public class TestCachingExec {
         final Date now = new Date();
         final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
 
-        impl = new CachingExec(mockBackend, new BasicHttpCache(),
-                CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet(
                 "http://foo.example.com/"));
         req1.addHeader("If-None-Match", "\"etag\"");
@@ -1638,7 +1464,7 @@ public class TestCachingExec {
 
         backendExpectsAnyRequestAndReturn(resp1);
         replayMocks();
-        final HttpResponse result = impl.execute(route, req1);
+        final HttpResponse result = impl.execute(route, req1, context, null);
         verifyMocks();
 
         assertEquals(HttpStatus.SC_NOT_MODIFIED, result.getStatusLine()
@@ -1652,7 +1478,7 @@ public class TestCachingExec {
 
         final Date now = new Date();
 
-        impl = new CachingExec(mockBackend, new BasicHttpCache(),CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
 
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         req1.addHeader("If-None-Match", "etag");
@@ -1673,8 +1499,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp1);
         backendExpectsAnyRequestAndReturn(resp2);
         replayMocks();
-        final HttpResponse result1 = impl.execute(route, req1);
-        final HttpResponse result2 = impl.execute(route, req2);
+        final HttpResponse result1 = impl.execute(route, req1, context, null);
+        final HttpResponse result2 = impl.execute(route, req2, context, null);
         verifyMocks();
 
         assertEquals(HttpStatus.SC_NOT_MODIFIED, result1.getStatusLine().getStatusCode());
@@ -1688,7 +1514,7 @@ public class TestCachingExec {
 
         final Date now = new Date();
 
-        impl = new CachingExec(mockBackend, new BasicHttpCache(),CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
 
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         req1.addHeader("If-None-Match", "etag");
@@ -1711,8 +1537,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp1);
         backendExpectsAnyRequestAndReturn(resp2);
         replayMocks();
-        final HttpResponse result1 = impl.execute(route, req1);
-        final HttpResponse result2 = impl.execute(route, req2);
+        final HttpResponse result1 = impl.execute(route, req1, context, null);
+        final HttpResponse result2 = impl.execute(route, req2, context, null);
         verifyMocks();
 
         assertEquals(HttpStatus.SC_NOT_MODIFIED, result1.getStatusLine().getStatusCode());
@@ -1727,7 +1553,7 @@ public class TestCachingExec {
         final Date now = new Date();
         final Date inOneMinute = new Date(System.currentTimeMillis()+60000);
 
-        impl = new CachingExec(mockBackend, new BasicHttpCache(),CacheConfig.DEFAULT);
+        impl = createCachingExecChain(mockBackend, new BasicHttpCache(), CacheConfig.DEFAULT);
 
         final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         req1.addHeader("If-None-Match", "etag");
@@ -1752,8 +1578,8 @@ public class TestCachingExec {
         backendExpectsAnyRequestAndReturn(resp1);
         backendExpectsAnyRequestAndReturn(resp2).anyTimes();
         replayMocks();
-        final HttpResponse result1 = impl.execute(route, req1);
-        final HttpResponse result2 = impl.execute(route, req2);
+        final HttpResponse result1 = impl.execute(route, req1, context, null);
+        final HttpResponse result2 = impl.execute(route, req2, context, null);
         verifyMocks();
 
         assertEquals(HttpStatus.SC_NOT_MODIFIED, result1.getStatusLine().getStatusCode());
@@ -1772,17 +1598,7 @@ public class TestCachingExec {
         return EasyMock.expect(resp).andReturn(Proxies.enhanceResponse(response));
     }
 
-    private IExpectationSetters<CloseableHttpResponse> implExpectsAnyRequestAndReturn(
-            final CloseableHttpResponse response) throws Exception {
-        final CloseableHttpResponse resp = impl.callBackend(
-                EasyMock.isA(HttpRoute.class),
-                EasyMock.isA(HttpRequestWrapper.class),
-                EasyMock.isA(HttpClientContext.class),
-                EasyMock.<HttpExecutionAware>isNull());
-        return EasyMock.expect(resp).andReturn(response);
-    }
-
-    private IExpectationSetters<CloseableHttpResponse> backendExpectsRequestAndReturn(
+    protected IExpectationSetters<CloseableHttpResponse> backendExpectsRequestAndReturn(
             final HttpRequestWrapper request, final HttpResponse response) throws Exception {
         final CloseableHttpResponse resp = mockBackend.execute(
                 EasyMock.isA(HttpRoute.class),
@@ -1792,7 +1608,7 @@ public class TestCachingExec {
         return EasyMock.expect(resp).andReturn(Proxies.enhanceResponse(response));
     }
 
-    private IExpectationSetters<CloseableHttpResponse> backendExpectsRequestAndReturn(
+    protected IExpectationSetters<CloseableHttpResponse> backendExpectsRequestAndReturn(
             final HttpRequestWrapper request, final CloseableHttpResponse response) throws Exception {
         final CloseableHttpResponse resp = mockBackend.execute(
                 EasyMock.isA(HttpRoute.class),
@@ -1802,7 +1618,7 @@ public class TestCachingExec {
         return EasyMock.expect(resp).andReturn(response);
     }
 
-    private IExpectationSetters<CloseableHttpResponse> backendExpectsAnyRequestAndThrows(
+    protected IExpectationSetters<CloseableHttpResponse> backendExpectsAnyRequestAndThrows(
             final Throwable throwable) throws Exception {
         final CloseableHttpResponse resp = mockBackend.execute(
                 EasyMock.isA(HttpRoute.class),
@@ -1812,7 +1628,7 @@ public class TestCachingExec {
         return EasyMock.expect(resp).andThrow(throwable);
     }
 
-    private IExpectationSetters<CloseableHttpResponse> backendCaptureRequestAndReturn(
+    protected IExpectationSetters<CloseableHttpResponse> backendCaptureRequestAndReturn(
             final Capture<HttpRequestWrapper> cap, final HttpResponse response) throws Exception {
         final CloseableHttpResponse resp = mockBackend.execute(
                 EasyMock.isA(HttpRoute.class),
@@ -1822,12 +1638,8 @@ public class TestCachingExec {
         return EasyMock.expect(resp).andReturn(Proxies.enhanceResponse(response));
     }
 
-    private void getCacheEntryReturns(final HttpCacheEntry result) throws IOException {
-        expect(mockCache.getCacheEntry(host, request)).andReturn(result);
-    }
-
-    private void getVariantCacheEntriesReturns(final Map<String,Variant> result) throws IOException {
-        expect(mockCache.getVariantCacheEntriesWithEtags(host, request)).andReturn(result);
+    protected void getCacheEntryReturns(final HttpCacheEntry result) throws IOException {
+        expect(mockCache.getCacheEntry(eq(host), eqRequest(request))).andReturn(result);
     }
 
     private void cacheInvalidatorWasCalled()  throws IOException {
@@ -1836,42 +1648,38 @@ public class TestCachingExec {
                 (HttpRequest)anyObject());
     }
 
-    private void cacheEntryValidatable(final boolean b) {
+    protected void cacheEntryValidatable(final boolean b) {
         expect(mockValidityPolicy.isRevalidatable(
                 (HttpCacheEntry)anyObject())).andReturn(b);
     }
 
-    private void cacheEntryMustRevalidate(final boolean b) {
+    protected void cacheEntryMustRevalidate(final boolean b) {
         expect(mockValidityPolicy.mustRevalidate(mockCacheEntry))
             .andReturn(b);
     }
 
-    private void cacheEntryProxyRevalidate(final boolean b) {
+    protected void cacheEntryProxyRevalidate(final boolean b) {
         expect(mockValidityPolicy.proxyRevalidate(mockCacheEntry))
             .andReturn(b);
     }
 
-    private void mayReturnStaleWhileRevalidating(final boolean b) {
+    protected void mayReturnStaleWhileRevalidating(final boolean b) {
         expect(mockValidityPolicy.mayReturnStaleWhileRevalidating(
                 (HttpCacheEntry)anyObject(), (Date)anyObject())).andReturn(b);
     }
 
-    private void conditionalRequestBuilderReturns(final HttpRequestWrapper validate)
+    protected void conditionalRequestBuilderReturns(final HttpRequestWrapper validate)
             throws Exception {
         expect(mockConditionalRequestBuilder.buildConditionalRequest(
                 request, entry)).andReturn(validate);
-}
-
-    private void getCurrentDateReturns(final Date date) {
-        expect(impl.getCurrentDate()).andReturn(date);
     }
 
-    private void requestPolicyAllowsCaching(final boolean allow) {
+    protected void requestPolicyAllowsCaching(final boolean allow) {
         expect(mockRequestPolicy.isServableFromCache(
                 (HttpRequest)anyObject())).andReturn(allow);
     }
 
-    private void cacheEntrySuitable(final boolean suitable) {
+    protected void cacheEntrySuitable(final boolean suitable) {
         expect(
                 mockSuitabilityChecker.canCachedResponseBeUsed(
                         (HttpHost)anyObject(),
@@ -1887,40 +1695,9 @@ public class TestCachingExec {
                 )).andReturn(staleness);
     }
 
-    private void responseIsGeneratedFromCache() {
+    protected void responseIsGeneratedFromCache() {
         expect(mockResponseGenerator.generateResponse(
                 (HttpCacheEntry)anyObject())).andReturn(mockCachedResponse);
     }
 
-    private void handleBackendResponseReturnsResponse(final HttpRequestWrapper request, final HttpResponse response)
-            throws IOException {
-        expect(
-                impl.handleBackendResponse(
-                        isA(HttpRoute.class),
-                        same(request),
-                        isA(HttpClientContext.class),
-                        (HttpExecutionAware) isNull(),
-                        isA(Date.class),
-                        isA(Date.class),
-                        isA(CloseableHttpResponse.class))).andReturn(
-                                Proxies.enhanceResponse(response));
-    }
-
-    private void mockImplMethods(final String... methods) {
-        mockedImpl = true;
-        impl = createMockBuilder(CachingExec.class).withConstructor(
-                mockBackend,
-                mockCache,
-                mockValidityPolicy,
-                mockResponsePolicy,
-                mockResponseGenerator,
-                mockRequestPolicy,
-                mockSuitabilityChecker,
-                mockConditionalRequestBuilder,
-                mockResponseProtocolCompliance,
-                mockRequestProtocolCompliance,
-                config,
-                asyncValidator).addMockedMethods(methods).createNiceMock();
-    }
-
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheJiraNumber1147.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheJiraNumber1147.java?rev=1494755&r1=1494754&r2=1494755&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheJiraNumber1147.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheJiraNumber1147.java Wed Jun 19 19:50:02 2013
@@ -112,7 +112,7 @@ public class TestHttpCacheJiraNumber1147
         EasyMock.replay(backend);
 
         final BasicHttpCache cache = new BasicHttpCache(resourceFactory, httpCacheStorage, cacheConfig);
-        final CachingExec t = new CachingExec(backend, cache, cacheConfig);
+        final ClientExecChain t = createCachingExecChain(backend, cache, cacheConfig);
 
         final HttpResponse response1 = t.execute(route, get, context, null);
         Assert.assertEquals(200, response1.getStatusLine().getStatusCode());
@@ -137,4 +137,9 @@ public class TestHttpCacheJiraNumber1147
         EasyMock.verify(backend);
     }
 
+    protected ClientExecChain createCachingExecChain(final ClientExecChain backend,
+            final BasicHttpCache cache, final CacheConfig config) {
+        return new CachingExec(backend, cache, config);
+    }
+
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolAllowedBehavior.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolAllowedBehavior.java?rev=1494755&r1=1494754&r2=1494755&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolAllowedBehavior.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolAllowedBehavior.java Wed Jun 19 19:50:02 2013
@@ -65,8 +65,8 @@ public class TestProtocolAllowedBehavior
 
         replayMocks();
         behaveAsNonSharedCache();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
 
         Assert.assertEquals(HttpStatus.SC_OK, result.getStatusLine().getStatusCode());
@@ -86,8 +86,8 @@ public class TestProtocolAllowedBehavior
 
         replayMocks();
         behaveAsNonSharedCache();
-        impl.execute(route, req1);
-        final HttpResponse result = impl.execute(route, req2);
+        impl.execute(route, req1, context, null);
+        final HttpResponse result = impl.execute(route, req2, context, null);
         verifyMocks();
 
         Assert.assertEquals(HttpStatus.SC_OK, result.getStatusLine().getStatusCode());

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java?rev=1494755&r1=1494754&r2=1494755&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java Wed Jun 19 19:50:02 2013
@@ -37,6 +37,7 @@ import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.cache.HttpCacheContext;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpExecutionAware;
 import org.apache.http.client.methods.HttpRequestWrapper;
@@ -84,9 +85,10 @@ public class TestProtocolDeviations {
     private ClientExecChain mockBackend;
     private HttpCache mockCache;
     private HttpRequest request;
+    private HttpCacheContext context;
     private CloseableHttpResponse originResponse;
 
-    private CachingExec impl;
+    private ClientExecChain impl;
 
     @Before
     public void setUp() {
@@ -98,6 +100,8 @@ public class TestProtocolDeviations {
 
         request = new BasicHttpRequest("GET", "/foo", HTTP_1_1);
 
+        context = HttpCacheContext.create();
+
         originResponse = Proxies.enhanceResponse(make200Response());
 
         final CacheConfig config = CacheConfig.custom()
@@ -110,7 +114,12 @@ public class TestProtocolDeviations {
         mockEntity = EasyMock.createNiceMock(HttpEntity.class);
         mockCache = EasyMock.createNiceMock(HttpCache.class);
 
-        impl = new CachingExec(mockBackend, cache, config);
+        impl = createCachingExecChain(mockBackend, cache, config);
+    }
+
+    protected ClientExecChain createCachingExecChain(
+            final ClientExecChain backend, final HttpCache cache, final CacheConfig config) {
+        return new CachingExec(backend, cache, config);
     }
 
     private HttpResponse make200Response() {
@@ -169,7 +178,7 @@ public class TestProtocolDeviations {
 
         replayMocks();
 
-        final HttpResponse response = impl.execute(route, HttpRequestWrapper.wrap(post));
+        final HttpResponse response = impl.execute(route, HttpRequestWrapper.wrap(post), context, null);
 
         verifyMocks();
 
@@ -227,7 +236,7 @@ public class TestProtocolDeviations {
         replayMocks();
         EasyMock.replay(mockBody);
 
-        final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(post));
+        final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(post), context, null);
 
         verifyMocks();
         EasyMock.verify(mockBody);
@@ -266,7 +275,7 @@ public class TestProtocolDeviations {
                         EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
         replayMocks();
 
-        impl.execute(route, HttpRequestWrapper.wrap(options));
+        impl.execute(route, HttpRequestWrapper.wrap(options), context, null);
 
         verifyMocks();
 
@@ -308,7 +317,7 @@ public class TestProtocolDeviations {
 
         replayMocks();
         try {
-            final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request));
+            final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request), context, null);
             Assert.assertTrue(HttpStatus.SC_PARTIAL_CONTENT != result.getStatusLine()
                     .getStatusCode());
         } catch (final ClientProtocolException acceptableBehavior) {
@@ -336,7 +345,7 @@ public class TestProtocolDeviations {
                         EasyMock.isA(HttpClientContext.class),
                         EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
         replayMocks();
-        final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request));
+        final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request), context, null);
         verifyMocks();
         Assert.assertSame(originResponse, result);
     }
@@ -359,7 +368,7 @@ public class TestProtocolDeviations {
                         EasyMock.isA(HttpClientContext.class),
                         EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
         replayMocks();
-        final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request));
+        final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request), context, null);
         verifyMocks();
         Assert.assertSame(originResponse, result);
     }
@@ -383,7 +392,7 @@ public class TestProtocolDeviations {
                         EasyMock.isA(HttpClientContext.class),
                         EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);
         replayMocks();
-        final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request));
+        final HttpResponse result = impl.execute(route, HttpRequestWrapper.wrap(request), context, null);
         verifyMocks();
         Assert.assertSame(originResponse, result);
     }



Mime
View raw message