hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1603443 [1/3] - in /httpcomponents/httpclient/trunk: fluent-hc/src/test/java/org/apache/http/client/fluent/ httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ httpclient/src/test/java/org/apache/http/conn/ssl/ httpclient/src...
Date Wed, 18 Jun 2014 13:06:44 GMT
Author: olegk
Date: Wed Jun 18 13:06:43 2014
New Revision: 1603443

URL: http://svn.apache.org/r1603443
Log:
Migrated integration tests to HttpServer from HttpCore 4.4

Added:
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/SSLTestContexts.java   (with props)
    httpcomponents/httpclient/trunk/httpclient/src/test/resources/test.keystore
Removed:
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/IntegrationTestBase.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/LocalTestServer.java
    httpcomponents/httpclient/trunk/httpclient/src/test/resources/hc-test.keystore
Modified:
    httpcomponents/httpclient/trunk/fluent-hc/src/test/java/org/apache/http/client/fluent/TestFluent.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestStaleWhileRevalidationReleasesConnection.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestBasicConnectionManager.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFakeNTLM.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionReuse.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookieVirtualHost.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestMinimalClientRequestExecution.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/LocalServerTestBase.java

Modified: httpcomponents/httpclient/trunk/fluent-hc/src/test/java/org/apache/http/client/fluent/TestFluent.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/fluent-hc/src/test/java/org/apache/http/client/fluent/TestFluent.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/fluent-hc/src/test/java/org/apache/http/client/fluent/TestFluent.java (original)
+++ httpcomponents/httpclient/trunk/fluent-hc/src/test/java/org/apache/http/client/fluent/TestFluent.java Wed Jun 18 13:06:43 2014
@@ -28,12 +28,13 @@ package org.apache.http.client.fluent;
 
 import java.io.File;
 import java.io.IOException;
-import java.net.InetSocketAddress;
 import java.nio.charset.Charset;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.ClientProtocolException;
@@ -41,20 +42,20 @@ import org.apache.http.client.ResponseHa
 import org.apache.http.entity.ContentType;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.localserver.LocalServerTestBase;
