From 6ba7afe88a249fd9153542fec6f56e6e44b651ae Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Sat, 15 Jan 2011 08:24:18 +0000 Subject: [PATCH] Fixed broken test case git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1059273 13f79535-47bb-0310-9956-ffa450edef68 --- .../impl/client/TestRequestRetryHandler.java | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java b/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java index 94266169d..40aee5f6b 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java @@ -35,8 +35,6 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.ConnectTimeoutException; -import org.apache.http.conn.HttpHostConnectException; -import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.scheme.SchemeSocketFactory; @@ -50,48 +48,28 @@ import org.junit.Test; public class TestRequestRetryHandler { - @Test(expected=HttpHostConnectException.class) + @Test(expected=UnknownHostException.class) public void testUseRetryHandlerInConnectionTimeOutWithThreadSafeClientConnManager() throws Exception { SchemeRegistry schemeRegistry = new SchemeRegistry(); - schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); + schemeRegistry.register(new Scheme("http", 80, new OppsieSchemeSocketFactory())); ClientConnectionManager connManager = new ThreadSafeClientConnManager(schemeRegistry); assertOnRetry(connManager); } - @Test(expected=HttpHostConnectException.class) + @Test(expected=UnknownHostException.class) public void testUseRetryHandlerInConnectionTimeOutWithSingleClientConnManager() throws Exception { SchemeRegistry schemeRegistry = new SchemeRegistry(); - schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); + schemeRegistry.register(new Scheme("http", 80, new OppsieSchemeSocketFactory())); ClientConnectionManager connManager = new SingleClientConnManager(schemeRegistry); assertOnRetry(connManager); } protected void assertOnRetry(ClientConnectionManager connManager) throws Exception { - SchemeRegistry schemeRegistry = new SchemeRegistry(); - schemeRegistry.register(new Scheme("http", 80, new SchemeSocketFactory() { - - public boolean isSecure(final Socket sock) throws IllegalArgumentException { - return false; - } - - public Socket createSocket(final HttpParams params) throws IOException { - throw new UnknownHostException("Ooopsie"); - } - - public Socket connectSocket( - final Socket sock, - final InetSocketAddress remoteAddress, - final InetSocketAddress localAddress, - final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { - throw new UnknownHostException("Ooopsie"); - } - })); - DefaultHttpClient client = new DefaultHttpClient(connManager); TestHttpRequestRetryHandler testRetryHandler = new TestHttpRequestRetryHandler(); client.setHttpRequestRetryHandler(testRetryHandler); @@ -121,4 +99,23 @@ public class TestRequestRetryHandler { } + static class OppsieSchemeSocketFactory implements SchemeSocketFactory { + + public boolean isSecure(final Socket sock) throws IllegalArgumentException { + return false; + } + + public Socket createSocket(final HttpParams params) throws IOException { + return new Socket(); + } + + public Socket connectSocket( + final Socket sock, + final InetSocketAddress remoteAddress, + final InetSocketAddress localAddress, + final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { + throw new UnknownHostException("Ooopsie"); + } + } + }