hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1414678 [4/4] - in /httpcomponents/httpclient/trunk: fluent-hc/src/main/java/org/apache/http/client/fluent/ httpclient/src/examples/org/apache/http/examples/client/ httpclient/src/main/java/org/apache/http/client/protocol/ httpclient/src/m...
Date Wed, 28 Nov 2012 13:39:48 GMT
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java Wed Nov 28 13:39:31 2012
@@ -27,13 +27,13 @@
 package org.apache.http.impl.client.integration;
 
 import java.io.IOException;
-import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.http.Header;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
+import org.apache.http.HttpInetConnection;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
@@ -76,33 +76,30 @@ public class TestRedirects extends Integ
 
     private static class BasicRedirectService implements HttpRequestHandler {
 
-        private int statuscode = HttpStatus.SC_MOVED_TEMPORARILY;
-        private String host = null;
-        private int port;
+        private final int statuscode;
 
-        public BasicRedirectService(final String host, int port, int statuscode) {
+        public BasicRedirectService(int statuscode) {
             super();
-            this.host = host;
-            this.port = port;
-            if (statuscode > 0) {
-                this.statuscode = statuscode;
-            }
+            this.statuscode = statuscode > 0 ? statuscode : HttpStatus.SC_MOVED_TEMPORARILY;
         }
 
-        public BasicRedirectService(final String host, int port) {
-            this(host, port, -1);
+        public BasicRedirectService() {
+            this(-1);
         }
 
         public void handle(
                 final HttpRequest request,
                 final HttpResponse response,
                 final HttpContext context) throws HttpException, IOException {
+            HttpInetConnection conn = (HttpInetConnection) context.getAttribute(ExecutionContext.HTTP_CONNECTION);
+            String localhost = conn.getLocalAddress().getHostName();
+            int port = conn.getLocalPort();
             ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
             String uri = request.getRequestLine().getUri();
             if (uri.equals("/oldlocation/")) {
                 response.setStatusLine(ver, this.statuscode);
                 response.addHeader(new BasicHeader("Location",
-                        "http://" + this.host + ":" + this.port + "/newlocation/"));
+                        "http://" + localhost + ":" + port + "/newlocation/"));
                 response.addHeader(new BasicHeader("Connection", "close"));
             } else if (uri.equals("/newlocation/")) {
                 response.setStatusLine(ver, HttpStatus.SC_OK);
@@ -112,6 +109,7 @@ public class TestRedirects extends Integ
                 response.setStatusLine(ver, HttpStatus.SC_NOT_FOUND);
             }
         }
+
     }
 
     private static class CircularRedirectService implements HttpRequestHandler {
@@ -217,17 +215,15 @@ public class TestRedirects extends Integ
 
     @Test
     public void testBasicRedirect300() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
+        HttpHost target = getServerHttp();
         this.localServer.register("*",
-                new BasicRedirectService(host, port, HttpStatus.SC_MULTIPLE_CHOICES));
+                new BasicRedirectService(HttpStatus.SC_MULTIPLE_CHOICES));
 
         HttpContext context = new BasicHttpContext();
 
         HttpGet httpget = new HttpGet("/oldlocation/");
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+        HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
@@ -239,61 +235,53 @@ public class TestRedirects extends Integ
 
     @Test
     public void testBasicRedirect301() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
+        HttpHost target = getServerHttp();
         this.localServer.register("*",
-                new BasicRedirectService(host, port, HttpStatus.SC_MOVED_PERMANENTLY));
+                new BasicRedirectService(HttpStatus.SC_MOVED_PERMANENTLY));
 
         HttpContext context = new BasicHttpContext();
 
         HttpGet httpget = new HttpGet("/oldlocation/");
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+        HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
-        HttpHost targetHost = (HttpHost) context.getAttribute(
+        HttpHost host = (HttpHost) context.getAttribute(
                 ExecutionContext.HTTP_TARGET_HOST);
 
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());
-        Assert.assertEquals(host, targetHost.getHostName());
-        Assert.assertEquals(port, targetHost.getPort());
+        Assert.assertEquals(target, host);
     }
 
     @Test
     public void testBasicRedirect302() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
+        HttpHost target = getServerHttp();
         this.localServer.register("*",
-                new BasicRedirectService(host, port, HttpStatus.SC_MOVED_TEMPORARILY));
+                new BasicRedirectService(HttpStatus.SC_MOVED_TEMPORARILY));
 
         HttpContext context = new BasicHttpContext();
 
         HttpGet httpget = new HttpGet("/oldlocation/");
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+        HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
-        HttpHost targetHost = (HttpHost) context.getAttribute(
+        HttpHost host = (HttpHost) context.getAttribute(
                 ExecutionContext.HTTP_TARGET_HOST);
 
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());
-        Assert.assertEquals(host, targetHost.getHostName());
-        Assert.assertEquals(port, targetHost.getPort());
+        Assert.assertEquals(target, host);
     }
 
     @Test
     public void testBasicRedirect302NoLocation() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
+        HttpHost target = getServerHttp();
         this.localServer.register("*", new HttpRequestHandler() {
 
             public void handle(
@@ -309,59 +297,53 @@ public class TestRedirects extends Integ
 
         HttpGet httpget = new HttpGet("/oldlocation/");
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+        HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
-        HttpHost targetHost = (HttpHost) context.getAttribute(
+        HttpHost host = (HttpHost) context.getAttribute(
                 ExecutionContext.HTTP_TARGET_HOST);
 
         Assert.assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, response.getStatusLine().getStatusCode());
         Assert.assertEquals("/oldlocation/", reqWrapper.getRequestLine().getUri());
-        Assert.assertEquals(host, targetHost.getHostName());
-        Assert.assertEquals(port, targetHost.getPort());
+        Assert.assertEquals(target, host);
     }
 
     @Test
     public void testBasicRedirect303() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
+        HttpHost target = getServerHttp();
         this.localServer.register("*",
-                new BasicRedirectService(host, port, HttpStatus.SC_SEE_OTHER));
+                new BasicRedirectService(HttpStatus.SC_SEE_OTHER));
 
         HttpContext context = new BasicHttpContext();
 
         HttpGet httpget = new HttpGet("/oldlocation/");
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+        HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
-        HttpHost targetHost = (HttpHost) context.getAttribute(
+        HttpHost host = (HttpHost) context.getAttribute(
                 ExecutionContext.HTTP_TARGET_HOST);
 
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());
-        Assert.assertEquals(host, targetHost.getHostName());
-        Assert.assertEquals(port, targetHost.getPort());
+        Assert.assertEquals(target, host);
     }
 
     @Test
     public void testBasicRedirect304() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