-import org.apache.http.localserver.LocalTestServer;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.util.EntityUtils;
+import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
 public class TestFluent extends LocalServerTestBase {
 
-    @Before
+    @Before @Override
     public void setUp() throws Exception {
-        this.localServer = new LocalTestServer(null, null);
-        localServer.register("/", new HttpRequestHandler() {
+        super.setUp();
+        this.serverBootstrap.registerHandler("/", new HttpRequestHandler() {
 
             @Override
             public void handle(
@@ -65,7 +66,7 @@ public class TestFluent extends LocalSer
             }
 
         });
-        localServer.register("/echo", new HttpRequestHandler() {
+        this.serverBootstrap.registerHandler("/echo", new HttpRequestHandler() {
 
             @Override
             public void handle(
@@ -90,28 +91,35 @@ public class TestFluent extends LocalSer
             }
 
         });
-        startServer();
+    }
+
+    @After @Override
+    public void shutDown() throws Exception {
+        if (this.server != null) {
+            this.server.shutdown(100, TimeUnit.MILLISECONDS);
+            this.server = null;
+        }
     }
 
     @Test
     public void testGetRequest() throws Exception {
-        final InetSocketAddress serviceAddress = this.localServer.getServiceAddress();
-        final String baseURL = "http://localhost:" + serviceAddress.getPort();
+        final HttpHost target = start();
+        final String baseURL = "http://localhost:" + target.getPort();
         final String message = Request.Get(baseURL + "/").execute().returnContent().asString();
         Assert.assertEquals("All is well", message);
     }
 
     @Test(expected = ClientProtocolException.class)
     public void testGetRequestFailure() throws Exception {
-        final InetSocketAddress serviceAddress = this.localServer.getServiceAddress();
-        final String baseURL = "http://localhost:" + serviceAddress.getPort();
+        final HttpHost target = start();
+        final String baseURL = "http://localhost:" + target.getPort();
         Request.Get(baseURL + "/boom").execute().returnContent().asString();
     }
 
     @Test
     public void testPostRequest() throws Exception {
-        final InetSocketAddress serviceAddress = this.localServer.getServiceAddress();
-        final String baseURL = "http://localhost:" + serviceAddress.getPort();
+        final HttpHost target = start();
+        final String baseURL = "http://localhost:" + target.getPort();
         final String message1 = Request.Post(baseURL + "/echo")
                 .bodyString("what is up?", ContentType.TEXT_PLAIN)
                 .execute().returnContent().asString();
@@ -124,8 +132,8 @@ public class TestFluent extends LocalSer
 
     @Test
     public void testContentAsStringWithCharset() throws Exception {
-        final InetSocketAddress serviceAddress = this.localServer.getServiceAddress();
-        final String baseURL = "http://localhost:" + serviceAddress.getPort();
+        final HttpHost target = start();
+        final String baseURL = "http://localhost:" + target.getPort();
         final Content content = Request.Post(baseURL + "/echo").bodyByteArray("Ü".getBytes("utf-8")).execute()
                 .returnContent();
         Assert.assertEquals((byte)-61, content.asBytes()[0]);
@@ -135,8 +143,8 @@ public class TestFluent extends LocalSer
 
     @Test
     public void testConnectionRelease() throws Exception {
-        final InetSocketAddress serviceAddress = this.localServer.getServiceAddress();
-        final String baseURL = "http://localhost:" + serviceAddress.getPort();
+        final HttpHost target = start();
+        final String baseURL = "http://localhost:" + target.getPort();
         for (int i = 0; i < 20; i++) {
             Request.Get(baseURL + "/").execute().returnContent();
             Request.Get(baseURL + "/").execute().returnResponse();

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestStaleWhileRevalidationReleasesConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestStaleWhileRevalidationReleasesConnection.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestStaleWhileRevalidationReleasesConnection.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestStaleWhileRevalidationReleasesConnection.java Wed Jun 18 13:06:43 2014
@@ -45,10 +45,12 @@ import org.apache.http.client.cache.Cach
 import org.apache.http.client.cache.HttpCacheContext;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.config.SocketConfig;
 import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.impl.bootstrap.HttpServer;
+import org.apache.http.impl.bootstrap.ServerBootstrap;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.localserver.LocalTestServer;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
@@ -65,7 +67,7 @@ public class TestStaleWhileRevalidationR
 
     private static final EchoViaHeaderHandler cacheHandler = new EchoViaHeaderHandler();
 
-    protected LocalTestServer localServer;
+    protected HttpServer localServer;
     private int port;
     private CloseableHttpClient client;
     private final String url = "/static/dom";
@@ -74,12 +76,15 @@ public class TestStaleWhileRevalidationR
 
     @Before
     public void start() throws Exception  {
-        this.localServer = new LocalTestServer(null, null);
-        this.localServer.register(url +"*", new EchoViaHeaderHandler());
-        localServer.setTimeout(5000);
+        this.localServer = ServerBootstrap.bootstrap()
+                .setSocketConfig(SocketConfig.custom()
+                        .setSoTimeout(5000)
+                        .build())
+                .registerHandler(url + "*", new EchoViaHeaderHandler())
+                .create();
         this.localServer.start();
 
-        port = this.localServer.getServiceAddress().getPort();
+        port = this.localServer.getLocalPort();
 
         final CacheConfig cacheConfig = CacheConfig.custom()
                 .setMaxCacheEntries(100)

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java Wed Jun 18 13:06:43 2014
@@ -28,14 +28,12 @@
 package org.apache.http.conn.ssl;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.InetSocketAddress;
 import java.net.Socket;
-import java.net.URL;
-import java.security.KeyStore;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLException;
@@ -44,43 +42,31 @@ import javax.net.ssl.SSLSession;
 import javax.net.ssl.SSLSocket;
 
 import org.apache.http.HttpHost;
+import org.apache.http.impl.bootstrap.HttpServer;
+import org.apache.http.impl.bootstrap.ServerBootstrap;
 import org.apache.http.localserver.LocalServerTestBase;
-import org.apache.http.localserver.LocalTestServer;
+import org.apache.http.localserver.SSLTestContexts;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.HttpContext;
+import org.junit.After;
 import org.junit.Assert;
-import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
  * Unit tests for {@link SSLConnectionSocketFactory}.
  */
-public class TestSSLSocketFactory extends LocalServerTestBase {
+public class TestSSLSocketFactory {
 
-    private KeyStore keystore;
+    private HttpServer server;
 
-    @Before
-    public void setUp() throws Exception {
-        keystore  = KeyStore.getInstance("jks");
-        final ClassLoader cl = getClass().getClassLoader();
-        final URL url = cl.getResource("hc-test.keystore");
-        final InputStream instream = url.openStream();
-        try {
-            keystore.load(instream, "nopassword".toCharArray());
-        } finally {
-            instream.close();
+    @After
+    public void shutDown() throws Exception {
+        if (this.server != null) {
+            this.server.shutdown(10, TimeUnit.SECONDS);
         }
     }
 
-    @Override
-    protected HttpHost getServerHttp() {
-        final InetSocketAddress address = this.localServer.getServiceAddress();
-        return new HttpHost(
-                address.getHostName(),
-                address.getPort(),
-                "https");
-    }
-
     static class TestX509HostnameVerifier implements X509HostnameVerifier {
 
         private boolean fired = false;
@@ -111,91 +97,81 @@ public class TestSSLSocketFactory extend
 
     @Test
     public void testBasicSSL() throws Exception {
-        final SSLContext serverSSLContext = SSLContexts.custom()
-                .useProtocol("TLS")
-                .loadTrustMaterial(keystore)
-                .loadKeyMaterial(keystore, "nopassword".toCharArray())
-                .build();
-        final SSLContext clientSSLContext = SSLContexts.custom()
-                .useProtocol("TLS")
-                .loadTrustMaterial(keystore)
-                .build();
-
-        this.localServer = new LocalTestServer(serverSSLContext);
-        this.localServer.registerDefaultHandlers();
-        this.localServer.start();
+        this.server = ServerBootstrap.bootstrap()
+                .setServerInfo(LocalServerTestBase.ORIGIN)
+                .setSslContext(SSLTestContexts.createServerSSLContext())
+                .create();
+        this.server.start();
 
-        final HttpHost host = new HttpHost("localhost", 443, "https");
         final HttpContext context = new BasicHttpContext();
         final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
         final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
-                clientSSLContext, hostVerifier);
+                SSLTestContexts.createClientSSLContext(), hostVerifier);
         final Socket socket = socketFactory.createSocket(context);
-        final InetSocketAddress remoteAddress = this.localServer.getServiceAddress();
-        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
-        final SSLSession sslsession = sslSocket.getSession();
+        final InetSocketAddress remoteAddress = new InetSocketAddress(this.server.getInetAddress(), this.server.getLocalPort());
+        final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
+        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
+        try {
+            final SSLSession sslsession = sslSocket.getSession();
 
-        Assert.assertNotNull(sslsession);
-        Assert.assertTrue(hostVerifier.isFired());
+            Assert.assertNotNull(sslsession);
+            Assert.assertTrue(hostVerifier.isFired());
+        } finally {
+            sslSocket.close();
+        }
     }
 
     @Test
     public void testClientAuthSSL() throws Exception {
-        final SSLContext serverSSLContext = SSLContexts.custom()
-                .useProtocol("TLS")
-                .loadTrustMaterial(keystore)
-                .loadKeyMaterial(keystore, "nopassword".toCharArray())
-                .build();
-        final SSLContext clientSSLContext = SSLContexts.custom()
-                .useProtocol("TLS")
-                .loadTrustMaterial(keystore)
-                .loadKeyMaterial(keystore, "nopassword".toCharArray())
-                .build();
-
-        this.localServer = new LocalTestServer(serverSSLContext, true);
-        this.localServer.registerDefaultHandlers();
-        this.localServer.start();
+        this.server = ServerBootstrap.bootstrap()
+                .setServerInfo(LocalServerTestBase.ORIGIN)
+                .setSslContext(SSLTestContexts.createServerSSLContext())
+                .create();
+        this.server.start();
 
-        final HttpHost host = new HttpHost("localhost", 443, "https");
         final HttpContext context = new BasicHttpContext();
         final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
-        final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(clientSSLContext, hostVerifier);
+        final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
+                SSLTestContexts.createClientSSLContext(), hostVerifier);
         final Socket socket = socketFactory.createSocket(context);
-        final InetSocketAddress remoteAddress = this.localServer.getServiceAddress();
-        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
-        final SSLSession sslsession = sslSocket.getSession();
+        final InetSocketAddress remoteAddress = new InetSocketAddress(this.server.getInetAddress(), this.server.getLocalPort());
+        final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
+        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
+        try {
+            final SSLSession sslsession = sslSocket.getSession();
 
-        Assert.assertNotNull(sslsession);
-        Assert.assertTrue(hostVerifier.isFired());
+            Assert.assertNotNull(sslsession);
+            Assert.assertTrue(hostVerifier.isFired());
+        } finally {
+            sslSocket.close();
+        }
     }
 
+    @Ignore("There is no way to force client auth with HttpServer in 4.4a1")
     @Test(expected=IOException.class)
     public void testClientAuthSSLFailure() throws Exception {
-        final SSLContext serverSSLContext = SSLContexts.custom()
-                .useProtocol("TLS")
-                .loadTrustMaterial(keystore)
-                .loadKeyMaterial(keystore, "nopassword".toCharArray())
-                .build();
-        final SSLContext clientSSLContext = SSLContexts.custom()
-                .useProtocol("TLS")
-                .loadTrustMaterial(keystore)
-                .build();
-
-        this.localServer = new LocalTestServer(serverSSLContext, true);
-        this.localServer.registerDefaultHandlers();
-        this.localServer.start();
+        this.server = ServerBootstrap.bootstrap()
+                .setServerInfo(LocalServerTestBase.ORIGIN)
+                .setSslContext(SSLTestContexts.createServerSSLContext())
+                .create();
+        this.server.start();
 
-        final HttpHost host = new HttpHost("localhost", 443, "https");
         final HttpContext context = new BasicHttpContext();
         final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
-        final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(clientSSLContext, hostVerifier);
+        final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
+                SSLTestContexts.createClientSSLContext(), hostVerifier);
         final Socket socket = socketFactory.createSocket(context);
-        final InetSocketAddress remoteAddress = this.localServer.getServiceAddress();
-        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
-        final SSLSession sslsession = sslSocket.getSession();
+        final InetSocketAddress remoteAddress = new InetSocketAddress(this.server.getInetAddress(), this.server.getLocalPort());
+        final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
+        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
+        try {
+            final SSLSession sslsession = sslSocket.getSession();
 
-        Assert.assertNotNull(sslsession);
-        Assert.assertTrue(hostVerifier.isFired());
+            Assert.assertNotNull(sslsession);
+            Assert.assertTrue(hostVerifier.isFired());
+        } finally {
+            sslSocket.close();
+        }
     }
 
     @Test
@@ -213,47 +189,38 @@ public class TestSSLSocketFactory extend
 
         };
 
-        final SSLContext serverSSLContext = SSLContexts.custom()
-                .useProtocol("TLS")
-                .loadTrustMaterial(keystore)
-                .loadKeyMaterial(keystore, "nopassword".toCharArray())
-                .build();
-        final SSLContext clientSSLContext = SSLContexts.custom()
-                .useProtocol("TLS")
-                .loadTrustMaterial(keystore)
-                .loadKeyMaterial(keystore, "nopassword".toCharArray(), aliasStrategy)
-                .build();
-
-        this.localServer = new LocalTestServer(serverSSLContext, true);
-        this.localServer.registerDefaultHandlers();
-        this.localServer.start();
+        this.server = ServerBootstrap.bootstrap()
+                .setServerInfo(LocalServerTestBase.ORIGIN)
+                .setSslContext(SSLTestContexts.createServerSSLContext())
+                .create();
+        this.server.start();
 
-        final HttpHost host = new HttpHost("localhost", 443, "https");
         final HttpContext context = new BasicHttpContext();
         final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
-        final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(clientSSLContext, hostVerifier);
+        final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
+                SSLTestContexts.createClientSSLContext(), hostVerifier);
         final Socket socket = socketFactory.createSocket(context);
-        final InetSocketAddress remoteAddress = this.localServer.getServiceAddress();
-        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
-        final SSLSession sslsession = sslSocket.getSession();
+        final InetSocketAddress remoteAddress = new InetSocketAddress(this.server.getInetAddress(), this.server.getLocalPort());
+        final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
+        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
+        try {
+            final SSLSession sslsession = sslSocket.getSession();
 
-        Assert.assertNotNull(sslsession);
-        Assert.assertTrue(hostVerifier.isFired());
+            Assert.assertNotNull(sslsession);
+            Assert.assertTrue(hostVerifier.isFired());
+        } finally {
+            sslSocket.close();
+        }
     }
 
     @Test(expected=SSLHandshakeException.class)
     public void testSSLTrustVerification() throws Exception {
-        final SSLContext serverSSLContext = SSLContexts.custom()
-                .useProtocol("TLS")
-                .loadTrustMaterial(keystore)
-                .loadKeyMaterial(keystore, "nopassword".toCharArray())
-                .build();
-
-        this.localServer = new LocalTestServer(serverSSLContext);
-        this.localServer.registerDefaultHandlers();
-        this.localServer.start();
+        this.server = ServerBootstrap.bootstrap()
+                .setServerInfo(LocalServerTestBase.ORIGIN)
+                .setSslContext(SSLTestContexts.createServerSSLContext())
+                .create();
+        this.server.start();
 
-        final HttpHost host = new HttpHost("localhost", 443, "https");
         final HttpContext context = new BasicHttpContext();
         // Use default SSL context
         final SSLContext defaultsslcontext = SSLContexts.createDefault();
@@ -262,23 +229,20 @@ public class TestSSLSocketFactory extend
                 SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
 
         final Socket socket = socketFactory.createSocket(context);
-        final InetSocketAddress remoteAddress = this.localServer.getServiceAddress();
-        socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
+        final InetSocketAddress remoteAddress = new InetSocketAddress(this.server.getInetAddress(), this.server.getLocalPort());
+        final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
+        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
+        sslSocket.close();
     }
 
     @Test
     public void testSSLTrustVerificationOverride() throws Exception {
-        final SSLContext serverSSLContext = SSLContexts.custom()
-                .useProtocol("TLS")
-                .loadTrustMaterial(keystore)
-                .loadKeyMaterial(keystore, "nopassword".toCharArray())
-                .build();
-
-        this.localServer = new LocalTestServer(serverSSLContext);
-        this.localServer.registerDefaultHandlers();
-        this.localServer.start();
+        this.server = ServerBootstrap.bootstrap()
+                .setServerInfo(LocalServerTestBase.ORIGIN)
+                .setSslContext(SSLTestContexts.createServerSSLContext())
+                .create();
+        this.server.start();
 
-        final HttpHost host = new HttpHost("localhost", 443, "https");
         final HttpContext context = new BasicHttpContext();
 
         final TrustStrategy trustStrategy = new TrustStrategy() {
@@ -298,8 +262,10 @@ public class TestSSLSocketFactory extend
                 SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
 
         final Socket socket = socketFactory.createSocket(context);
-        final InetSocketAddress remoteAddress = this.localServer.getServiceAddress();
-        socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
+        final InetSocketAddress remoteAddress = new InetSocketAddress(this.server.getInetAddress(), this.server.getLocalPort());
+        final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
+        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
+        sslSocket.close();
     }
 
     @Test

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java Wed Jun 18 13:06:43 2014
@@ -27,7 +27,6 @@
 package org.apache.http.impl.client;
 
 import java.io.IOException;
-import java.net.InetSocketAddress;
 import java.util.LinkedList;
 import java.util.Queue;
 import java.util.concurrent.CancellationException;
@@ -49,7 +48,8 @@ import org.apache.http.client.ResponseHa
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.concurrent.FutureCallback;
-import org.apache.http.localserver.LocalTestServer;
+import org.apache.http.impl.bootstrap.HttpServer;
+import org.apache.http.impl.bootstrap.ServerBootstrap;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.junit.After;
@@ -60,7 +60,7 @@ import org.junit.Test;
 @SuppressWarnings("boxing") // test code
 public class TestFutureRequestExecutionService {
 
-    private LocalTestServer localServer;
+    private HttpServer localServer;
     private String uri;
     private FutureRequestExecutionService httpAsyncClientWithFuture;
 
@@ -68,8 +68,8 @@ public class TestFutureRequestExecutionS
 
     @Before
     public void before() throws Exception {
-            this.localServer = new LocalTestServer(null, null);
-            this.localServer.register("/wait", new HttpRequestHandler() {
+            this.localServer = ServerBootstrap.bootstrap()
+                    .registerHandler("/wait", new HttpRequestHandler() {
 
                 @Override
                 public void handle(
@@ -84,10 +84,10 @@ public class TestFutureRequestExecutionS
                     }
                     response.setStatusCode(200);
                 }
-            });
+            }).create();
+
             this.localServer.start();
-            final InetSocketAddress address = localServer.getServiceAddress();
-            uri = "http://" + address.getHostName() + ":" + address.getPort() + "/wait";
+            uri = "http://localhost:" + this.localServer.getLocalPort() + "/wait";
             final HttpClient httpClient = HttpClientBuilder.create()
                     .setMaxConnPerRoute(5)
                     .build();

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java Wed Jun 18 13:06:43 2014
@@ -49,15 +49,15 @@ import org.apache.http.conn.ConnectionRe
 import org.apache.http.conn.HttpClientConnectionManager;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.protocol.UriHttpRequestHandlerMapper;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 
@@ -65,22 +65,16 @@ import org.mockito.Mockito;
  *  Tests for Abort handling.
  */
 @SuppressWarnings("static-access") // test code
-public class TestAbortHandling extends IntegrationTestBase {
-
-    @Before
-    public void setUp() throws Exception {
-        startServer();
-    }
+public class TestAbortHandling extends LocalServerTestBase {
 
     @Test
     public void testAbortRetry_HTTPCLIENT_1120() throws Exception {
-        final int port = this.localServer.getServiceAddress().getPort();
         final CountDownLatch wait = new CountDownLatch(1);
 
-        this.localServer.register("*", new HttpRequestHandler(){
+        this.serverBootstrap.registerHandler("*", new HttpRequestHandler() {
             @Override
             public void handle(final HttpRequest request, final HttpResponse response,
-                    final HttpContext context) throws HttpException, IOException {
+                               final HttpContext context) throws HttpException, IOException {
                 try {
                     wait.countDown(); // trigger abort
                     Thread.sleep(2000); // allow time for abort to happen
@@ -90,10 +84,11 @@ public class TestAbortHandling extends I
                 } catch (final Exception e) {
                     response.setStatusCode(HttpStatus.SC_REQUEST_TIMEOUT);
                 }
-            }});
+            }
+        });
 
-        final String s = "http://localhost:" + port + "/path";
-        final HttpGet httpget = new HttpGet(s);
+        final HttpHost target = start();
+        final HttpGet httpget = new HttpGet("/");
 
         final Thread t = new Thread() {
              @Override
@@ -108,11 +103,9 @@ public class TestAbortHandling extends I
 
         t.start();
 
-        this.httpclient = HttpClients.createDefault();
-
         final HttpClientContext context = HttpClientContext.create();
         try {
-            this.httpclient.execute(getServerHttp(), httpget, context);
+            this.httpclient.execute(target, httpget, context);
         } catch (final IllegalStateException e) {
         } catch (final IOException e) {
         }
@@ -128,16 +121,17 @@ public class TestAbortHandling extends I
         final ConMan conMan = new ConMan(connLatch, awaitLatch);
         final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
         final CountDownLatch getLatch = new CountDownLatch(1);
-        final CloseableHttpClient client = HttpClients.custom().setConnectionManager(conMan).build();
+        this.clientBuilder.setConnectionManager(conMan);
         final HttpContext context = new BasicHttpContext();
         final HttpGet httpget = new HttpGet("http://www.example.com/a");
-        this.httpclient = client;
+
+        start();
 
         new Thread(new Runnable() {
             @Override
             public void run() {
                 try {
-                    client.execute(httpget, context);
+                    httpclient.execute(httpget, context);
                 } catch(final Throwable t) {
                     throwableRef.set(t);
                 } finally {
@@ -163,22 +157,21 @@ public class TestAbortHandling extends I
      */
     @Test
     public void testAbortAfterAllocateBeforeRequest() throws Exception {
-        this.localServer.register("*", new BasicService());
+        this.serverBootstrap.registerHandler("*", new BasicService());
 
         final CountDownLatch releaseLatch = new CountDownLatch(1);
-        final PoolingHttpClientConnectionManager conMan = new PoolingHttpClientConnectionManager();
         final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
         final CountDownLatch getLatch = new CountDownLatch(1);
-        final CloseableHttpClient client = HttpClients.custom().setConnectionManager(conMan).build();
         final HttpContext context = new BasicHttpContext();
         final HttpGet httpget = new CustomGet("a", releaseLatch);
-        this.httpclient = client;
+
+        final HttpHost target = start();
 
         new Thread(new Runnable() {
             @Override
             public void run() {
                 try {
-                    client.execute(getServerHttp(), httpget, context);
+                    httpclient.execute(target, httpget, context);
                 } catch(final Throwable t) {
                     throwableRef.set(t);
                 } finally {
@@ -204,16 +197,15 @@ public class TestAbortHandling extends I
      */
     @Test
     public void testAbortBeforeExecute() throws Exception {
-        this.localServer.register("*", new BasicService());
+        this.serverBootstrap.registerHandler("*", new BasicService());
 
-        final PoolingHttpClientConnectionManager conMan = new PoolingHttpClientConnectionManager();
         final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
         final CountDownLatch getLatch = new CountDownLatch(1);
         final CountDownLatch startLatch = new CountDownLatch(1);
-        final CloseableHttpClient client = HttpClients.custom().setConnectionManager(conMan).build();
         final HttpContext context = new BasicHttpContext();
         final HttpGet httpget = new HttpGet("a");
-        this.httpclient = client;
+
+        final HttpHost target = start();
 
         new Thread(new Runnable() {
             @Override
@@ -226,7 +218,7 @@ public class TestAbortHandling extends I
                     } catch(final InterruptedException interrupted) {
                         throw new RuntimeException("Never started!", interrupted);
                     }
-                    client.execute(getServerHttp(), httpget, context);
+                    httpclient.execute(target, httpget, context);
                 } catch(final Throwable t) {
                     throwableRef.set(t);
                 } finally {
@@ -250,25 +242,27 @@ public class TestAbortHandling extends I
      */
     @Test
     public void testAbortAfterRedirectedRoute() throws Exception {
-        final int port = this.localServer.getServiceAddress().getPort();
-        this.localServer.register("*", new BasicRedirectService(port));
+        final UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper();
+        this.serverBootstrap.setHandlerMapper(reqistry);
 
         final CountDownLatch connLatch = new CountDownLatch(1);
         final CountDownLatch awaitLatch = new CountDownLatch(1);
         final ConnMan4 conMan = new ConnMan4(connLatch, awaitLatch);
         final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
         final CountDownLatch getLatch = new CountDownLatch(1);
-        final CloseableHttpClient client = HttpClients.custom().setConnectionManager(conMan).build();
+        this.clientBuilder.setConnectionManager(conMan);
         final HttpContext context = new BasicHttpContext();
         final HttpGet httpget = new HttpGet("a");
-        this.httpclient = client;
+
+        final HttpHost target = start();
+        reqistry.register("*", new BasicRedirectService(target.getPort()));
 
         new Thread(new Runnable() {
             @Override
             public void run() {
                 try {
-                    final HttpHost host = new HttpHost("127.0.0.1", port);
-                    client.execute(host, httpget, context);
+                    final HttpHost host = new HttpHost("127.0.0.1", target.getPort());
+                    httpclient.execute(host, httpget, context);
                 } catch(final Throwable t) {
                     throwableRef.set(t);
                 } finally {

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestBasicConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestBasicConnectionManager.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestBasicConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestBasicConnectionManager.java Wed Jun 18 13:06:43 2014
@@ -29,41 +29,19 @@ package org.apache.http.impl.client.inte
 import org.apache.http.HttpHost;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.HttpClients;
 import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
-import org.apache.http.localserver.LocalTestServer;
+import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.util.EntityUtils;
-import org.junit.After;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
-import java.io.IOException;
-import java.net.InetSocketAddress;
-
-public class TestBasicConnectionManager extends IntegrationTestBase {
-
-    @SuppressWarnings("resource") // BasicHttpClientConnectionManager
-    @Before
-    public void setUp() throws Exception {
-        this.localServer = new LocalTestServer(null, null);
-        this.localServer.registerDefaultHandlers();
-        this.localServer.start();
-
-        this.httpclient = HttpClients.custom()
-                .setConnectionManager(new BasicHttpClientConnectionManager())
-                .build();
-    }
-
-    @After
-    public void cleanup() throws IOException {
-        this.httpclient.close();
-    }
+public class TestBasicConnectionManager extends LocalServerTestBase {
 
     @Test
     public void testBasics() throws Exception {
-        final InetSocketAddress address = localServer.getServiceAddress();
-        final HttpHost target = new HttpHost(address.getHostName(), address.getPort());
+        this.clientBuilder.setConnectionManager(new BasicHttpClientConnectionManager());
+
+        final HttpHost target = start();
         final HttpGet get = new HttpGet("/random/1024");
         final CloseableHttpResponse response = this.httpclient.execute(target, get);
         try {
@@ -76,8 +54,9 @@ public class TestBasicConnectionManager 
 
     @Test(expected=IllegalStateException.class)
     public void testConnectionStillInUse() throws Exception {
-        final InetSocketAddress address = localServer.getServiceAddress();
-        final HttpHost target = new HttpHost(address.getHostName(), address.getPort());
+        this.clientBuilder.setConnectionManager(new BasicHttpClientConnectionManager());
+
+        final HttpHost target = start();
         final HttpGet get1 = new HttpGet("/random/1024");
         this.httpclient.execute(target, get1);
         final HttpGet get2 = new HttpGet("/random/1024");

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java Wed Jun 18 13:06:43 2014
@@ -56,10 +56,9 @@ import org.apache.http.entity.StringEnti
 import org.apache.http.impl.auth.BasicScheme;
 import org.apache.http.impl.client.BasicAuthCache;
 import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.HttpClients;
 import org.apache.http.impl.client.TargetAuthenticationStrategy;
 import org.apache.http.localserver.BasicAuthTokenExtractor;
-import org.apache.http.localserver.LocalTestServer;
+import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.localserver.RequestBasicAuth;
 import org.apache.http.localserver.ResponseBasicUnauthorized;
 import org.apache.http.message.BasicHeader;
@@ -82,19 +81,19 @@ import org.junit.Test;
 /**
  * Unit tests for automatic client authentication.
  */
-public class TestClientAuthentication extends IntegrationTestBase {
+public class TestClientAuthentication extends LocalServerTestBase {
 
-    @Before
+    @Before @Override
     public void setUp() throws Exception {
+        super.setUp();
         final HttpProcessor httpproc = HttpProcessorBuilder.create()
             .add(new ResponseDate())
-            .add(new ResponseServer())
+            .add(new ResponseServer(LocalServerTestBase.ORIGIN))
             .add(new ResponseContent())
             .add(new ResponseConnControl())
             .add(new RequestBasicAuth())
             .add(new ResponseBasicUnauthorized()).build();
-        this.localServer = new LocalTestServer(httpproc, null);
-        startServer();
+        this.serverBootstrap.setHttpProcessor(httpproc);
     }
 
     static class AuthHandler implements HttpRequestHandler {
@@ -172,14 +171,16 @@ public class TestClientAuthentication ex
 
     @Test
     public void testBasicAuthenticationNoCreds() throws Exception {
-        this.localServer.register("*", new AuthHandler());
+        this.serverBootstrap.registerHandler("*", new AuthHandler());
 
-        final TestCredentialsProvider credsProvider = new TestCredentialsProvider(null);
-        this.httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
+        final HttpHost target = start();
 
+        final HttpClientContext context = HttpClientContext.create();
+        final TestCredentialsProvider credsProvider = new TestCredentialsProvider(null);
+        context.setCredentialsProvider(credsProvider);
         final HttpGet httpget = new HttpGet("/");
 
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), httpget);
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         final HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity);
@@ -191,16 +192,17 @@ public class TestClientAuthentication ex
 
     @Test
     public void testBasicAuthenticationFailure() throws Exception {
-        this.localServer.register("*", new AuthHandler());
+        this.serverBootstrap.registerHandler("*", new AuthHandler());
 
+        final HttpHost target = start();
+
+        final HttpClientContext context = HttpClientContext.create();
         final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
                 new UsernamePasswordCredentials("test", "all-wrong"));
-
-        this.httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
-
+        context.setCredentialsProvider(credsProvider);
         final HttpGet httpget = new HttpGet("/");
 
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), httpget);
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         final HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity);
@@ -212,16 +214,17 @@ public class TestClientAuthentication ex
 
     @Test
     public void testBasicAuthenticationSuccess() throws Exception {
-        this.localServer.register("*", new AuthHandler());
+        this.serverBootstrap.registerHandler("*", new AuthHandler());
 
+        final HttpGet httpget = new HttpGet("/");
+        final HttpClientContext context = HttpClientContext.create();
         final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
                 new UsernamePasswordCredentials("test", "test"));
+        context.setCredentialsProvider(credsProvider);
 
-        this.httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
-
-        final HttpGet httpget = new HttpGet("/");
+        final HttpHost target = start();
 
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), httpget);
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         final HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity);
@@ -235,30 +238,32 @@ public class TestClientAuthentication ex
     public void testBasicAuthenticationSuccessOnNonRepeatablePutExpectContinue() throws Exception {
         final HttpProcessor httpproc = HttpProcessorBuilder.create()
             .add(new ResponseDate())
-            .add(new ResponseServer(LocalTestServer.ORIGIN))
+            .add(new ResponseServer(LocalServerTestBase.ORIGIN))
             .add(new ResponseContent())
             .add(new ResponseConnControl())
             .add(new RequestBasicAuth())
             .add(new ResponseBasicUnauthorized()).build();
-        this.localServer = new LocalTestServer(
-                httpproc, null, null, new AuthExpectationVerifier(), null, false);
-        this.localServer.register("*", new AuthHandler());
-        this.localServer.start();
+        this.serverBootstrap.setHttpProcessor(httpproc)
+            .setExpectationVerifier(new AuthExpectationVerifier())
+            .registerHandler("*", new AuthHandler());
 
-        final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
-                new UsernamePasswordCredentials("test", "test"));
-
-        this.httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
+        final HttpHost target = start();
 
-        final RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(true).build();
+        final RequestConfig config = RequestConfig.custom()
+                .setExpectContinueEnabled(true)
+                .build();
         final HttpPut httpput = new HttpPut("/");
         httpput.setConfig(config);
         httpput.setEntity(new InputStreamEntity(
                 new ByteArrayInputStream(
                         new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
                         -1));
+        final HttpClientContext context = HttpClientContext.create();
+        final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
+                new UsernamePasswordCredentials("test", "test"));
+        context.setCredentialsProvider(credsProvider);
 
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), httpput);
+        final HttpResponse response = this.httpclient.execute(target, httpput, context);
         final HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity);
@@ -266,12 +271,9 @@ public class TestClientAuthentication ex
 
     @Test(expected=ClientProtocolException.class)
     public void testBasicAuthenticationFailureOnNonRepeatablePutDontExpectContinue() throws Exception {
-        this.localServer.register("*", new AuthHandler());
-
-        final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
-                new UsernamePasswordCredentials("test", "boom"));
+        this.serverBootstrap.registerHandler("*", new AuthHandler());
 
-        this.httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
+        final HttpHost target = start();
 
         final RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(true).build();
         final HttpPut httpput = new HttpPut("/");
@@ -281,8 +283,13 @@ public class TestClientAuthentication ex
                         new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
                         -1));
 
+        final HttpClientContext context = HttpClientContext.create();
+        final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
+                new UsernamePasswordCredentials("test", "boom"));
+        context.setCredentialsProvider(credsProvider);
+
         try {
-            this.httpclient.execute(getServerHttp(), httpput);
+            this.httpclient.execute(target, httpput, context);
             Assert.fail("ClientProtocolException should have been thrown");
         } catch (final ClientProtocolException ex) {
             final Throwable cause = ex.getCause();
@@ -294,17 +301,19 @@ public class TestClientAuthentication ex
 
     @Test
     public void testBasicAuthenticationSuccessOnRepeatablePost() throws Exception {
-        this.localServer.register("*", new AuthHandler());
+        this.serverBootstrap.registerHandler("*", new AuthHandler());
 
-        final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
-                new UsernamePasswordCredentials("test", "test"));
-
-        this.httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
+        final HttpHost target = start();
 
         final HttpPost httppost = new HttpPost("/");
         httppost.setEntity(new StringEntity("some important stuff", Consts.ASCII));
 
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), httppost);
+        final HttpClientContext context = HttpClientContext.create();
+        final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
+                new UsernamePasswordCredentials("test", "test"));
+        context.setCredentialsProvider(credsProvider);
+
+        final HttpResponse response = this.httpclient.execute(target, httppost, context);
         final HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity);
@@ -316,19 +325,22 @@ public class TestClientAuthentication ex
 
     @Test(expected=ClientProtocolException.class)
     public void testBasicAuthenticationFailureOnNonRepeatablePost() throws Exception {
-        this.localServer.register("*", new AuthHandler());
+        this.serverBootstrap.registerHandler("*", new AuthHandler());
 
-        final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
-                new UsernamePasswordCredentials("test", "test"));
-
-        this.httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
+        final HttpHost target = start();
 
         final HttpPost httppost = new HttpPost("/");
         httppost.setEntity(new InputStreamEntity(
                 new ByteArrayInputStream(
                         new byte[] { 0,1,2,3,4,5,6,7,8,9 }), -1));
+
+        final HttpClientContext context = HttpClientContext.create();
+        final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
+                new UsernamePasswordCredentials("test", "test"));
+        context.setCredentialsProvider(credsProvider);
+
         try {
-            this.httpclient.execute(getServerHttp(), httppost);
+            this.httpclient.execute(target, httppost, context);
             Assert.fail("ClientProtocolException should have been thrown");
         } catch (final ClientProtocolException ex) {
             final Throwable cause = ex.getCause();
@@ -367,30 +379,28 @@ public class TestClientAuthentication ex
 
     @Test
     public void testBasicAuthenticationCredentialsCaching() throws Exception {
-        this.localServer.register("*", new AuthHandler());
+        this.serverBootstrap.registerHandler("*", new AuthHandler());
 
-        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
-        credsProvider.setCredentials(AuthScope.ANY,
-                new UsernamePasswordCredentials("test", "test"));
         final TestTargetAuthenticationStrategy authStrategy = new TestTargetAuthenticationStrategy();
+        this.clientBuilder.setTargetAuthenticationStrategy(authStrategy);
 
-        this.httpclient = HttpClients.custom()
-            .setDefaultCredentialsProvider(credsProvider)
-            .setTargetAuthenticationStrategy(authStrategy)
-            .build();
+        final HttpHost target = start();
 
         final HttpClientContext context = HttpClientContext.create();
+        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
+        credsProvider.setCredentials(AuthScope.ANY,
+                new UsernamePasswordCredentials("test", "test"));
+        context.setCredentialsProvider(credsProvider);
 
-        final HttpHost targethost = getServerHttp();
         final HttpGet httpget = new HttpGet("/");
 
-        final HttpResponse response1 = this.httpclient.execute(targethost, httpget, context);
+        final HttpResponse response1 = this.httpclient.execute(target, httpget, context);
         final HttpEntity entity1 = response1.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response1.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity1);
         EntityUtils.consume(entity1);
 
-        final HttpResponse response2 = this.httpclient.execute(targethost, httpget, context);
+        final HttpResponse response2 = this.httpclient.execute(target, httpget, context);
         final HttpEntity entity2 = response1.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response2.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity2);
@@ -429,28 +439,30 @@ public class TestClientAuthentication ex
 
     @Test
     public void testAuthenticationCredentialsCachingReauthenticationOnDifferentRealm() throws Exception {
-        this.localServer.register("/this", new RealmAuthHandler("this realm", "test:this"));
-        this.localServer.register("/that", new RealmAuthHandler("that realm", "test:that"));
+        this.serverBootstrap.registerHandler("/this", new RealmAuthHandler("this realm", "test:this"));
+        this.serverBootstrap.registerHandler("/that", new RealmAuthHandler("that realm", "test:that"));
+
+        this.server = this.serverBootstrap.create();
+        this.server.start();
 
-        final HttpHost targethost = getServerHttp();
+        final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), this.scheme.name());
 
         final TestTargetAuthenticationStrategy authStrategy = new TestTargetAuthenticationStrategy();
         final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
-        credsProvider.setCredentials(new AuthScope(targethost, "this realm", null),
+        credsProvider.setCredentials(new AuthScope(target, "this realm", null),
                 new UsernamePasswordCredentials("test", "this"));
-        credsProvider.setCredentials(new AuthScope(targethost, "that realm", null),
+        credsProvider.setCredentials(new AuthScope(target, "that realm", null),
                 new UsernamePasswordCredentials("test", "that"));
 
-        this.httpclient = HttpClients.custom()
-                .setDefaultCredentialsProvider(credsProvider)
-                .setTargetAuthenticationStrategy(authStrategy)
-                .build();
+        this.clientBuilder.setTargetAuthenticationStrategy(authStrategy);
+        this.httpclient = this.clientBuilder.build();
 
         final HttpClientContext context = HttpClientContext.create();
+        context.setCredentialsProvider(credsProvider);
 
         final HttpGet httpget1 = new HttpGet("/this");
 
-        final HttpResponse response1 = this.httpclient.execute(targethost, httpget1, context);
+        final HttpResponse response1 = this.httpclient.execute(target, httpget1, context);
         final HttpEntity entity1 = response1.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response1.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity1);
@@ -458,7 +470,7 @@ public class TestClientAuthentication ex
 
         final HttpGet httpget2 = new HttpGet("/this");
 
-        final HttpResponse response2 = this.httpclient.execute(targethost, httpget2, context);
+        final HttpResponse response2 = this.httpclient.execute(target, httpget2, context);
         final HttpEntity entity2 = response1.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response2.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity2);
@@ -466,7 +478,7 @@ public class TestClientAuthentication ex
 
         final HttpGet httpget3 = new HttpGet("/that");
 
-        final HttpResponse response3 = this.httpclient.execute(targethost, httpget3, context);
+        final HttpResponse response3 = this.httpclient.execute(target, httpget3, context);
         final HttpEntity entity3 = response1.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response3.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity3);
@@ -477,14 +489,13 @@ public class TestClientAuthentication ex
 
     @Test
     public void testAuthenticationUserinfoInRequestSuccess() throws Exception {
-        this.localServer.register("*", new AuthHandler());
+        this.serverBootstrap.registerHandler("*", new AuthHandler());
 
-        final HttpHost target = getServerHttp();
+        final HttpHost target = start();
         final HttpGet httpget = new HttpGet("http://test:test@" +  target.toHostString() + "/");
 
-        this.httpclient = HttpClients.custom().build();
-
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), httpget);
+        final HttpClientContext context = HttpClientContext.create();
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         final HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity);
@@ -493,14 +504,13 @@ public class TestClientAuthentication ex
 
     @Test
     public void testAuthenticationUserinfoInRequestFailure() throws Exception {
-        this.localServer.register("*", new AuthHandler());
+        this.serverBootstrap.registerHandler("*", new AuthHandler());
 
-        final HttpHost target = getServerHttp();
+        final HttpHost target = start();
         final HttpGet httpget = new HttpGet("http://test:all-wrong@" +  target.toHostString() + "/");
 
-        this.httpclient = HttpClients.custom().build();
-
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), httpget);
+        final HttpClientContext context = HttpClientContext.create();
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         final HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity);
@@ -530,15 +540,15 @@ public class TestClientAuthentication ex
 
     @Test
     public void testAuthenticationUserinfoInRedirectSuccess() throws Exception {
-        this.localServer.register("*", new AuthHandler());
-        this.localServer.register("/thatway", new RedirectHandler());
+        this.serverBootstrap.registerHandler("*", new AuthHandler());
+        this.serverBootstrap.registerHandler("/thatway", new RedirectHandler());
 
-        final HttpHost target = getServerHttp();
-        final HttpGet httpget = new HttpGet("http://" +  target.toHostString() + "/thatway");
+        final HttpHost target = start();
 
-        this.httpclient = HttpClients.custom().build();
+        final HttpGet httpget = new HttpGet("http://" +  target.toHostString() + "/thatway");
+        final HttpClientContext context = HttpClientContext.create();
 
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), httpget);
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         final HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity);
@@ -579,26 +589,21 @@ public class TestClientAuthentication ex
     @Test
     public void testPreemptiveAuthentication() throws Exception {
         final CountingAuthHandler requestHandler = new CountingAuthHandler();
-        this.localServer.register("*", requestHandler);
-
-        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
-        credsProvider.setCredentials(AuthScope.ANY,
-                new UsernamePasswordCredentials("test", "test"));
-
-        this.httpclient = HttpClients.custom()
-            .setDefaultCredentialsProvider(credsProvider)
-            .build();
+        this.serverBootstrap.registerHandler("*", requestHandler);
 
-        final HttpHost targethost = getServerHttp();
+        final HttpHost target = start();
 
         final HttpClientContext context = HttpClientContext.create();
         final AuthCache authCache = new BasicAuthCache();
-        authCache.put(targethost, new BasicScheme());
+        authCache.put(target, new BasicScheme());
         context.setAuthCache(authCache);
+        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
+        credsProvider.setCredentials(AuthScope.ANY,
+                new UsernamePasswordCredentials("test", "test"));
+        context.setCredentialsProvider(credsProvider);
 
         final HttpGet httpget = new HttpGet("/");
-
-        final HttpResponse response1 = this.httpclient.execute(targethost, httpget, context);
+        final HttpResponse response1 = this.httpclient.execute(target, httpget, context);
         final HttpEntity entity1 = response1.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response1.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity1);
@@ -610,26 +615,21 @@ public class TestClientAuthentication ex
     @Test
     public void testPreemptiveAuthenticationFailure() throws Exception {
         final CountingAuthHandler requestHandler = new CountingAuthHandler();
-        this.localServer.register("*", requestHandler);
-
-        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
-        credsProvider.setCredentials(AuthScope.ANY,
-                new UsernamePasswordCredentials("test", "stuff"));
+        this.serverBootstrap.registerHandler("*", requestHandler);
 
-        this.httpclient = HttpClients.custom()
-            .setDefaultCredentialsProvider(credsProvider)
-            .build();
-
-        final HttpHost targethost = getServerHttp();
+        final HttpHost target = start();
 
         final HttpClientContext context = HttpClientContext.create();
         final AuthCache authCache = new BasicAuthCache();
-        authCache.put(targethost, new BasicScheme());
+        authCache.put(target, new BasicScheme());
         context.setAuthCache(authCache);
+        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
+        credsProvider.setCredentials(AuthScope.ANY,
+                new UsernamePasswordCredentials("test", "stuff"));
+        context.setCredentialsProvider(credsProvider);
 
         final HttpGet httpget = new HttpGet("/");
-
-        final HttpResponse response1 = this.httpclient.execute(targethost, httpget, context);
+        final HttpResponse response1 = this.httpclient.execute(target, httpget, context);
         final HttpEntity entity1 = response1.getEntity();
         Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response1.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity1);
@@ -659,14 +659,16 @@ public class TestClientAuthentication ex
 
     @Test
     public void testAuthenticationTargetAsProxy() throws Exception {
-        this.localServer.register("*", new ProxyAuthHandler());
+        this.serverBootstrap.registerHandler("*", new ProxyAuthHandler());
 
+        final HttpHost target = start();
+
+        final HttpClientContext context = HttpClientContext.create();
         final TestCredentialsProvider credsProvider = new TestCredentialsProvider(null);
-        this.httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
+        context.setCredentialsProvider(credsProvider);
 
         final HttpGet httpget = new HttpGet("/");
-
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), httpget);
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         final HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED,
                 response.getStatusLine().getStatusCode());
@@ -695,24 +697,20 @@ public class TestClientAuthentication ex
 
     @Test
     public void testConnectionCloseAfterAuthenticationSuccess() throws Exception {
-        this.localServer.register("*", new ClosingAuthHandler());
+        this.serverBootstrap.registerHandler("*", new ClosingAuthHandler());
 
+        final HttpHost target = start();
+
+        final HttpClientContext context = HttpClientContext.create();
         final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
         credsProvider.setCredentials(AuthScope.ANY,
                 new UsernamePasswordCredentials("test", "test"));
-
-        this.httpclient = HttpClients.custom()
-                .setDefaultCredentialsProvider(credsProvider)
-                .build();
-
-        final HttpClientContext context = HttpClientContext.create();
-
-        final HttpHost targethost = getServerHttp();
+        context.setCredentialsProvider(credsProvider);
 
         for (int i = 0; i < 2; i++) {
             final HttpGet httpget = new HttpGet("/");
 
-            final HttpResponse response = this.httpclient.execute(targethost, httpget, context);
+            final HttpResponse response = this.httpclient.execute(target, httpget, context);
             EntityUtils.consume(response.getEntity());
             Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFakeNTLM.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFakeNTLM.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFakeNTLM.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFakeNTLM.java Wed Jun 18 13:06:43 2014
@@ -26,6 +26,8 @@
  */
 package org.apache.http.impl.client.integration;
 
+import java.io.IOException;
+
 import org.apache.http.HttpException;
 import org.apache.http.HttpHeaders;
 import org.apache.http.HttpHost;
@@ -39,26 +41,18 @@ import org.apache.http.client.methods.Ht
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.impl.client.HttpClients;
-import org.apache.http.localserver.LocalTestServer;
+import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.message.BasicStatusLine;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
-import java.io.IOException;
-
 /**
  * Unit tests for some of the NTLM auth functionality..
  */
-public class TestClientAuthenticationFakeNTLM extends IntegrationTestBase {
-
-    @Before
-    public void setUp() throws Exception {
-        this.localServer = new LocalTestServer(null, null);
-    }
+public class TestClientAuthenticationFakeNTLM extends LocalServerTestBase {
 
     static class NtlmResponseHandler implements HttpRequestHandler {
 
@@ -78,8 +72,9 @@ public class TestClientAuthenticationFak
 
     @Test
     public void testNTLMAuthenticationFailure() throws Exception {
-        this.localServer.register("*", new NtlmResponseHandler());
-        this.localServer.start();
+        this.serverBootstrap.registerHandler("*", new NtlmResponseHandler());
+
+        final HttpHost target = start();
 
         final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
         credsProvider.setCredentials(AuthScope.ANY,
@@ -90,11 +85,9 @@ public class TestClientAuthenticationFak
                 .build();
 
         final HttpContext context = HttpClientContext.create();
-
-        final HttpHost targethost = getServerHttp();
         final HttpGet httpget = new HttpGet("/");
 
-        final HttpResponse response = this.httpclient.execute(targethost, httpget, context);
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
         Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
                 response.getStatusLine().getStatusCode());
@@ -128,10 +121,10 @@ public class TestClientAuthenticationFak
 
     @Test
     public void testNTLMv1Type2Message() throws Exception {
-        this.localServer.register("*", new NtlmType2MessageResponseHandler("TlRMTVNTUAACAA" +
+        this.serverBootstrap.registerHandler("*", new NtlmType2MessageResponseHandler("TlRMTVNTUAACAA" +
                 "AADAAMADgAAAAzggLiASNFZ4mrze8AAAAAAAAAAAAAAAAAAAAABgBwFwAAAA9T" +
                 "AGUAcgB2AGUAcgA="));
-        this.localServer.start();
+        final HttpHost target = start();
 
         final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
         credsProvider.setCredentials(AuthScope.ANY,
@@ -142,11 +135,9 @@ public class TestClientAuthenticationFak
                 .build();
 
         final HttpContext context = HttpClientContext.create();
-
-        final HttpHost targethost = getServerHttp();
         final HttpGet httpget = new HttpGet("/");
 
-        final HttpResponse response = this.httpclient.execute(targethost, httpget, context);
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
         Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
                 response.getStatusLine().getStatusCode());
@@ -154,10 +145,10 @@ public class TestClientAuthenticationFak
 
     @Test
     public void testNTLMv2Type2Message() throws Exception {
-        this.localServer.register("*", new NtlmType2MessageResponseHandler("TlRMTVNTUAACAA" +
+        this.serverBootstrap.registerHandler("*", new NtlmType2MessageResponseHandler("TlRMTVNTUAACAA" +
                 "AADAAMADgAAAAzgoriASNFZ4mrze8AAAAAAAAAACQAJABEAAAABgBwFwAAAA9T" +
                 "AGUAcgB2AGUAcgACAAwARABvAG0AYQBpAG4AAQAMAFMAZQByAHYAZQByAAAAAAA="));
-        this.localServer.start();
+        final HttpHost target = start();
 
         final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
         credsProvider.setCredentials(AuthScope.ANY,
@@ -168,11 +159,9 @@ public class TestClientAuthenticationFak
                 .build();
 
         final HttpContext context = HttpClientContext.create();
-
-        final HttpHost targethost = getServerHttp();
         final HttpGet httpget = new HttpGet("/");
 
-        final HttpResponse response = this.httpclient.execute(targethost, httpget, context);
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
         Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
                 response.getStatusLine().getStatusCode());
@@ -202,25 +191,20 @@ public class TestClientAuthenticationFak
 
     @Test
     public void testNTLMType2MessageOnlyAuthenticationFailure() throws Exception {
-        this.localServer.register("*", new NtlmType2MessageOnlyResponseHandler("TlRMTVNTUAACAA" +
+        this.serverBootstrap.registerHandler("*", new NtlmType2MessageOnlyResponseHandler("TlRMTVNTUAACAA" +
                 "AADAAMADgAAAAzggLiASNFZ4mrze8AAAAAAAAAAAAAAAAAAAAABgBwFwAAAA9T" +
                 "AGUAcgB2AGUAcgA="));
-        this.localServer.start();
 
+        final HttpHost target = start();
+
+        final HttpClientContext context = HttpClientContext.create();
         final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
         credsProvider.setCredentials(AuthScope.ANY,
                 new NTCredentials("test", "test", null, null));
-
-        this.httpclient = HttpClients.custom()
-                .setDefaultCredentialsProvider(credsProvider)
-                .build();
-
-        final HttpContext context = HttpClientContext.create();
-
-        final HttpHost targethost = getServerHttp();
+        context.setCredentialsProvider(credsProvider);
         final HttpGet httpget = new HttpGet("/");
 
-        final HttpResponse response = this.httpclient.execute(targethost, httpget, context);
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
         Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
                 response.getStatusLine().getStatusCode());
@@ -228,25 +212,20 @@ public class TestClientAuthenticationFak
 
     @Test
     public void testNTLMType2NonUnicodeMessageOnlyAuthenticationFailure() throws Exception {
-        this.localServer.register("*", new NtlmType2MessageOnlyResponseHandler("TlRMTVNTUAACAA" +
+        this.serverBootstrap.registerHandler("*", new NtlmType2MessageOnlyResponseHandler("TlRMTVNTUAACAA" +
                 "AABgAGADgAAAAyggLiASNFZ4mrze8AAAAAAAAAAAAAAAAAAAAABgBwFwAAAA9T" +
                 "ZXJ2ZXI="));
-        this.localServer.start();
 
+        final HttpHost target = start();
+
+        final HttpClientContext context = HttpClientContext.create();
         final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
         credsProvider.setCredentials(AuthScope.ANY,
                 new NTCredentials("test", "test", null, null));
-
-        this.httpclient = HttpClients.custom()
-                .setDefaultCredentialsProvider(credsProvider)
-                .build();
-
-        final HttpContext context = HttpClientContext.create();
-
-        final HttpHost targethost = getServerHttp();
+        context.setCredentialsProvider(credsProvider);
         final HttpGet httpget = new HttpGet("/");
 
-        final HttpResponse response = this.httpclient.execute(targethost, httpget, context);
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
         Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
                 response.getStatusLine().getStatusCode());

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java Wed Jun 18 13:06:43 2014
@@ -31,6 +31,7 @@ import java.io.IOException;
 import org.apache.http.Consts;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseInterceptor;
@@ -41,9 +42,9 @@ import org.apache.http.auth.Credentials;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.CredentialsProvider;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.localserver.LocalTestServer;
+import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.localserver.RequestBasicAuth;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpProcessor;
@@ -58,7 +59,7 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-public class TestClientAuthenticationFallBack extends IntegrationTestBase {
+public class TestClientAuthenticationFallBack extends LocalServerTestBase {
 
     public class ResponseBasicUnauthorized implements HttpResponseInterceptor {
 
@@ -74,17 +75,17 @@ public class TestClientAuthenticationFal
 
     }
 
-    @Before
+    @Before @Override
     public void setUp() throws Exception {
+        super.setUp();
         final HttpProcessor httpproc = HttpProcessorBuilder.create()
             .add(new ResponseDate())
-            .add(new ResponseServer(LocalTestServer.ORIGIN))
+            .add(new ResponseServer(LocalServerTestBase.ORIGIN))
             .add(new ResponseContent())
             .add(new ResponseConnControl())
             .add(new RequestBasicAuth())
             .add(new ResponseBasicUnauthorized()).build();
-        this.localServer = new LocalTestServer(httpproc, null);
-        startServer();
+        this.serverBootstrap.setHttpProcessor(httpproc);
     }
 
     static class AuthHandler implements HttpRequestHandler {
@@ -138,16 +139,17 @@ public class TestClientAuthenticationFal
 
     @Test
     public void testBasicAuthenticationSuccess() throws Exception {
-        this.localServer.register("*", new AuthHandler());
+        this.serverBootstrap.registerHandler("*", new AuthHandler());
 
+        final HttpHost target = start();
+
+        final HttpClientContext context = HttpClientContext.create();
         final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
                 new UsernamePasswordCredentials("test", "test"));
-
-        this.httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
-
+        context.setCredentialsProvider(credsProvider);
         final HttpGet httpget = new HttpGet("/");
 
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), httpget);
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         final HttpEntity entity = response.getEntity();
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
         Assert.assertNotNull(entity);

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java Wed Jun 18 13:06:43 2014
@@ -33,6 +33,7 @@ import java.util.concurrent.atomic.Atomi
 import org.apache.http.Consts;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseInterceptor;
@@ -52,9 +53,8 @@ import org.apache.http.config.RegistryBu
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.auth.BasicScheme;
 import org.apache.http.impl.auth.BasicSchemeFactory;
-import org.apache.http.impl.client.HttpClients;
 import org.apache.http.impl.client.TargetAuthenticationStrategy;
-import org.apache.http.localserver.LocalTestServer;
+import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.localserver.RequestBasicAuth;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpProcessor;
@@ -69,7 +69,7 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-public class TestClientReauthentication extends IntegrationTestBase {
+public class TestClientReauthentication extends LocalServerTestBase {
 
     public class ResponseBasicUnauthorized implements HttpResponseInterceptor {
 
@@ -84,18 +84,17 @@ public class TestClientReauthentication 
 
     }
 
-    @Before
+    @Before @Override
     public void setUp() throws Exception {
+        super.setUp();
         final HttpProcessor httpproc = HttpProcessorBuilder.create()
             .add(new ResponseDate())
-            .add(new ResponseServer(LocalTestServer.ORIGIN))
+            .add(new ResponseServer(LocalServerTestBase.ORIGIN))
             .add(new ResponseContent())
             .add(new ResponseConnControl())
             .add(new RequestBasicAuth())
             .add(new ResponseBasicUnauthorized()).build();
-
-        this.localServer = new LocalTestServer(httpproc, null);
-        startServer();
+        this.serverBootstrap.setHttpProcessor(httpproc);
     }
 
     static class AuthHandler implements HttpRequestHandler {
@@ -156,7 +155,7 @@ public class TestClientReauthentication 
 
     @Test
     public void testBasicAuthenticationSuccess() throws Exception {
-        this.localServer.register("*", new AuthHandler());
+        this.serverBootstrap.registerHandler("*", new AuthHandler());
 
         final BasicSchemeFactory myBasicAuthSchemeFactory = new BasicSchemeFactory() {
 
@@ -192,17 +191,19 @@ public class TestClientReauthentication 
         final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
             .register("MyBasic", myBasicAuthSchemeFactory)
             .build();
-        this.httpclient = HttpClients.custom()
+        this.httpclient = this.clientBuilder
             .setDefaultAuthSchemeRegistry(authSchemeRegistry)
             .setTargetAuthenticationStrategy(myAuthStrategy)
             .setDefaultCredentialsProvider(credsProvider)
             .build();
 
+        final HttpHost target = start();
+
         final HttpClientContext context = HttpClientContext.create();
         for (int i = 0; i < 10; i++) {
             final HttpGet httpget = new HttpGet("/");
             httpget.setConfig(config);
-            final HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+            final HttpResponse response = this.httpclient.execute(target, httpget, context);
             final HttpEntity entity = response.getEntity();
             Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
             Assert.assertNotNull(entity);



Mime
View raw message