mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-02-18 16:07:11 +00:00
HTTPCLIENT-1244: relaxed EasyMock based unit tests in the Caching module
Contributed by Joe Campbell <joseph.r.campbell at gmail.com> git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1395613 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
639cc93c56
commit
43d4e8f469
@ -59,7 +59,7 @@ public void setUp() {
|
|||||||
nineSecondsAgo = new Date(now.getTime() - 9 * 1000L);
|
nineSecondsAgo = new Date(now.getTime() - 9 * 1000L);
|
||||||
statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1,
|
statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1,
|
||||||
HttpStatus.SC_OK, "OK");
|
HttpStatus.SC_OK, "OK");
|
||||||
mockResource = createMock(Resource.class);
|
mockResource = createNiceMock(Resource.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpCacheEntry makeEntry(Header[] headers) {
|
private HttpCacheEntry makeEntry(Header[] headers) {
|
||||||
|
@ -73,8 +73,8 @@ public void setUp() {
|
|||||||
params.setMaxCacheEntries(MAX_ENTRIES);
|
params.setMaxCacheEntries(MAX_ENTRIES);
|
||||||
params.setMaxObjectSize(MAX_BYTES);
|
params.setMaxObjectSize(MAX_BYTES);
|
||||||
cache = new BasicHttpCache(params);
|
cache = new BasicHttpCache(params);
|
||||||
mockBackend = EasyMock.createMock(HttpClient.class);
|
mockBackend = EasyMock.createNiceMock(HttpClient.class);
|
||||||
mockCache = EasyMock.createMock(HttpCache.class);
|
mockCache = EasyMock.createNiceMock(HttpCache.class);
|
||||||
impl = new CachingHttpClient(mockBackend, cache, params);
|
impl = new CachingHttpClient(mockBackend, cache, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,8 +95,8 @@ protected IExpectationSetters<HttpResponse> backendExpectsAnyRequest() throws Ex
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void emptyMockCacheExpectsNoPuts() throws Exception {
|
protected void emptyMockCacheExpectsNoPuts() throws Exception {
|
||||||
mockBackend = EasyMock.createMock(HttpClient.class);
|
mockBackend = EasyMock.createNiceMock(HttpClient.class);
|
||||||
mockCache = EasyMock.createMock(HttpCache.class);
|
mockCache = EasyMock.createNiceMock(HttpCache.class);
|
||||||
|
|
||||||
impl = new CachingHttpClient(mockBackend, mockCache, params);
|
impl = new CachingHttpClient(mockBackend, mockCache, params);
|
||||||
|
|
||||||
|
@ -79,9 +79,9 @@ public void setUp() {
|
|||||||
params.setMaxCacheEntries(MAX_ENTRIES);
|
params.setMaxCacheEntries(MAX_ENTRIES);
|
||||||
|
|
||||||
HttpCache cache = new BasicHttpCache(params);
|
HttpCache cache = new BasicHttpCache(params);
|
||||||
mockBackend = EasyMock.createMock(HttpClient.class);
|
mockBackend = EasyMock.createNiceMock(HttpClient.class);
|
||||||
mockEntity = EasyMock.createMock(HttpEntity.class);
|
mockEntity = EasyMock.createNiceMock(HttpEntity.class);
|
||||||
mockCache = EasyMock.createMock(HttpCache.class);
|
mockCache = EasyMock.createNiceMock(HttpCache.class);
|
||||||
impl = new CachingHttpClient(mockBackend, cache, params);
|
impl = new CachingHttpClient(mockBackend, cache, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,12 +49,12 @@ public class TestAsynchronousValidationRequest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mockParent = EasyMock.createMock(AsynchronousValidator.class);
|
mockParent = EasyMock.createNiceMock(AsynchronousValidator.class);
|
||||||
mockClient = EasyMock.createMock(CachingHttpClient.class);
|
mockClient = EasyMock.createNiceMock(CachingHttpClient.class);
|
||||||
target = new HttpHost("foo.example.com");
|
target = new HttpHost("foo.example.com");
|
||||||
request = new HttpGet("/");
|
request = new HttpGet("/");
|
||||||
mockContext = EasyMock.createMock(HttpContext.class);
|
mockContext = EasyMock.createNiceMock(HttpContext.class);
|
||||||
mockCacheEntry = EasyMock.createMock(HttpCacheEntry.class);
|
mockCacheEntry = EasyMock.createNiceMock(HttpCacheEntry.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -61,13 +61,13 @@ public class TestAsynchronousValidator {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mockClient = EasyMock.createMock(CachingHttpClient.class);
|
mockClient = EasyMock.createNiceMock(CachingHttpClient.class);
|
||||||
target = new HttpHost("foo.example.com");
|
target = new HttpHost("foo.example.com");
|
||||||
request = new HttpGet("/");
|
request = new HttpGet("/");
|
||||||
mockContext = EasyMock.createMock(HttpContext.class);
|
mockContext = EasyMock.createNiceMock(HttpContext.class);
|
||||||
mockCacheEntry = EasyMock.createMock(HttpCacheEntry.class);
|
mockCacheEntry = EasyMock.createNiceMock(HttpCacheEntry.class);
|
||||||
|
|
||||||
mockExecutor = EasyMock.createMock(ExecutorService.class);
|
mockExecutor = EasyMock.createNiceMock(ExecutorService.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,9 +73,9 @@ public void setUp() {
|
|||||||
tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||||
|
|
||||||
host = new HttpHost("foo.example.com");
|
host = new HttpHost("foo.example.com");
|
||||||
mockStorage = createMock(HttpCacheStorage.class);
|
mockStorage = createNiceMock(HttpCacheStorage.class);
|
||||||
cacheKeyGenerator = new CacheKeyGenerator();
|
cacheKeyGenerator = new CacheKeyGenerator();
|
||||||
mockEntry = createMock(HttpCacheEntry.class);
|
mockEntry = createNiceMock(HttpCacheEntry.class);
|
||||||
request = HttpTestUtils.makeDefaultRequest();
|
request = HttpTestUtils.makeDefaultRequest();
|
||||||
response = HttpTestUtils.make200Response();
|
response = HttpTestUtils.make200Response();
|
||||||
|
|
||||||
|
@ -53,8 +53,8 @@ public class TestCacheKeyGenerator {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
host = new HttpHost("foo.example.com");
|
host = new HttpHost("foo.example.com");
|
||||||
mockEntry = EasyMock.createMock(HttpCacheEntry.class);
|
mockEntry = EasyMock.createNiceMock(HttpCacheEntry.class);
|
||||||
mockRequest = EasyMock.createMock(HttpRequest.class);
|
mockRequest = EasyMock.createNiceMock(HttpRequest.class);
|
||||||
extractor = new CacheKeyGenerator();
|
extractor = new CacheKeyGenerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ public void setUp() {
|
|||||||
new BasicHeader("Content-Length", "150") };
|
new BasicHeader("Content-Length", "150") };
|
||||||
|
|
||||||
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, sixSecondsAgo, hdrs);
|
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, sixSecondsAgo, hdrs);
|
||||||
mockValidityPolicy = EasyMock.createMock(CacheValidityPolicy.class);
|
mockValidityPolicy = EasyMock.createNiceMock(CacheValidityPolicy.class);
|
||||||
impl = new CachedHttpResponseGenerator(mockValidityPolicy);
|
impl = new CachedHttpResponseGenerator(mockValidityPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public void setUp() {
|
|||||||
|
|
||||||
host = new HttpHost("foo.example.com");
|
host = new HttpHost("foo.example.com");
|
||||||
request = new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1);
|
request = new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1);
|
||||||
mockValidityPolicy = EasyMock.createMock(CacheValidityPolicy.class);
|
mockValidityPolicy = EasyMock.createNiceMock(CacheValidityPolicy.class);
|
||||||
entry = HttpTestUtils.makeCacheEntry();
|
entry = HttpTestUtils.makeCacheEntry();
|
||||||
|
|
||||||
impl = new CachedResponseSuitabilityChecker(new CacheConfig());
|
impl = new CachedResponseSuitabilityChecker(new CacheConfig());
|
||||||
|
@ -115,25 +115,25 @@ public class TestCachingHttpClient {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mockRequestPolicy = createMock(CacheableRequestPolicy.class);
|
mockRequestPolicy = createNiceMock(CacheableRequestPolicy.class);
|
||||||
mockValidityPolicy = createMock(CacheValidityPolicy.class);
|
mockValidityPolicy = createNiceMock(CacheValidityPolicy.class);
|
||||||
mockBackend = createMock(HttpClient.class);
|
mockBackend = createNiceMock(HttpClient.class);
|
||||||
mockCache = createMock(HttpCache.class);
|
mockCache = createNiceMock(HttpCache.class);
|
||||||
mockSuitabilityChecker = createMock(CachedResponseSuitabilityChecker.class);
|
mockSuitabilityChecker = createNiceMock(CachedResponseSuitabilityChecker.class);
|
||||||
mockResponsePolicy = createMock(ResponseCachingPolicy.class);
|
mockResponsePolicy = createNiceMock(ResponseCachingPolicy.class);
|
||||||
mockConnectionManager = createMock(ClientConnectionManager.class);
|
mockConnectionManager = createNiceMock(ClientConnectionManager.class);
|
||||||
mockHandler = createMock(ResponseHandler.class);
|
mockHandler = createNiceMock(ResponseHandler.class);
|
||||||
mockBackendResponse = createMock(HttpResponse.class);
|
mockBackendResponse = createNiceMock(HttpResponse.class);
|
||||||
mockUriRequest = createMock(HttpUriRequest.class);
|
mockUriRequest = createNiceMock(HttpUriRequest.class);
|
||||||
mockCacheEntry = createMock(HttpCacheEntry.class);
|
mockCacheEntry = createNiceMock(HttpCacheEntry.class);
|
||||||
mockResponseGenerator = createMock(CachedHttpResponseGenerator.class);
|
mockResponseGenerator = createNiceMock(CachedHttpResponseGenerator.class);
|
||||||
mockCachedResponse = createMock(HttpResponse.class);
|
mockCachedResponse = createNiceMock(HttpResponse.class);
|
||||||
mockConditionalRequestBuilder = createMock(ConditionalRequestBuilder.class);
|
mockConditionalRequestBuilder = createNiceMock(ConditionalRequestBuilder.class);
|
||||||
mockConditionalRequest = createMock(HttpRequest.class);
|
mockConditionalRequest = createNiceMock(HttpRequest.class);
|
||||||
mockStatusLine = createMock(StatusLine.class);
|
mockStatusLine = createNiceMock(StatusLine.class);
|
||||||
mockResponseProtocolCompliance = createMock(ResponseProtocolCompliance.class);
|
mockResponseProtocolCompliance = createNiceMock(ResponseProtocolCompliance.class);
|
||||||
mockRequestProtocolCompliance = createMock(RequestProtocolCompliance.class);
|
mockRequestProtocolCompliance = createNiceMock(RequestProtocolCompliance.class);
|
||||||
mockStorage = createMock(HttpCacheStorage.class);
|
mockStorage = createNiceMock(HttpCacheStorage.class);
|
||||||
|
|
||||||
requestDate = new Date(System.currentTimeMillis() - 1000);
|
requestDate = new Date(System.currentTimeMillis() - 1000);
|
||||||
responseDate = new Date();
|
responseDate = new Date();
|
||||||
@ -2159,7 +2159,7 @@ private void mockImplMethods(String... methods) {
|
|||||||
mockSuitabilityChecker,
|
mockSuitabilityChecker,
|
||||||
mockConditionalRequestBuilder,
|
mockConditionalRequestBuilder,
|
||||||
mockResponseProtocolCompliance,
|
mockResponseProtocolCompliance,
|
||||||
mockRequestProtocolCompliance).addMockedMethods(methods).createMock();
|
mockRequestProtocolCompliance).addMockedMethods(methods).createNiceMock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public class TestCombinedEntity {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCombinedEntityBasics() throws Exception {
|
public void testCombinedEntityBasics() throws Exception {
|
||||||
Resource resource = EasyMock.createMock(Resource.class);
|
Resource resource = EasyMock.createNiceMock(Resource.class);
|
||||||
EasyMock.expect(resource.getInputStream()).andReturn(
|
EasyMock.expect(resource.getInputStream()).andReturn(
|
||||||
new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 }));
|
new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 }));
|
||||||
resource.dispose();
|
resource.dispose();
|
||||||
|
@ -91,7 +91,7 @@ public void testIssue1147() throws Exception {
|
|||||||
ResourceFactory resourceFactory = new FileResourceFactory(cacheDir);
|
ResourceFactory resourceFactory = new FileResourceFactory(cacheDir);
|
||||||
HttpCacheStorage httpCacheStorage = new ManagedHttpCacheStorage(cacheConfig);
|
HttpCacheStorage httpCacheStorage = new ManagedHttpCacheStorage(cacheConfig);
|
||||||
|
|
||||||
HttpClient client = EasyMock.createMock(HttpClient.class);
|
HttpClient client = EasyMock.createNiceMock(HttpClient.class);
|
||||||
HttpGet get = new HttpGet("http://somehost/");
|
HttpGet get = new HttpGet("http://somehost/");
|
||||||
HttpContext context = new BasicHttpContext();
|
HttpContext context = new BasicHttpContext();
|
||||||
HttpHost target = new HttpHost("somehost");
|
HttpHost target = new HttpHost("somehost");
|
||||||
|
@ -98,9 +98,9 @@ public void setUp() {
|
|||||||
params.setMaxCacheEntries(MAX_ENTRIES);
|
params.setMaxCacheEntries(MAX_ENTRIES);
|
||||||
|
|
||||||
HttpCache cache = new BasicHttpCache(params);
|
HttpCache cache = new BasicHttpCache(params);
|
||||||
mockBackend = EasyMock.createMock(HttpClient.class);
|
mockBackend = EasyMock.createNiceMock(HttpClient.class);
|
||||||
mockEntity = EasyMock.createMock(HttpEntity.class);
|
mockEntity = EasyMock.createNiceMock(HttpEntity.class);
|
||||||
mockCache = EasyMock.createMock(HttpCache.class);
|
mockCache = EasyMock.createNiceMock(HttpCache.class);
|
||||||
|
|
||||||
impl = new CachingHttpClient(mockBackend, cache, params);
|
impl = new CachingHttpClient(mockBackend, cache, params);
|
||||||
}
|
}
|
||||||
@ -203,7 +203,7 @@ public void testHTTP1_1RequestsWithUnknownBodyLengthAreRejectedOrHaveContentLeng
|
|||||||
(new Random()).nextBytes(bytes);
|
(new Random()).nextBytes(bytes);
|
||||||
|
|
||||||
HttpEntity mockBody = EasyMock.createMockBuilder(ByteArrayEntity.class).withConstructor(
|
HttpEntity mockBody = EasyMock.createMockBuilder(ByteArrayEntity.class).withConstructor(
|
||||||
new Object[] { bytes }).addMockedMethods("getContentLength").createMock();
|
new Object[] { bytes }).addMockedMethods("getContentLength").createNiceMock();
|
||||||
org.easymock.EasyMock.expect(mockBody.getContentLength()).andReturn(-1L).anyTimes();
|
org.easymock.EasyMock.expect(mockBody.getContentLength()).andReturn(-1L).anyTimes();
|
||||||
post.setEntity(mockBody);
|
post.setEntity(mockBody);
|
||||||
|
|
||||||
|
@ -550,7 +550,7 @@ public void testUnknownHeadersOnResponsesAreForwarded() throws Exception {
|
|||||||
public void testRequestsExpecting100ContinueBehaviorShouldSetExpectHeader() throws Exception {
|
public void testRequestsExpecting100ContinueBehaviorShouldSetExpectHeader() throws Exception {
|
||||||
BasicHttpEntityEnclosingRequest post = EasyMock.createMockBuilder(
|
BasicHttpEntityEnclosingRequest post = EasyMock.createMockBuilder(
|
||||||
BasicHttpEntityEnclosingRequest.class).withConstructor("POST", "/", HttpVersion.HTTP_1_1)
|
BasicHttpEntityEnclosingRequest.class).withConstructor("POST", "/", HttpVersion.HTTP_1_1)
|
||||||
.addMockedMethods("expectContinue").createMock();
|
.addMockedMethods("expectContinue").createNiceMock();
|
||||||
post.setEntity(new BasicHttpEntity());
|
post.setEntity(new BasicHttpEntity());
|
||||||
post.setHeader("Content-Length", "128");
|
post.setHeader("Content-Length", "128");
|
||||||
|
|
||||||
@ -595,7 +595,7 @@ public void testRequestsNotExpecting100ContinueBehaviorShouldNotSetExpectContinu
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
BasicHttpEntityEnclosingRequest post = EasyMock.createMockBuilder(
|
BasicHttpEntityEnclosingRequest post = EasyMock.createMockBuilder(
|
||||||
BasicHttpEntityEnclosingRequest.class).withConstructor("POST", "/", HttpVersion.HTTP_1_1)
|
BasicHttpEntityEnclosingRequest.class).withConstructor("POST", "/", HttpVersion.HTTP_1_1)
|
||||||
.addMockedMethods("expectContinue").createMock();
|
.addMockedMethods("expectContinue").createNiceMock();
|
||||||
post.setEntity(new BasicHttpEntity());
|
post.setEntity(new BasicHttpEntity());
|
||||||
post.setHeader("Content-Length", "128");
|
post.setHeader("Content-Length", "128");
|
||||||
|
|
||||||
|
@ -51,10 +51,10 @@ public class TestEhcacheHttpCacheStorage extends TestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mockCache = EasyMock.createMock(Ehcache.class);
|
mockCache = EasyMock.createNiceMock(Ehcache.class);
|
||||||
CacheConfig config = new CacheConfig();
|
CacheConfig config = new CacheConfig();
|
||||||
config.setMaxUpdateRetries(1);
|
config.setMaxUpdateRetries(1);
|
||||||
mockSerializer = EasyMock.createMock(HttpCacheEntrySerializer.class);
|
mockSerializer = EasyMock.createNiceMock(HttpCacheEntrySerializer.class);
|
||||||
impl = new EhcacheHttpCacheStorage(mockCache, config, mockSerializer);
|
impl = new EhcacheHttpCacheStorage(mockCache, config, mockSerializer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public void setUp() {
|
|||||||
}
|
}
|
||||||
CACHE_MANAGER.addCache(TEST_EHCACHE_NAME);
|
CACHE_MANAGER.addCache(TEST_EHCACHE_NAME);
|
||||||
HttpCacheStorage storage = new EhcacheHttpCacheStorage(CACHE_MANAGER.getCache(TEST_EHCACHE_NAME));
|
HttpCacheStorage storage = new EhcacheHttpCacheStorage(CACHE_MANAGER.getCache(TEST_EHCACHE_NAME));
|
||||||
mockBackend = EasyMock.createMock(HttpClient.class);
|
mockBackend = EasyMock.createNiceMock(HttpClient.class);
|
||||||
|
|
||||||
impl = new CachingHttpClient(mockBackend, new HeapResourceFactory(), storage, params);
|
impl = new CachingHttpClient(mockBackend, new HeapResourceFactory(), storage, params);
|
||||||
}
|
}
|
||||||
|
@ -57,13 +57,13 @@ public class TestMemcachedHttpCacheStorage extends TestCase {
|
|||||||
@Override
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
mockMemcachedClient = EasyMock.createMock(MemcachedClientIF.class);
|
mockMemcachedClient = EasyMock.createNiceMock(MemcachedClientIF.class);
|
||||||
mockKeyHashingScheme = EasyMock.createMock(KeyHashingScheme.class);
|
mockKeyHashingScheme = EasyMock.createNiceMock(KeyHashingScheme.class);
|
||||||
mockMemcachedCacheEntryFactory = EasyMock.createMock(MemcachedCacheEntryFactory.class);
|
mockMemcachedCacheEntryFactory = EasyMock.createNiceMock(MemcachedCacheEntryFactory.class);
|
||||||
mockMemcachedCacheEntry = EasyMock.createMock(MemcachedCacheEntry.class);
|
mockMemcachedCacheEntry = EasyMock.createNiceMock(MemcachedCacheEntry.class);
|
||||||
mockMemcachedCacheEntry2 = EasyMock.createMock(MemcachedCacheEntry.class);
|
mockMemcachedCacheEntry2 = EasyMock.createNiceMock(MemcachedCacheEntry.class);
|
||||||
mockMemcachedCacheEntry3 = EasyMock.createMock(MemcachedCacheEntry.class);
|
mockMemcachedCacheEntry3 = EasyMock.createNiceMock(MemcachedCacheEntry.class);
|
||||||
mockMemcachedCacheEntry4 = EasyMock.createMock(MemcachedCacheEntry.class);
|
mockMemcachedCacheEntry4 = EasyMock.createNiceMock(MemcachedCacheEntry.class);
|
||||||
CacheConfig config = new CacheConfig();
|
CacheConfig config = new CacheConfig();
|
||||||
config.setMaxUpdateRetries(1);
|
config.setMaxUpdateRetries(1);
|
||||||
impl = new MemcachedHttpCacheStorage(mockMemcachedClient, config,
|
impl = new MemcachedHttpCacheStorage(mockMemcachedClient, config,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user