+        HttpHost target = getServerHttp();
         this.localServer.register("*",
-                new BasicRedirectService(host, port, HttpStatus.SC_NOT_MODIFIED));
+                new BasicRedirectService(HttpStatus.SC_NOT_MODIFIED));
 
         HttpContext context = new BasicHttpContext();
 
         HttpGet httpget = new HttpGet("/oldlocation/");
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+        HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
@@ -373,17 +355,14 @@ public class TestRedirects extends Integ
 
     @Test
     public void testBasicRedirect305() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
+        HttpHost target = getServerHttp();
         this.localServer.register("*",
-                new BasicRedirectService(host, port, HttpStatus.SC_USE_PROXY));
-
+                new BasicRedirectService(HttpStatus.SC_USE_PROXY));
         HttpContext context = new BasicHttpContext();
 
         HttpGet httpget = new HttpGet("/oldlocation/");
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+        HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
@@ -395,32 +374,30 @@ public class TestRedirects extends Integ
 
     @Test
     public void testBasicRedirect307() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
+        HttpHost target = getServerHttp();
         this.localServer.register("*",
-                new BasicRedirectService(host, port, HttpStatus.SC_TEMPORARY_REDIRECT));
+                new BasicRedirectService(HttpStatus.SC_TEMPORARY_REDIRECT));
 
         HttpContext context = new BasicHttpContext();
 
         HttpGet httpget = new HttpGet("/oldlocation/");
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+        HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
-        HttpHost targetHost = (HttpHost) context.getAttribute(
+        HttpHost host = (HttpHost) context.getAttribute(
                 ExecutionContext.HTTP_TARGET_HOST);
 
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());
-        Assert.assertEquals(host, targetHost.getHostName());
-        Assert.assertEquals(port, targetHost.getPort());
+        Assert.assertEquals(target, host);
     }
 
     @Test(expected=ClientProtocolException.class)
     public void testMaxRedirectCheck() throws Exception {
+        HttpHost target = getServerHttp();
         this.localServer.register("*", new CircularRedirectService());
 
         this.httpclient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
@@ -428,7 +405,7 @@ public class TestRedirects extends Integ
 
         HttpGet httpget = new HttpGet("/circular-oldlocation/");
         try {
-            this.httpclient.execute(getServerHttp(), httpget);
+            this.httpclient.execute(target, httpget);
         } catch (ClientProtocolException e) {
             Assert.assertTrue(e.getCause() instanceof RedirectException);
             throw e;
@@ -437,6 +414,7 @@ public class TestRedirects extends Integ
 
     @Test(expected=ClientProtocolException.class)
     public void testCircularRedirect() throws Exception {
+        HttpHost target = getServerHttp();
         this.localServer.register("*", new CircularRedirectService());
 
         this.httpclient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false);
@@ -444,7 +422,7 @@ public class TestRedirects extends Integ
         HttpGet httpget = new HttpGet("/circular-oldlocation/");
 
         try {
-            this.httpclient.execute(getServerHttp(), httpget);
+            this.httpclient.execute(target, httpget);
         } catch (ClientProtocolException e) {
             Assert.assertTrue(e.getCause() instanceof CircularRedirectException);
             throw e;
@@ -453,17 +431,15 @@ public class TestRedirects extends Integ
 
     @Test
     public void testPostNoRedirect() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
-        this.localServer.register("*", new BasicRedirectService(host, port));
+        HttpHost target = getServerHttp();
+        this.localServer.register("*", new BasicRedirectService());
 
         HttpContext context = new BasicHttpContext();
 
         HttpPost httppost = new HttpPost("/oldlocation/");
         httppost.setEntity(new StringEntity("stuff"));
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httppost, context);
+        HttpResponse response = this.httpclient.execute(target, httppost, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
@@ -476,18 +452,15 @@ public class TestRedirects extends Integ
 
     @Test
     public void testPostRedirectSeeOther() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
-        this.localServer.register("*", new BasicRedirectService(host, port,
-                HttpStatus.SC_SEE_OTHER));
+        HttpHost target = getServerHttp();
+        this.localServer.register("*", new BasicRedirectService(HttpStatus.SC_SEE_OTHER));
 
         HttpContext context = new BasicHttpContext();
 
         HttpPost httppost = new HttpPost("/oldlocation/");
         httppost.setEntity(new StringEntity("stuff"));
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httppost, context);
+        HttpResponse response = this.httpclient.execute(target, httppost, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
@@ -500,9 +473,7 @@ public class TestRedirects extends Integ
 
     @Test
     public void testRelativeRedirect() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
+        HttpHost target = getServerHttp();
         this.localServer.register("*", new RelativeRedirectService());
 
         HttpContext context = new BasicHttpContext();
@@ -511,25 +482,22 @@ public class TestRedirects extends Integ
                 ClientPNames.REJECT_RELATIVE_REDIRECT, false);
         HttpGet httpget = new HttpGet("/oldlocation/");
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+        HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
-        HttpHost targetHost = (HttpHost) context.getAttribute(
+        HttpHost host = (HttpHost) context.getAttribute(
                 ExecutionContext.HTTP_TARGET_HOST);
 
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertEquals("/relativelocation/", reqWrapper.getRequestLine().getUri());
-        Assert.assertEquals(host, targetHost.getHostName());
-        Assert.assertEquals(port, targetHost.getPort());
+        Assert.assertEquals(host, target);
     }
 
     @Test
     public void testRelativeRedirect2() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
+        HttpHost target = getServerHttp();
         this.localServer.register("*", new RelativeRedirectService2());
 
         HttpContext context = new BasicHttpContext();
@@ -538,22 +506,22 @@ public class TestRedirects extends Integ
                 ClientPNames.REJECT_RELATIVE_REDIRECT, false);
         HttpGet httpget = new HttpGet("/test/oldlocation");
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+        HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                 ExecutionContext.HTTP_REQUEST);
-        HttpHost targetHost = (HttpHost) context.getAttribute(
+        HttpHost host = (HttpHost) context.getAttribute(
                 ExecutionContext.HTTP_TARGET_HOST);
 
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertEquals("/test/relativelocation", reqWrapper.getRequestLine().getUri());
-        Assert.assertEquals(host, targetHost.getHostName());
-        Assert.assertEquals(port, targetHost.getPort());
+        Assert.assertEquals(host, target);
     }
 
     @Test(expected=ClientProtocolException.class)
     public void testRejectRelativeRedirect() throws Exception {
+        HttpHost target = getServerHttp();
         this.localServer.register("*", new RelativeRedirectService());
 
         this.httpclient.getParams().setBooleanParameter(
@@ -561,34 +529,34 @@ public class TestRedirects extends Integ
         HttpGet httpget = new HttpGet("/oldlocation/");
 
         try {
-            this.httpclient.execute(getServerHttp(), httpget);
+            this.httpclient.execute(target, httpget);
         } catch (ClientProtocolException e) {
             Assert.assertTrue(e.getCause() instanceof ProtocolException);
             throw e;
         }
     }
 
-    @Test(expected=ClientProtocolException.class)
+    @Test(expected=IOException.class)
     public void testRejectBogusRedirectLocation() throws Exception {
+        HttpHost target = getServerHttp();
         this.localServer.register("*", new BogusRedirectService("xxx://bogus"));
 
         HttpGet httpget = new HttpGet("/oldlocation/");
 
-        this.httpclient.execute(getServerHttp(), httpget);
+        this.httpclient.execute(target, httpget);
     }
 
     @Test(expected=ClientProtocolException.class)
     public void testRejectInvalidRedirectLocation() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
+        HttpHost target = getServerHttp();
         this.localServer.register("*",
-                new BogusRedirectService("http://"+ host +":"+ port +"/newlocation/?p=I have spaces"));
+                new BogusRedirectService("http://" + target.toHostString() +
+                        "/newlocation/?p=I have spaces"));
 
         HttpGet httpget = new HttpGet("/oldlocation/");
 
         try {
-            this.httpclient.execute(getServerHttp(), httpget);
+            this.httpclient.execute(target, httpget);
         } catch (ClientProtocolException e) {
             Assert.assertTrue(e.getCause() instanceof ProtocolException);
             throw e;
@@ -597,16 +565,14 @@ public class TestRedirects extends Integ
 
     @Test
     public void testRedirectWithCookie() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
+        HttpHost target = getServerHttp();
 
-        this.localServer.register("*", new BasicRedirectService(host, port));
+        this.localServer.register("*", new BasicRedirectService());
 
         CookieStore cookieStore = new BasicCookieStore();
 
         BasicClientCookie cookie = new BasicClientCookie("name", "value");
-        cookie.setDomain(host);
+        cookie.setDomain(target.getHostName());
         cookie.setPath("/");
 
         cookieStore.addCookie(cookie);
@@ -616,7 +582,7 @@ public class TestRedirects extends Integ
         HttpGet httpget = new HttpGet("/oldlocation/");
 
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+        HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
@@ -631,11 +597,9 @@ public class TestRedirects extends Integ
 
     @Test
     public void testDefaultHeadersRedirect() throws Exception {
-        InetSocketAddress address = this.localServer.getServiceAddress();
-        int port = address.getPort();
-        String host = address.getHostName();
+        HttpHost target = getServerHttp();
 
-        this.localServer.register("*", new BasicRedirectService(host, port));
+        this.localServer.register("*", new BasicRedirectService());
 
         HttpContext context = new BasicHttpContext();
 
@@ -647,7 +611,7 @@ public class TestRedirects extends Integ
         HttpGet httpget = new HttpGet("/oldlocation/");
 
 
-        HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+        HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
 
         HttpRequest reqWrapper = (HttpRequest) context.getAttribute(

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java Wed Nov 28 13:39:31 2012
@@ -27,20 +27,17 @@
 
 package org.apache.http.impl.conn;
 
-import java.net.Socket;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpHost;
+import org.apache.http.config.ConnectionConfig;
+import org.apache.http.config.Lookup;
 import org.apache.http.conn.ConnectionRequest;
-import org.apache.http.conn.DnsResolver;
 import org.apache.http.conn.HttpConnectionFactory;
 import org.apache.http.conn.SocketClientConnection;
 import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SchemeSocketFactory;
-import org.apache.http.params.HttpParams;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -50,10 +47,7 @@ public class TestBasicHttpClientConnecti
 
     private SocketClientConnection conn;
     private HttpConnectionFactory<SocketClientConnection> connFactory;
-    private Socket socket;
-    private SchemeSocketFactory plainSocketFactory;
-    private SchemeRegistry schemeRegistry;
-    private DnsResolver dnsResolver;
+    private Lookup<ConnectionSocketFactory> socketFactoryRegistry;
     private BasicHttpClientConnectionManager mgr;
 
     @SuppressWarnings("unchecked")
@@ -61,24 +55,17 @@ public class TestBasicHttpClientConnecti
     public void setup() throws Exception {
         conn = Mockito.mock(SocketClientConnection.class);
         connFactory = Mockito.mock(HttpConnectionFactory.class);
-        Mockito.when(connFactory.create()).thenReturn(conn);
-        socket = Mockito.mock(Socket.class);
-        plainSocketFactory = Mockito.mock(SchemeSocketFactory.class);
-        Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpParams>any())).thenReturn(socket);
-
-        Scheme http = new Scheme("http", 80, plainSocketFactory);
-        schemeRegistry = new SchemeRegistry();
-        schemeRegistry.register(http);
-
-        dnsResolver = Mockito.mock(DnsResolver.class);
-
-        mgr = new BasicHttpClientConnectionManager(schemeRegistry, dnsResolver, connFactory);
+        socketFactoryRegistry = Mockito.mock(Lookup.class);
+        mgr = new BasicHttpClientConnectionManager(socketFactoryRegistry, connFactory);
     }
 
     @Test
     public void testLeaseReleaseNonReusable() throws Exception {
         HttpHost target = new HttpHost("localhost");
         HttpRoute route = new HttpRoute(target);
+
+        Mockito.when(connFactory.create(Mockito.<ConnectionConfig>any())).thenReturn(conn);
+
         ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
         HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
         Assert.assertNotNull(conn1);
@@ -94,18 +81,21 @@ public class TestBasicHttpClientConnecti
         Assert.assertNotNull(conn2);
         Assert.assertFalse(conn2.isOpen());
 
-        Mockito.verify(connFactory, Mockito.times(2)).create();
+        Mockito.verify(connFactory, Mockito.times(2)).create(Mockito.<ConnectionConfig>any());
     }
 
     @Test
     public void testLeaseReleaseReusable() throws Exception {
         HttpHost target = new HttpHost("somehost");
         HttpRoute route = new HttpRoute(target);
+
+        Mockito.when(connFactory.create(Mockito.<ConnectionConfig>any())).thenReturn(conn);
+
         ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
         HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
         Assert.assertNotNull(conn1);
 
-        Mockito.verify(connFactory, Mockito.times(1)).create();
+        Mockito.verify(connFactory, Mockito.times(1)).create(Mockito.<ConnectionConfig>any());
 
         Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);
 
@@ -119,18 +109,21 @@ public class TestBasicHttpClientConnecti
         Assert.assertNotNull(conn2);
         Assert.assertTrue(conn2.isOpen());
 
-        Mockito.verify(connFactory, Mockito.times(1)).create();
+        Mockito.verify(connFactory, Mockito.times(1)).create(Mockito.<ConnectionConfig>any());
     }
 
     @Test
     public void testLeaseReleaseReusableWithState() throws Exception {
         HttpHost target = new HttpHost("somehost");
         HttpRoute route = new HttpRoute(target);
+
+        Mockito.when(connFactory.create(Mockito.<ConnectionConfig>any())).thenReturn(conn);
+
         ConnectionRequest connRequest1 = mgr.requestConnection(route, "some state");
         HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
         Assert.assertNotNull(conn1);
 
-        Mockito.verify(connFactory, Mockito.times(1)).create();
+        Mockito.verify(connFactory, Mockito.times(1)).create(Mockito.<ConnectionConfig>any());
 
         Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);
 
