cacheConfig.setMaxObjectSizeBytes(262144); //256kb
ResourceFactory resourceFactory = new FileResourceFactory(cacheDir);
HttpCacheStorage httpCacheStorage = new ManagedHttpCacheStorage(cacheConfig);
HttpClient client = EasyMock.createMock(HttpClient.class);
HttpGet get = new HttpGet("http://somehost/");
HttpContext context = new BasicHttpContext();
HttpHost target = new HttpHost("somehost");
Date now = new Date();
Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.setEntity(HttpTestUtils.makeBody(128));
response.setHeader("Content-Length", "128");
response.setHeader("ETag", "\"etag\"");
response.setHeader("Cache-Control", "public, max-age=3600");
response.setHeader("Last-Modified", DateUtils.formatDate(tenSecondsAgo));
EasyMock.expect(client.execute(
EasyMock.eq(target),
EasyMock.isA(HttpRequest.class),
EasyMock.same(context))).andReturn(response);
EasyMock.replay(client);
CachingHttpClient t = new CachingHttpClient(client, resourceFactory, httpCacheStorage, cacheConfig);
HttpResponse response1 = t.execute(get, context);
Assert.assertEquals(200, response1.getStatusLine().getStatusCode());
EntityUtils.consume(response1.getEntity());
EasyMock.verify(client);
removeCache();
EasyMock.reset(client);
EasyMock.expect(client.execute(
EasyMock.eq(target),
EasyMock.isA(HttpRequest.class),
EasyMock.same(context))).andReturn(response);
EasyMock.replay(client);