Fixed broken test case

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1165646 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2011-09-06 12:49:00 +00:00
parent ce13e3606f
commit d65b529e08
1 changed files with 50 additions and 41 deletions

View File

@ -27,11 +27,10 @@ package org.apache.http.impl.client;
import org.apache.http.conn.ConnectTimeoutException;
import java.io.IOException;
import java.net.UnknownHostException;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.ExecutionContext;
import static org.mockito.Mockito.when;
@ -42,27 +41,37 @@ import org.junit.Test;
public class TestDefaultHttpRequestRetryHandler {
@Test
public void retryOnConnectTimeout() throws Exception {
DefaultHttpClient client = new DefaultHttpClient();
@Test
public void noRetryOnConnectTimeout() throws Exception {
HttpContext context = mock(HttpContext.class);
HttpUriRequest request = mock(HttpUriRequest.class);
DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
Assert.assertEquals(3, retryHandler.getRetryCount());
client.setHttpRequestRetryHandler(retryHandler);
when(request.isAborted()).thenReturn(Boolean.FALSE);
when(context.getAttribute(ExecutionContext.HTTP_REQUEST)).thenReturn(request);
HttpRequestBase request = new HttpGet("http://www.example.com/");
HttpConnectionParams.setConnectionTimeout(request.getParams(), 1);
try {
client.execute(request);
} catch (ConnectTimeoutException ex) {
Assert.assertEquals(3, retryHandler.getRetryCount());
}
Assert.assertFalse(retryHandler.retryRequest(new ConnectTimeoutException(), 1, context));
}
@Test
public void noRetryOnAbortedRequests() throws Exception{
HttpContext context = mock(HttpContext.class);
HttpRequestBase request = mock(HttpRequestBase.class);
@Test
public void noRetryOnUnknownHost() throws Exception {
HttpContext context = mock(HttpContext.class);
HttpUriRequest request = mock(HttpUriRequest.class);
DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
when(request.isAborted()).thenReturn(Boolean.FALSE);
when(context.getAttribute(ExecutionContext.HTTP_REQUEST)).thenReturn(request);
Assert.assertFalse(retryHandler.retryRequest(new UnknownHostException(), 1, context));
}
@Test
public void noRetryOnAbortedRequests() throws Exception{
HttpContext context = mock(HttpContext.class);
HttpUriRequest request = mock(HttpUriRequest.class);
DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
@ -70,13 +79,13 @@ public class TestDefaultHttpRequestRetryHandler {
when(context.getAttribute(ExecutionContext.HTTP_REQUEST)).thenReturn(request);
Assert.assertFalse(retryHandler.retryRequest(new IOException(),3,context));
}
}
@Test
public void retryOnNonAbortedRequests() throws Exception{
@Test
public void retryOnNonAbortedRequests() throws Exception{
HttpContext context = mock(HttpContext.class);
HttpRequestBase request = mock(HttpRequestBase.class);
HttpContext context = mock(HttpContext.class);
HttpUriRequest request = mock(HttpUriRequest.class);
DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
@ -84,13 +93,13 @@ public class TestDefaultHttpRequestRetryHandler {
when(context.getAttribute(ExecutionContext.HTTP_REQUEST)).thenReturn(request);
Assert.assertTrue(retryHandler.retryRequest(new IOException(),3,context));
}
}
@Test
public void noRetryOnConnectionTimeout() throws Exception{
@Test
public void noRetryOnConnectionTimeout() throws Exception{
HttpContext context = mock(HttpContext.class);
HttpRequestBase request = mock(HttpRequestBase.class);
HttpContext context = mock(HttpContext.class);
HttpUriRequest request = mock(HttpUriRequest.class);
DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
@ -98,6 +107,6 @@ public class TestDefaultHttpRequestRetryHandler {
when(context.getAttribute(ExecutionContext.HTTP_REQUEST)).thenReturn(request);
Assert.assertFalse(retryHandler.retryRequest(new ConnectTimeoutException(),3,context));
}
}
}