@@ -144,18 +137,21 @@ public class TestBasicHttpClientConnecti
         Assert.assertNotNull(conn2);
         Assert.assertTrue(conn2.isOpen());
 
-        Mockito.verify(connFactory, Mockito.times(1)).create();
+        Mockito.verify(connFactory, Mockito.times(1)).create(Mockito.<ConnectionConfig>any());
     }
 
     @Test
     public void testLeaseDifferentRoute() throws Exception {
         HttpHost target1 = new HttpHost("somehost");
         HttpRoute route1 = new HttpRoute(target1);
+
+        Mockito.when(connFactory.create(Mockito.<ConnectionConfig>any())).thenReturn(conn);
+
         ConnectionRequest connRequest1 = mgr.requestConnection(route1, null);
         HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
         Assert.assertNotNull(conn1);
 
-        Mockito.verify(connFactory, Mockito.times(1)).create();
+        Mockito.verify(connFactory, Mockito.times(1)).create(Mockito.<ConnectionConfig>any());
 
         Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE, Boolean.FALSE);
 
@@ -172,18 +168,21 @@ public class TestBasicHttpClientConnecti
         Assert.assertFalse(conn2.isOpen());
 
         Mockito.verify(conn).close();
-        Mockito.verify(connFactory, Mockito.times(2)).create();
+        Mockito.verify(connFactory, Mockito.times(2)).create(Mockito.<ConnectionConfig>any());
     }
 
     @Test
     public void testLeaseExpired() throws Exception {
         HttpHost target = new HttpHost("somehost");
         HttpRoute route = new HttpRoute(target);
+
+        Mockito.when(connFactory.create(Mockito.<ConnectionConfig>any())).thenReturn(conn);
+
         ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
         HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
         Assert.assertNotNull(conn1);
 
-        Mockito.verify(connFactory, Mockito.times(1)).create();
+        Mockito.verify(connFactory, Mockito.times(1)).create(Mockito.<ConnectionConfig>any());
 
         Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE, Boolean.FALSE);
 
@@ -200,7 +199,7 @@ public class TestBasicHttpClientConnecti
         Assert.assertFalse(conn2.isOpen());
 
         Mockito.verify(conn).close();
-        Mockito.verify(connFactory, Mockito.times(2)).create();
+        Mockito.verify(connFactory, Mockito.times(2)).create(Mockito.<ConnectionConfig>any());
     }
 
     @Test(expected=IllegalArgumentException.class)
@@ -223,11 +222,14 @@ public class TestBasicHttpClientConnecti
     public void testShutdown() throws Exception {
         HttpHost target = new HttpHost("somehost");
         HttpRoute route = new HttpRoute(target);
+
+        Mockito.when(connFactory.create(Mockito.<ConnectionConfig>any())).thenReturn(conn);
+
         ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
         HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
         Assert.assertNotNull(conn1);
 
-        Mockito.verify(connFactory, Mockito.times(1)).create();
+        Mockito.verify(connFactory, Mockito.times(1)).create(Mockito.<ConnectionConfig>any());
 
         Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);
 
@@ -249,11 +251,14 @@ public class TestBasicHttpClientConnecti
     public void testCloseExpired() throws Exception {
         HttpHost target = new HttpHost("somehost");
         HttpRoute route = new HttpRoute(target);
+
+        Mockito.when(connFactory.create(Mockito.<ConnectionConfig>any())).thenReturn(conn);
+
         ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
         HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
         Assert.assertNotNull(conn1);
 
-        Mockito.verify(connFactory, Mockito.times(1)).create();
+        Mockito.verify(connFactory, Mockito.times(1)).create(Mockito.<ConnectionConfig>any());
 
         Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE, Boolean.FALSE);
 
@@ -273,11 +278,14 @@ public class TestBasicHttpClientConnecti
     public void testCloseIdle() throws Exception {
         HttpHost target = new HttpHost("somehost");
         HttpRoute route = new HttpRoute(target);
+
+        Mockito.when(connFactory.create(Mockito.<ConnectionConfig>any())).thenReturn(conn);
+
         ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
         HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
         Assert.assertNotNull(conn1);
 
-        Mockito.verify(connFactory, Mockito.times(1)).create();
+        Mockito.verify(connFactory, Mockito.times(1)).create(Mockito.<ConnectionConfig>any());
 
         Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE, Boolean.FALSE);
 
@@ -297,6 +305,9 @@ public class TestBasicHttpClientConnecti
     public void testAlreadyLeased() throws Exception {
         HttpHost target = new HttpHost("somehost");
         HttpRoute route = new HttpRoute(target);
+
+        Mockito.when(connFactory.create(Mockito.<ConnectionConfig>any())).thenReturn(conn);
+
         ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
         HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
         Assert.assertNotNull(conn1);

Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java?rev=1414678&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java Wed Nov 28 13:39:31 2012
@@ -0,0 +1,81 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.conn;
+
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpVersion;
+import org.apache.http.conn.SchemePortResolver;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.message.BasicHttpRequest;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * Tests for {@link DefaultRoutePlanner}.
+ */
+public class TestDefaultRoutePlanner {
+
+    private SchemePortResolver schemePortResolver;
+    private DefaultRoutePlanner routePlanner;
+
+    @Before
+    public void setup() {
+        schemePortResolver = Mockito.mock(SchemePortResolver.class);
+        routePlanner = new DefaultRoutePlanner(schemePortResolver);
+    }
+
+    @Test
+    public void testDirect() throws Exception {
+        HttpHost target = new HttpHost("somehost", 80, "http");
+        HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
+
+        HttpRoute route = routePlanner.determineRoute(target, request, null);
+
+        Assert.assertEquals(target, route.getTargetHost());
+        Assert.assertEquals(1, route.getHopCount());
+        Assert.assertFalse(route.isSecure());
+        Mockito.verify(schemePortResolver, Mockito.never()).resolve(Mockito.<HttpHost>any());
+    }
+
+    @Test
+    public void testDirectDefaultPort() throws Exception {
+        HttpHost target = new HttpHost("somehost", -1, "https");
+        Mockito.when(schemePortResolver.resolve(target)).thenReturn(443);
+        HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
+
+        HttpRoute route = routePlanner.determineRoute(target, request, null);
+
+        Assert.assertEquals(new HttpHost("somehost", 443, "https"), route.getTargetHost());
+        Assert.assertEquals(1, route.getHopCount());
+        Assert.assertTrue(route.isSecure());
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionManagerBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionManagerBase.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionManagerBase.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionManagerBase.java Wed Nov 28 13:39:31 2012
@@ -35,16 +35,16 @@ import java.util.concurrent.TimeoutExcep
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpHost;
+import org.apache.http.config.Lookup;
 import org.apache.http.conn.ConnectionPoolTimeoutException;
 import org.apache.http.conn.ConnectionRequest;
 import org.apache.http.conn.DnsResolver;
+import org.apache.http.conn.SchemePortResolver;
 import org.apache.http.conn.SocketClientConnection;
 import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SchemeSocketFactory;
-import org.apache.http.params.HttpParams;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
 import org.apache.http.pool.ConnPool;
+import org.apache.http.protocol.HttpContext;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -54,8 +54,9 @@ public class TestHttpClientConnectionMan
 
     private SocketClientConnection conn;
     private Socket socket;
-    private SchemeSocketFactory plainSocketFactory;
-    private SchemeRegistry schemeRegistry;
+    private ConnectionSocketFactory plainSocketFactory;
+    private Lookup<ConnectionSocketFactory> socketFactoryRegistry;
+    private SchemePortResolver schemePortResolver;
     private DnsResolver dnsResolver;
     private Future<CPoolEntry> future;
     private ConnPool<HttpRoute, CPoolEntry> pool;
@@ -66,17 +67,14 @@ public class TestHttpClientConnectionMan
     public void setup() throws Exception {
         conn = Mockito.mock(SocketClientConnection.class);
         socket = Mockito.mock(Socket.class);
-        plainSocketFactory = Mockito.mock(SchemeSocketFactory.class);
-        Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpParams>any())).thenReturn(socket);
+        plainSocketFactory = Mockito.mock(ConnectionSocketFactory.class);
+        socketFactoryRegistry = Mockito.mock(Lookup.class);
+        schemePortResolver = Mockito.mock(SchemePortResolver.class);
         dnsResolver = Mockito.mock(DnsResolver.class);
-
-        Scheme http = new Scheme("http", 80, plainSocketFactory);
-        schemeRegistry = new SchemeRegistry();
-        schemeRegistry.register(http);
-
         pool = Mockito.mock(ConnPool.class);
         future = Mockito.mock(Future.class);
-        mgr = new HttpClientConnectionManagerBase(pool, schemeRegistry, dnsResolver) {
+        mgr = new HttpClientConnectionManagerBase(
+                pool, socketFactoryRegistry, schemePortResolver, dnsResolver) {
 
             public void closeIdleConnections(long idletime, TimeUnit tunit) {
             }
@@ -99,6 +97,11 @@ public class TestHttpClientConnectionMan
                 -1, TimeUnit.MILLISECONDS);
 
         Mockito.when(future.isCancelled()).thenReturn(Boolean.FALSE);
+        Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainSocketFactory);
+        Mockito.when(schemePortResolver.resolve(target)).thenReturn(80);
+        Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpContext>any())).thenReturn(socket);
+
+        Mockito.when(future.isCancelled()).thenReturn(false);
         Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
         Mockito.when(pool.lease(route, null, null)).thenReturn(future);
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java Wed Nov 28 13:39:31 2012
@@ -32,16 +32,14 @@ import java.net.InetSocketAddress;
 import java.net.Socket;
 
 import org.apache.http.HttpHost;
+import org.apache.http.config.Lookup;
+import org.apache.http.config.SocketConfig;
 import org.apache.http.conn.ConnectTimeoutException;
 import org.apache.http.conn.DnsResolver;
-import org.apache.http.conn.HttpInetSocketAddress;
+import org.apache.http.conn.SchemePortResolver;
 import org.apache.http.conn.SocketClientConnection;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SchemeSocketFactory;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpParams;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.HttpContext;
 import org.junit.Before;
@@ -52,116 +50,150 @@ public class TestHttpClientConnectionOpe
 
     private SocketClientConnection conn;
     private Socket socket;
-    private SchemeSocketFactory plainSocketFactory;
-    private SchemeLayeredSocketFactory sslSocketFactory;
-    private SchemeRegistry schemeRegistry;
+    private ConnectionSocketFactory plainSocketFactory;
+    private LayeredConnectionSocketFactory sslSocketFactory;
+    private Lookup<ConnectionSocketFactory> socketFactoryRegistry;
+    private SchemePortResolver schemePortResolver;
     private DnsResolver dnsResolver;
     private HttpClientConnectionOperator connectionOperator;
 
+    @SuppressWarnings("unchecked")
     @Before
     public void setup() throws Exception {
         conn = Mockito.mock(SocketClientConnection.class);
         socket = Mockito.mock(Socket.class);
-        plainSocketFactory = Mockito.mock(SchemeSocketFactory.class);
-        sslSocketFactory = Mockito.mock(SchemeLayeredSocketFactory.class);
-        Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpParams>any())).thenReturn(socket);
-        Mockito.when(sslSocketFactory.createSocket(Mockito.<HttpParams>any())).thenReturn(socket);
+        plainSocketFactory = Mockito.mock(ConnectionSocketFactory.class);
+        sslSocketFactory = Mockito.mock(LayeredConnectionSocketFactory.class);
+        socketFactoryRegistry = Mockito.mock(Lookup.class);
+        schemePortResolver = Mockito.mock(SchemePortResolver.class);
         dnsResolver = Mockito.mock(DnsResolver.class);
-
-        Scheme http = new Scheme("http", 80, plainSocketFactory);
-        Scheme https = new Scheme("https", 443, sslSocketFactory);
-        schemeRegistry = new SchemeRegistry();
-        schemeRegistry.register(http);
-        schemeRegistry.register(https);
-
-        connectionOperator = new HttpClientConnectionOperator(schemeRegistry, dnsResolver);
+        connectionOperator = new HttpClientConnectionOperator(
+                socketFactoryRegistry, schemePortResolver, dnsResolver);
     }
 
     @Test
     public void testConnect() throws Exception {
         HttpContext context = new BasicHttpContext();
-        HttpParams params = new BasicHttpParams();
         HttpHost host = new HttpHost("somehost");
         InetAddress local = InetAddress.getByAddress(new byte[] {127, 0, 0, 0});
         InetAddress ip1 = InetAddress.getByAddress(new byte[] {127, 0, 0, 1});
         InetAddress ip2 = InetAddress.getByAddress(new byte[] {127, 0, 0, 2});
 
         Mockito.when(dnsResolver.resolve("somehost")).thenReturn(new InetAddress[] { ip1, ip2 });
+        Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainSocketFactory);
+        Mockito.when(schemePortResolver.resolve(host)).thenReturn(80);
+        Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpContext>any())).thenReturn(socket);
         Mockito.when(plainSocketFactory.connectSocket(
+                Mockito.anyInt(),
                 Mockito.<Socket>any(),
+                Mockito.<HttpHost>any(),
                 Mockito.<InetSocketAddress>any(),
                 Mockito.<InetSocketAddress>any(),
-                Mockito.<HttpParams>any())).thenReturn(socket);
+                Mockito.<HttpContext>any())).thenReturn(socket);
 
-        connectionOperator.connect(conn, host, local, context, params);
-
-        Mockito.verify(plainSocketFactory).connectSocket(socket,
+        SocketConfig socketConfig = SocketConfig.custom()
+            .setSoKeepAlive(true)
+            .setSoReuseAddress(true)
+            .setSoTimeout(5000)
+            .setTcpNoDelay(true)
+            .setSoLinger(50)
+            .build();
+        InetSocketAddress localAddress = new InetSocketAddress(local, 0);
+        connectionOperator.connect(conn, host, localAddress, 1000, socketConfig, context);
+
+        Mockito.verify(socket).setKeepAlive(true);
+        Mockito.verify(socket).setReuseAddress(true);
+        Mockito.verify(socket).setSoTimeout(5000);
+        Mockito.verify(socket).setSoLinger(true, 50);
+        Mockito.verify(socket).setTcpNoDelay(true);
+
+        Mockito.verify(plainSocketFactory).connectSocket(
+                1000,
+                socket,
+                host,
                 new InetSocketAddress(ip1, 80),
-                new InetSocketAddress(local, 0), params);
+                localAddress,
+                context);
         Mockito.verify(conn, Mockito.times(2)).bind(socket);
     }
 
     @Test(expected=ConnectTimeoutException.class)
     public void testConnectFailure() throws Exception {
         HttpContext context = new BasicHttpContext();
-        HttpParams params = new BasicHttpParams();
         HttpHost host = new HttpHost("somehost");
-        InetAddress local = InetAddress.getByAddress(new byte[] {127, 0, 0, 0});
         InetAddress ip1 = InetAddress.getByAddress(new byte[] {10, 0, 0, 1});
         InetAddress ip2 = InetAddress.getByAddress(new byte[] {10, 0, 0, 2});
 
         Mockito.when(dnsResolver.resolve("somehost")).thenReturn(new InetAddress[] { ip1, ip2 });
+        Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainSocketFactory);
+        Mockito.when(schemePortResolver.resolve(host)).thenReturn(80);
+        Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpContext>any())).thenReturn(socket);
         Mockito.when(plainSocketFactory.connectSocket(
+                Mockito.anyInt(),
                 Mockito.<Socket>any(),
+                Mockito.<HttpHost>any(),
                 Mockito.<InetSocketAddress>any(),
                 Mockito.<InetSocketAddress>any(),
-                Mockito.<HttpParams>any())).thenThrow(new ConnectTimeoutException());
+                Mockito.<HttpContext>any())).thenThrow(new ConnectTimeoutException());
 
-        connectionOperator.connect(conn, host, local, context, params);
+        connectionOperator.connect(conn, host, null, 1000, SocketConfig.DEFAULT, context);
     }
 
     @Test
     public void testConnectFailover() throws Exception {
         HttpContext context = new BasicHttpContext();
-        HttpParams params = new BasicHttpParams();
         HttpHost host = new HttpHost("somehost");
         InetAddress local = InetAddress.getByAddress(new byte[] {127, 0, 0, 0});
         InetAddress ip1 = InetAddress.getByAddress(new byte[] {10, 0, 0, 1});
         InetAddress ip2 = InetAddress.getByAddress(new byte[] {10, 0, 0, 2});
 
         Mockito.when(dnsResolver.resolve("somehost")).thenReturn(new InetAddress[] { ip1, ip2 });
+        Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainSocketFactory);
+        Mockito.when(schemePortResolver.resolve(host)).thenReturn(80);
+        Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpContext>any())).thenReturn(socket);
         Mockito.when(plainSocketFactory.connectSocket(
+                Mockito.anyInt(),
                 Mockito.<Socket>any(),
-                Mockito.eq(new HttpInetSocketAddress(host, ip1, 80)),
+                Mockito.<HttpHost>any(),
+                Mockito.eq(new InetSocketAddress(ip1, 80)),
                 Mockito.<InetSocketAddress>any(),
-                Mockito.<HttpParams>any())).thenThrow(new ConnectTimeoutException());
+                Mockito.<HttpContext>any())).thenThrow(new ConnectTimeoutException());
         Mockito.when(plainSocketFactory.connectSocket(
+                Mockito.anyInt(),
                 Mockito.<Socket>any(),
-                Mockito.eq(new HttpInetSocketAddress(host, ip2, 80)),
+                Mockito.<HttpHost>any(),
+                Mockito.eq(new InetSocketAddress(ip2, 80)),
                 Mockito.<InetSocketAddress>any(),
-                Mockito.<HttpParams>any())).thenReturn(socket);
+                Mockito.<HttpContext>any())).thenReturn(socket);
 
-        connectionOperator.connect(conn, host, local, context, params);
+        InetSocketAddress localAddress = new InetSocketAddress(local, 0);
+        connectionOperator.connect(conn, host, localAddress, 1000, SocketConfig.DEFAULT, context);
 
-        Mockito.verify(plainSocketFactory).connectSocket(socket,
-                new HttpInetSocketAddress(host, ip2, 80),
-                new InetSocketAddress(local, 0), params);
+        Mockito.verify(plainSocketFactory).connectSocket(
+                1000,
+                socket,
+                host,
+                new InetSocketAddress(ip2, 80),
+                localAddress,
+                context);
         Mockito.verify(conn, Mockito.times(3)).bind(socket);
     }
 
     @Test
     public void testUpgrade() throws Exception {
         HttpContext context = new BasicHttpContext();
-        HttpParams params = new BasicHttpParams();
         HttpHost host = new HttpHost("somehost", -1, "https");
 
+        Mockito.when(socketFactoryRegistry.lookup("https")).thenReturn(sslSocketFactory);
+        Mockito.when(schemePortResolver.resolve(host)).thenReturn(443);
+        Mockito.when(sslSocketFactory.createSocket(Mockito.<HttpContext>any())).thenReturn(socket);
         Mockito.when(sslSocketFactory.createLayeredSocket(
                 Mockito.<Socket>any(),
                 Mockito.eq("somehost"),
                 Mockito.eq(443),
-                Mockito.<HttpParams>any())).thenReturn(socket);
+                Mockito.<HttpContext>any())).thenReturn(socket);
 
-        connectionOperator.upgrade(conn, host, context, params);
+        connectionOperator.upgrade(conn, host, context);
 
         Mockito.verify(conn).bind(socket);
     }
@@ -169,10 +201,9 @@ public class TestHttpClientConnectionOpe
     @Test(expected=IllegalArgumentException.class)
     public void testUpgradeNonLayeringScheme() throws Exception {
         HttpContext context = new BasicHttpContext();
-        HttpParams params = new BasicHttpParams();
         HttpHost host = new HttpHost("somehost", -1, "http");
 
-        connectionOperator.upgrade(conn, host, context, params);
+        connectionOperator.upgrade(conn, host, context);
     }
 
 }

Copied: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java (from r1414676, httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java?p2=httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java&p1=httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java&r1=1414676&r2=1414678&rev=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java Wed Nov 28 13:39:31 2012
@@ -27,61 +27,65 @@
 
 package org.apache.http.impl.conn;
 
-import java.net.Proxy;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
-import java.util.List;
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.URI;
 import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpVersion;
-import org.apache.http.message.BasicHttpRequest;
-
+import org.apache.http.conn.SchemePortResolver;
 import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.conn.routing.HttpRoutePlanner;
-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.mockup.ProxySelectorMockup;
+import org.apache.http.message.BasicHttpRequest;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
+import org.mockito.Mockito;
 
 /**
- * Tests for <code>ProxySelectorRoutePlanner</code>.
+ * Tests for {@link SystemDefaultRoutePlanner}.
  */
-public class TestProxySelRoutePlanner {
+public class TestSystemDefaultRoutePlanner {
 
-    /**
-     * Instantiates a default scheme registry.
-     *
-     * @return the default scheme registry
-     */
-    public SchemeRegistry createSchemeRegistry() {
-
-        SchemeRegistry schreg = new SchemeRegistry();
-        schreg.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
-
-        return schreg;
+    private SchemePortResolver schemePortResolver;
+    private ProxySelector proxySelector;
+    private SystemDefaultRoutePlanner routePlanner;
+
+    @Before
+    public void setup() {
+        schemePortResolver = Mockito.mock(SchemePortResolver.class);
+        proxySelector = Mockito.mock(ProxySelector.class);
+        routePlanner = new SystemDefaultRoutePlanner(schemePortResolver, proxySelector);
     }
 
     @Test
     public void testDirect() throws Exception {
+        HttpHost target = new HttpHost("somehost", 80, "http");
+        HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
 
-        HttpRoutePlanner hrp =
-            new ProxySelectorRoutePlanner(createSchemeRegistry(),
-                                          new ProxySelectorMockup(null));
+        HttpRoute route = routePlanner.determineRoute(target, request, null);
 
-        HttpHost target =
-            new HttpHost("www.test.invalid", 80, "http");
-        HttpRequest request =
-            new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
-
-        HttpRoute route = hrp.determineRoute(target, request, null);
+        Assert.assertEquals(target, route.getTargetHost());
+        Assert.assertEquals(1, route.getHopCount());
+        Assert.assertFalse(route.isSecure());
+        Mockito.verify(schemePortResolver, Mockito.never()).resolve(Mockito.<HttpHost>any());
+    }
 
-        Assert.assertEquals("wrong target", target, route.getTargetHost());
-        Assert.assertEquals("not direct", 1, route.getHopCount());
+    @Test
+    public void testDirectDefaultPort() throws Exception {
+        HttpHost target = new HttpHost("somehost", -1, "https");
+        Mockito.when(schemePortResolver.resolve(target)).thenReturn(443);
+        HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
+
+        HttpRoute route = routePlanner.determineRoute(target, request, null);
+
+        Assert.assertEquals(new HttpHost("somehost", 443, "https"), route.getTargetHost());
+        Assert.assertEquals(1, route.getHopCount());
+        Assert.assertTrue(route.isSecure());
     }
 
     @Test
@@ -97,21 +101,17 @@ public class TestProxySelRoutePlanner {
         proxies.add(new Proxy(Proxy.Type.HTTP, isa1));
         proxies.add(new Proxy(Proxy.Type.HTTP, isa2));
 
-        HttpRoutePlanner hrp =
-            new ProxySelectorRoutePlanner(createSchemeRegistry(),
-                                          new ProxySelectorMockup(proxies));
+        Mockito.when(proxySelector.select(new URI("http://somehost:80"))).thenReturn(proxies);
 
-        HttpHost target =
-            new HttpHost("www.test.invalid", 80, "http");
+        HttpHost target = new HttpHost("somehost", 80, "http");
         HttpRequest request =
             new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
 
-        HttpRoute route = hrp.determineRoute(target, request, null);
+        HttpRoute route = routePlanner.determineRoute(target, request, null);
 
-        Assert.assertEquals("wrong target", target, route.getTargetHost());
-        Assert.assertEquals("not via proxy", 2, route.getHopCount());
-        Assert.assertEquals("wrong proxy", isa1.getPort(),
-                     route.getProxyHost().getPort());
+        Assert.assertEquals(target, route.getTargetHost());
+        Assert.assertEquals(2, route.getHopCount());
+        Assert.assertEquals(isa1.getPort(), route.getProxyHost().getPort());
     }
 
 }

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/LocalServerTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/LocalServerTestBase.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/LocalServerTestBase.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/LocalServerTestBase.java Wed Nov 28 13:39:31 2012
@@ -46,6 +46,7 @@ public abstract class LocalServerTestBas
         if (localServer != null) {
             localServer.stop();
         }
+        localServer = null;
     }
 
     protected void startServer() throws Exception {

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/LocalTestServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/LocalTestServer.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/LocalTestServer.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/LocalTestServer.java Wed Nov 28 13:39:31 2012
@@ -235,7 +235,6 @@ public class LocalTestServer {
             ssock = new ServerSocket();
         }
 
-        ssock.setSoTimeout(timeout);
         ssock.setReuseAddress(true); // probably pointless for port '0'
         ssock.bind(TEST_SERVER_ADDR);
         servicedSocket = ssock;

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java Wed Nov 28 13:39:31 2012
@@ -35,6 +35,7 @@ import org.apache.http.params.HttpParams
 /**
  * {@link LayeredSchemeSocketFactory} mockup implementation.
  */
+@Deprecated
 public class SecureSocketFactoryMockup extends SocketFactoryMockup
     implements SchemeLayeredSocketFactory {
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java Wed Nov 28 13:39:31 2012
@@ -39,6 +39,7 @@ import org.apache.http.params.HttpParams
 /**
  * {@link SchemeSocketFactory} mockup implementation.
  */
+@Deprecated
 public class SocketFactoryMockup implements SchemeSocketFactory {
 
     /* A default instance of this mockup. */



Mime
View raw message