hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [02/17] httpcomponents-client git commit: Moved classes and renamed packages (no functional changes)
Date Sat, 02 Sep 2017 15:28:02 GMT
http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestExecRuntimeImpl.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestExecRuntimeImpl.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestExecRuntimeImpl.java
deleted file mode 100644
index 63e51a8..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestExecRuntimeImpl.java
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * ====================================================================
- * 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.hc.client5.http.impl.sync;
-
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import org.apache.hc.client5.http.CancellableAware;
-import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.config.RequestConfig;
-import org.apache.hc.client5.http.io.ConnectionEndpoint;
-import org.apache.hc.client5.http.io.HttpClientConnectionManager;
-import org.apache.hc.client5.http.io.LeaseRequest;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.core5.concurrent.Cancellable;
-import org.apache.hc.core5.http.ConnectionRequestTimeoutException;
-import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
-import org.apache.hc.core5.io.ShutdownType;
-import org.apache.hc.core5.util.TimeValue;
-import org.apache.logging.log4j.Logger;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-@SuppressWarnings({"static-access"}) // test code
-public class TestExecRuntimeImpl {
-
-    @Mock
-    private Logger log;
-    @Mock
-    private HttpClientConnectionManager mgr;
-    @Mock
-    private LeaseRequest leaseRequest;
-    @Mock
-    private HttpRequestExecutor requestExecutor;
-    @Mock
-    private CancellableAware cancellableAware;
-    @Mock
-    private ConnectionEndpoint connectionEndpoint;
-
-    private HttpRoute route;
-    private ExecRuntimeImpl execRuntime;
-
-    @Before
-    public void setup() {
-        MockitoAnnotations.initMocks(this);
-        route = new HttpRoute(new HttpHost("host", 80));
-        execRuntime = new ExecRuntimeImpl(log, mgr, requestExecutor, cancellableAware);
-    }
-
-    @Test
-    public void testAcquireEndpoint() throws Exception {
-        final HttpClientContext context = HttpClientContext.create();
-        final RequestConfig config = RequestConfig.custom()
-                .setConnectTimeout(123, TimeUnit.MILLISECONDS)
-                .setSocketTimeout(234, TimeUnit.MILLISECONDS)
-                .setConnectionRequestTimeout(345, TimeUnit.MILLISECONDS)
-                .build();
-        context.setRequestConfig(config);
-        final HttpRoute route = new HttpRoute(new HttpHost("host", 80));
-
-        Mockito.when(mgr.lease(route, null)).thenReturn(leaseRequest);
-        Mockito.when(leaseRequest.get(
-                Mockito.anyLong(), Mockito.<TimeUnit>any())).thenReturn(connectionEndpoint);
-
-        execRuntime.acquireConnection(route, null, context);
-
-        Assert.assertTrue(execRuntime.isConnectionAcquired());
-        Assert.assertSame(connectionEndpoint, execRuntime.ensureValid());
-        Assert.assertFalse(execRuntime.isConnected());
-        Assert.assertFalse(execRuntime.isConnectionReusable());
-
-        Mockito.verify(leaseRequest).get(345, TimeUnit.MILLISECONDS);
-        Mockito.verify(cancellableAware, Mockito.times(1)).setCancellable(leaseRequest);
-        Mockito.verify(cancellableAware, Mockito.times(1)).setCancellable(execRuntime);
-        Mockito.verify(cancellableAware, Mockito.times(2)).setCancellable(Mockito.<Cancellable>any());
-    }
-
-    @Test(expected = IllegalStateException.class)
-    public void testAcquireEndpointAlreadyAcquired() throws Exception {
-        final HttpClientContext context = HttpClientContext.create();
-
-        Mockito.when(mgr.lease(route, null)).thenReturn(leaseRequest);
-        Mockito.when(leaseRequest.get(
-                Mockito.anyLong(), Mockito.<TimeUnit>any())).thenReturn(connectionEndpoint);
-
-        execRuntime.acquireConnection(route, null, context);
-
-        Assert.assertTrue(execRuntime.isConnectionAcquired());
-        Assert.assertSame(connectionEndpoint, execRuntime.ensureValid());
-
-        execRuntime.acquireConnection(route, null, context);
-    }
-
-    @Test(expected = ConnectionRequestTimeoutException.class)
-    public void testAcquireEndpointLeaseRequestTimeout() throws Exception {
-        final HttpClientContext context = HttpClientContext.create();
-
-        Mockito.when(mgr.lease(route, null)).thenReturn(leaseRequest);
-        Mockito.when(leaseRequest.get(
-                Mockito.anyLong(), Mockito.<TimeUnit>any())).thenThrow(new TimeoutException());
-
-        execRuntime.acquireConnection(route, null, context);
-    }
-
-    @Test(expected = RequestFailedException.class)
-    public void testAcquireEndpointLeaseRequestFailure() throws Exception {
-        final HttpClientContext context = HttpClientContext.create();
-
-        Mockito.when(mgr.lease(route, null)).thenReturn(leaseRequest);
-        Mockito.when(leaseRequest.get(
-                Mockito.anyLong(), Mockito.<TimeUnit>any())).thenThrow(new ExecutionException(new IllegalStateException()));
-
-        execRuntime.acquireConnection(route, null, context);
-    }
-
-    @Test
-    public void testAbortEndpoint() throws Exception {
-        final HttpClientContext context = HttpClientContext.create();
-        Mockito.when(mgr.lease(route, null)).thenReturn(leaseRequest);
-        Mockito.when(leaseRequest.get(
-                Mockito.anyLong(), Mockito.<TimeUnit>any())).thenReturn(connectionEndpoint);
-
-        execRuntime.acquireConnection(new HttpRoute(new HttpHost("host", 80)), null, context);
-        Assert.assertTrue(execRuntime.isConnectionAcquired());
-        execRuntime.discardConnection();
-
-        Assert.assertFalse(execRuntime.isConnectionAcquired());
-
-        Mockito.verify(connectionEndpoint).shutdown(ShutdownType.IMMEDIATE);
-        Mockito.verify(mgr).release(connectionEndpoint, null, TimeValue.ZERO_MILLISECONDS);
-
-        execRuntime.discardConnection();
-
-        Mockito.verify(connectionEndpoint, Mockito.times(1)).shutdown(ShutdownType.IMMEDIATE);
-        Mockito.verify(mgr, Mockito.times(1)).release(
-                Mockito.<ConnectionEndpoint>any(),
-                Mockito.any(),
-                Mockito.<TimeValue>any());
-    }
-
-    @Test
-    public void testCancell() throws Exception {
-        final HttpClientContext context = HttpClientContext.create();
-
-        Mockito.when(mgr.lease(route, null)).thenReturn(leaseRequest);
-        Mockito.when(leaseRequest.get(
-                Mockito.anyLong(), Mockito.<TimeUnit>any())).thenReturn(connectionEndpoint);
-
-        execRuntime.acquireConnection(route, null, context);
-        Assert.assertTrue(execRuntime.isConnectionAcquired());
-
-        Assert.assertTrue(execRuntime.cancel());
-
-        Assert.assertFalse(execRuntime.isConnectionAcquired());
-
-        Mockito.verify(connectionEndpoint).shutdown(ShutdownType.IMMEDIATE);
-        Mockito.verify(mgr).release(connectionEndpoint, null, TimeValue.ZERO_MILLISECONDS);
-
-        Assert.assertFalse(execRuntime.cancel());
-
-        Mockito.verify(connectionEndpoint, Mockito.times(1)).shutdown(ShutdownType.IMMEDIATE);
-        Mockito.verify(mgr, Mockito.times(1)).release(
-                Mockito.<ConnectionEndpoint>any(),
-                Mockito.any(),
-                Mockito.<TimeValue>any());
-    }
-
-    @Test
-    public void testReleaseEndpointReusable() throws Exception {
-        final HttpClientContext context = HttpClientContext.create();
-
-        Mockito.when(mgr.lease(route, null)).thenReturn(leaseRequest);
-        Mockito.when(leaseRequest.get(
-                Mockito.anyLong(), Mockito.<TimeUnit>any())).thenReturn(connectionEndpoint);
-
-        execRuntime.acquireConnection(route, null, context);
-        Assert.assertTrue(execRuntime.isConnectionAcquired());
-
-        execRuntime.setConnectionState("some state");
-        execRuntime.setConnectionValidFor(TimeValue.ofMillis(100000));
-        execRuntime.markConnectionReusable();
-
-        execRuntime.releaseConnection();
-
-        Assert.assertFalse(execRuntime.isConnectionAcquired());
-
-        Mockito.verify(connectionEndpoint, Mockito.never()).close();
-        Mockito.verify(mgr).release(connectionEndpoint, "some state", TimeValue.ofMillis(100000));
-
-        execRuntime.releaseConnection();
-
-        Mockito.verify(mgr, Mockito.times(1)).release(
-                Mockito.<ConnectionEndpoint>any(),
-                Mockito.any(),
-                Mockito.<TimeValue>any());
-    }
-
-    @Test
-    public void testReleaseEndpointNonReusable() throws Exception {
-        final HttpClientContext context = HttpClientContext.create();
-
-        Mockito.when(mgr.lease(route, null)).thenReturn(leaseRequest);
-        Mockito.when(leaseRequest.get(
-                Mockito.anyLong(), Mockito.<TimeUnit>any())).thenReturn(connectionEndpoint);
-
-        execRuntime.acquireConnection(route, null, context);
-        Assert.assertTrue(execRuntime.isConnectionAcquired());
-
-        execRuntime.setConnectionState("some state");
-        execRuntime.setConnectionValidFor(TimeValue.ofMillis(100000));
-        execRuntime.markConnectionNonReusable();
-
-        execRuntime.releaseConnection();
-
-        Assert.assertFalse(execRuntime.isConnectionAcquired());
-
-        Mockito.verify(connectionEndpoint, Mockito.times(1)).close();
-        Mockito.verify(mgr).release(connectionEndpoint, null, TimeValue.ZERO_MILLISECONDS);
-
-        execRuntime.releaseConnection();
-
-        Mockito.verify(mgr, Mockito.times(1)).release(
-                Mockito.<ConnectionEndpoint>any(),
-                Mockito.any(),
-                Mockito.<TimeValue>any());
-    }
-
-    @Test
-    public void testConnectEndpoint() throws Exception {
-        final HttpClientContext context = HttpClientContext.create();
-        final RequestConfig config = RequestConfig.custom()
-                .setConnectTimeout(123, TimeUnit.MILLISECONDS)
-                .setSocketTimeout(234, TimeUnit.MILLISECONDS)
-                .setConnectionRequestTimeout(345, TimeUnit.MILLISECONDS)
-                .build();
-        context.setRequestConfig(config);
-
-        Mockito.when(mgr.lease(route, null)).thenReturn(leaseRequest);
-        Mockito.when(leaseRequest.get(
-                Mockito.anyLong(), Mockito.<TimeUnit>any())).thenReturn(connectionEndpoint);
-
-        execRuntime.acquireConnection(route, null, context);
-        Assert.assertTrue(execRuntime.isConnectionAcquired());
-
-        Mockito.when(connectionEndpoint.isConnected()).thenReturn(false);
-        Assert.assertFalse(execRuntime.isConnected());
-
-        execRuntime.connect(context);
-
-        Mockito.verify(mgr).connect(connectionEndpoint, TimeValue.ofMillis(123), context);
-        Mockito.verify(connectionEndpoint).setSocketTimeout(234);
-    }
-
-    @Test
-    public void testDisonnectEndpoint() throws Exception {
-        final HttpClientContext context = HttpClientContext.create();
-
-        Mockito.when(mgr.lease(route, null)).thenReturn(leaseRequest);
-        Mockito.when(leaseRequest.get(
-                Mockito.anyLong(), Mockito.<TimeUnit>any())).thenReturn(connectionEndpoint);
-
-        execRuntime.acquireConnection(route, null, context);
-        Assert.assertTrue(execRuntime.isConnectionAcquired());
-
-        Mockito.when(connectionEndpoint.isConnected()).thenReturn(true);
-        Assert.assertTrue(execRuntime.isConnected());
-
-        execRuntime.connect(context);
-
-        Mockito.verify(mgr, Mockito.never()).connect(
-                Mockito.same(connectionEndpoint), Mockito.<TimeValue>any(), Mockito.<HttpClientContext>any());
-
-        execRuntime.disconnect();
-
-        Mockito.verify(connectionEndpoint).close();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestFutureRequestExecutionService.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestFutureRequestExecutionService.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestFutureRequestExecutionService.java
deleted file mode 100644
index 24cdffe..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestFutureRequestExecutionService.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * ====================================================================
- * 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.hc.client5.http.impl.sync;
-
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.Queue;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
-import org.apache.hc.client5.http.io.HttpClientConnectionManager;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.sync.methods.HttpGet;
-import org.apache.hc.core5.concurrent.FutureCallback;
-import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.ClassicHttpResponse;
-import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
-import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
-import org.apache.hc.core5.http.io.HttpClientResponseHandler;
-import org.apache.hc.core5.http.io.HttpRequestHandler;
-import org.apache.hc.core5.http.protocol.HttpContext;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-@SuppressWarnings("boxing") // test code
-public class TestFutureRequestExecutionService {
-
-    private HttpServer localServer;
-    private String uri;
-    private FutureRequestExecutionService httpAsyncClientWithFuture;
-
-    private final AtomicBoolean blocked = new AtomicBoolean(false);
-
-    @Before
-    public void before() throws Exception {
-        this.localServer = ServerBootstrap.bootstrap()
-                .register("/wait", new HttpRequestHandler() {
-
-            @Override
-            public void handle(
-                    final ClassicHttpRequest request,
-                    final ClassicHttpResponse response,
-                    final HttpContext context) throws HttpException, IOException {
-                try {
-                    while(blocked.get()) {
-                        Thread.sleep(10);
-                    }
-                } catch (final InterruptedException e) {
-                    throw new IllegalStateException(e);
-                }
-                response.setCode(200);
-            }
-        }).create();
-
-        this.localServer.start();
-        uri = "http://localhost:" + this.localServer.getLocalPort() + "/wait";
-        final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
-                .setMaxConnPerRoute(5)
-                .build();
-        final CloseableHttpClient httpClient = HttpClientBuilder.create()
-                .setConnectionManager(cm)
-                .build();
-        final ExecutorService executorService = Executors.newFixedThreadPool(5);
-        httpAsyncClientWithFuture = new FutureRequestExecutionService(httpClient, executorService);
-    }
-
-    @After
-    public void after() throws Exception {
-        blocked.set(false); // any remaining requests should unblock
-        this.localServer.stop();
-        httpAsyncClientWithFuture.close();
-    }
-
-    @Test
-    public void shouldExecuteSingleCall() throws InterruptedException, ExecutionException {
-        final HttpRequestFutureTask<Boolean> task = httpAsyncClientWithFuture.execute(
-            new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler());
-        Assert.assertTrue("request should have returned OK", task.get().booleanValue());
-    }
-
-    @Test(expected=CancellationException.class)
-    public void shouldCancel() throws InterruptedException, ExecutionException {
-        final HttpRequestFutureTask<Boolean> task = httpAsyncClientWithFuture.execute(
-            new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler());
-        task.cancel(true);
-        task.get();
-    }
-
-    @Test(expected=TimeoutException.class)
-    public void shouldTimeout() throws InterruptedException, ExecutionException, TimeoutException {
-        blocked.set(true);
-        final HttpRequestFutureTask<Boolean> task = httpAsyncClientWithFuture.execute(
-            new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler());
-        task.get(10, TimeUnit.MILLISECONDS);
-    }
-
-    @Test
-    public void shouldExecuteMultipleCalls() throws Exception {
-        final int reqNo = 100;
-        final Queue<Future<Boolean>> tasks = new LinkedList<>();
-        for(int i = 0; i < reqNo; i++) {
-            final Future<Boolean> task = httpAsyncClientWithFuture.execute(
-                    new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler());
-            tasks.add(task);
-        }
-        for (final Future<Boolean> task : tasks) {
-            final Boolean b = task.get();
-            Assert.assertNotNull(b);
-            Assert.assertTrue("request should have returned OK", b.booleanValue());
-        }
-    }
-
-    @Test
-    public void shouldExecuteMultipleCallsAndCallback() throws Exception {
-        final int reqNo = 100;
-        final Queue<Future<Boolean>> tasks = new LinkedList<>();
-        final CountDownLatch latch = new CountDownLatch(reqNo);
-        for(int i = 0; i < reqNo; i++) {
-            final Future<Boolean> task = httpAsyncClientWithFuture.execute(
-                    new HttpGet(uri), HttpClientContext.create(),
-                    new OkidokiHandler(), new CountingCallback(latch));
-            tasks.add(task);
-        }
-        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
-        for (final Future<Boolean> task : tasks) {
-            final Boolean b = task.get();
-            Assert.assertNotNull(b);
-            Assert.assertTrue("request should have returned OK", b.booleanValue());
-        }
-    }
-
-    private final class CountingCallback implements FutureCallback<Boolean> {
-
-        private final CountDownLatch latch;
-
-        CountingCallback(final CountDownLatch latch) {
-            super();
-            this.latch = latch;
-        }
-
-        @Override
-        public void failed(final Exception ex) {
-            latch.countDown();
-        }
-
-        @Override
-        public void completed(final Boolean result) {
-            latch.countDown();
-        }
-
-        @Override
-        public void cancelled() {
-            latch.countDown();
-        }
-    }
-
-
-    private final class OkidokiHandler implements HttpClientResponseHandler<Boolean> {
-        @Override
-        public Boolean handleResponse(
-                final ClassicHttpResponse response) throws IOException {
-            return response.getCode() == 200;
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestInternalHttpClient.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestInternalHttpClient.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestInternalHttpClient.java
deleted file mode 100644
index 2b1a878..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestInternalHttpClient.java
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * ====================================================================
- * 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.hc.client5.http.impl.sync;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.Arrays;
-
-import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.auth.AuthSchemeProvider;
-import org.apache.hc.client5.http.auth.CredentialsProvider;
-import org.apache.hc.client5.http.config.RequestConfig;
-import org.apache.hc.client5.http.cookie.CookieSpecProvider;
-import org.apache.hc.client5.http.cookie.CookieStore;
-import org.apache.hc.client5.http.io.HttpClientConnectionManager;
-import org.apache.hc.client5.http.protocol.ClientProtocolException;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.routing.HttpRoutePlanner;
-import org.apache.hc.client5.http.sync.ExecChain;
-import org.apache.hc.client5.http.sync.ExecChainHandler;
-import org.apache.hc.client5.http.sync.methods.HttpGet;
-import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.config.Lookup;
-import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-/**
- *  Simple tests for {@link InternalHttpClient}.
- */
-@SuppressWarnings({"static-access"}) // test code
-public class TestInternalHttpClient {
-
-    @Mock
-    private HttpClientConnectionManager connManager;
-    @Mock
-    private HttpRequestExecutor requestExecutor;
-    @Mock
-    private ExecChainHandler execChain;
-    @Mock
-    private HttpRoutePlanner routePlanner;
-    @Mock
-    private Lookup<CookieSpecProvider> cookieSpecRegistry;
-    @Mock
-    private Lookup<AuthSchemeProvider> authSchemeRegistry;
-    @Mock
-    private CookieStore cookieStore;
-    @Mock
-    private CredentialsProvider credentialsProvider;
-    @Mock
-    private RequestConfig defaultConfig;
-    @Mock
-    private Closeable closeable1;
-    @Mock
-    private Closeable closeable2;
-
-    private InternalHttpClient client;
-
-    @SuppressWarnings("unchecked")
-    @Before
-    public void setup() throws Exception {
-        MockitoAnnotations.initMocks(this);
-        client = new InternalHttpClient(connManager, requestExecutor, new ExecChainElement(execChain, null), routePlanner,
-                cookieSpecRegistry, authSchemeRegistry, cookieStore, credentialsProvider,
-                defaultConfig, Arrays.asList(closeable1, closeable2));
-
-    }
-
-    @Test
-    public void testExecute() throws Exception {
-        final HttpGet httpget = new HttpGet("http://somehost/stuff");
-        final HttpRoute route = new HttpRoute(new HttpHost("somehost", 80));
-
-        Mockito.when(routePlanner.determineRoute(
-                Mockito.eq(new HttpHost("somehost")),
-                Mockito.<HttpClientContext>any())).thenReturn(route);
-
-        client.execute(httpget);
-
-        Mockito.verify(execChain).execute(
-                Mockito.<ClassicHttpRequest>any(),
-                Mockito.<ExecChain.Scope>any(),
-                Mockito.<ExecChain>any());
-    }
-
-    @Test(expected=ClientProtocolException.class)
-    public void testExecuteHttpException() throws Exception {
-        final HttpGet httpget = new HttpGet("http://somehost/stuff");
-        final HttpRoute route = new HttpRoute(new HttpHost("somehost", 80));
-
-        Mockito.when(routePlanner.determineRoute(
-                Mockito.eq(new HttpHost("somehost")),
-                Mockito.<HttpClientContext>any())).thenReturn(route);
-        Mockito.when(execChain.execute(
-                Mockito.<ClassicHttpRequest>any(),
-                Mockito.<ExecChain.Scope>any(),
-                Mockito.<ExecChain>any())).thenThrow(new HttpException());
-
-        client.execute(httpget);
-    }
-
-    @Test
-    public void testExecuteDefaultContext() throws Exception {
-        final HttpGet httpget = new HttpGet("http://somehost/stuff");
-        final HttpRoute route = new HttpRoute(new HttpHost("somehost", 80));
-
-        Mockito.when(routePlanner.determineRoute(
-                Mockito.eq(new HttpHost("somehost")),
-                Mockito.<HttpClientContext>any())).thenReturn(route);
-
-        final HttpClientContext context = HttpClientContext.create();
-        client.execute(httpget, context);
-
-        Assert.assertSame(cookieSpecRegistry, context.getCookieSpecRegistry());
-        Assert.assertSame(authSchemeRegistry, context.getAuthSchemeRegistry());
-        Assert.assertSame(cookieStore, context.getCookieStore());
-        Assert.assertSame(credentialsProvider, context.getCredentialsProvider());
-        Assert.assertSame(defaultConfig, context.getRequestConfig());
-    }
-
-    @Test
-    public void testExecuteRequestConfig() throws Exception {
-        final HttpGet httpget = new HttpGet("http://somehost/stuff");
-        final HttpRoute route = new HttpRoute(new HttpHost("somehost", 80));
-
-        Mockito.when(routePlanner.determineRoute(
-                Mockito.eq(new HttpHost("somehost")),
-                Mockito.<HttpClientContext>any())).thenReturn(route);
-
-        final RequestConfig config = RequestConfig.custom().build();
-        httpget.setConfig(config);
-        final HttpClientContext context = HttpClientContext.create();
-        client.execute(httpget, context);
-
-        Assert.assertSame(config, context.getRequestConfig());
-    }
-
-    @SuppressWarnings("unchecked")
-    @Test
-    public void testExecuteLocalContext() throws Exception {
-        final HttpGet httpget = new HttpGet("http://somehost/stuff");
-        final HttpRoute route = new HttpRoute(new HttpHost("somehost", 80));
-
-        Mockito.when(routePlanner.determineRoute(
-                Mockito.eq(new HttpHost("somehost")),
-                Mockito.<HttpClientContext>any())).thenReturn(route);
-
-        final HttpClientContext context = HttpClientContext.create();
-
-        final Lookup<CookieSpecProvider> localCookieSpecRegistry = Mockito.mock(Lookup.class);
-        final Lookup<AuthSchemeProvider> localAuthSchemeRegistry = Mockito.mock(Lookup.class);
-        final CookieStore localCookieStore = Mockito.mock(CookieStore.class);
-        final CredentialsProvider localCredentialsProvider = Mockito.mock(CredentialsProvider.class);
-        final RequestConfig localConfig = RequestConfig.custom().build();
-
-        context.setCookieSpecRegistry(localCookieSpecRegistry);
-        context.setAuthSchemeRegistry(localAuthSchemeRegistry);
-        context.setCookieStore(localCookieStore);
-        context.setCredentialsProvider(localCredentialsProvider);
-        context.setRequestConfig(localConfig);
-
-        client.execute(httpget, context);
-
-        Assert.assertSame(localCookieSpecRegistry, context.getCookieSpecRegistry());
-        Assert.assertSame(localAuthSchemeRegistry, context.getAuthSchemeRegistry());
-        Assert.assertSame(localCookieStore, context.getCookieStore());
-        Assert.assertSame(localCredentialsProvider, context.getCredentialsProvider());
-        Assert.assertSame(localConfig, context.getRequestConfig());
-    }
-
-    @Test
-    public void testClientClose() throws Exception {
-        client.close();
-
-        Mockito.verify(closeable1).close();
-        Mockito.verify(closeable2).close();
-    }
-
-    @Test
-    public void testClientCloseIOException() throws Exception {
-        Mockito.doThrow(new IOException()).when(closeable1).close();
-
-        client.close();
-
-        Mockito.verify(closeable1).close();
-        Mockito.verify(closeable2).close();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestMainClientExec.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestMainClientExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestMainClientExec.java
deleted file mode 100644
index a59e559..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestMainClientExec.java
+++ /dev/null
@@ -1,348 +0,0 @@
-/*
- * ====================================================================
- * 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.hc.client5.http.impl.sync;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InterruptedIOException;
-
-import org.apache.hc.client5.http.ConnectionKeepAliveStrategy;
-import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.entity.EntityBuilder;
-import org.apache.hc.client5.http.impl.ConnectionShutdownException;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.protocol.UserTokenHandler;
-import org.apache.hc.client5.http.sync.ExecChain;
-import org.apache.hc.client5.http.sync.ExecRuntime;
-import org.apache.hc.client5.http.sync.methods.HttpGet;
-import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.ClassicHttpResponse;
-import org.apache.hc.core5.http.ConnectionReuseStrategy;
-import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
-import org.apache.hc.core5.util.TimeValue;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-@SuppressWarnings({"boxing","static-access"}) // test code
-public class TestMainClientExec {
-
-    @Mock
-    private ConnectionReuseStrategy reuseStrategy;
-    @Mock
-    private ConnectionKeepAliveStrategy keepAliveStrategy;
-    @Mock
-    private UserTokenHandler userTokenHandler;
-    @Mock
-    private ExecRuntime endpoint;
-
-    private MainClientExec mainClientExec;
-    private HttpHost target;
-
-    @Before
-    public void setup() throws Exception {
-        MockitoAnnotations.initMocks(this);
-        mainClientExec = new MainClientExec(reuseStrategy, keepAliveStrategy, userTokenHandler);
-        target = new HttpHost("foo", 80);
-    }
-
-    @Test
-    public void testExecRequestNonPersistentConnection() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpClientContext context = new HttpClientContext();
-        final ClassicHttpRequest request = new HttpGet("http://bar/test");
-        final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
-        response.setEntity(EntityBuilder.create()
-                .setStream(new ByteArrayInputStream(new byte[]{}))
-                .build());
-
-        Mockito.when(endpoint.isConnectionAcquired()).thenReturn(false);
-        Mockito.when(endpoint.execute(
-                Mockito.same(request),
-                Mockito.<HttpClientContext>any())).thenReturn(response);
-        Mockito.when(reuseStrategy.keepAlive(
-                Mockito.same(request),
-                Mockito.same(response),
-                Mockito.<HttpClientContext>any())).thenReturn(false);
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        final ClassicHttpResponse finalResponse = mainClientExec.execute(request, scope, null);
-        Mockito.verify(endpoint).execute(request, context);
-        Mockito.verify(endpoint, Mockito.times(1)).markConnectionNonReusable();
-        Mockito.verify(endpoint, Mockito.never()).releaseConnection();
-
-        Assert.assertNull(context.getUserToken());
-        Assert.assertNotNull(finalResponse);
-        Assert.assertTrue(finalResponse instanceof CloseableHttpResponse);
-    }
-
-    @Test
-    public void testExecRequestNonPersistentConnectionNoResponseEntity() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpClientContext context = new HttpClientContext();
-        final ClassicHttpRequest request = new HttpGet("http://bar/test");
-        final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
-        response.setEntity(null);
-
-        Mockito.when(endpoint.isConnectionAcquired()).thenReturn(false);
-        Mockito.when(endpoint.execute(
-                Mockito.same(request),
-                Mockito.<HttpClientContext>any())).thenReturn(response);
-        Mockito.when(reuseStrategy.keepAlive(
-                Mockito.same(request),
-                Mockito.same(response),
-                Mockito.<HttpClientContext>any())).thenReturn(false);
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        final ClassicHttpResponse finalResponse = mainClientExec.execute(request, scope, null);
-
-        Mockito.verify(endpoint).execute(request, context);
-        Mockito.verify(endpoint).markConnectionNonReusable();
-        Mockito.verify(endpoint).releaseConnection();
-
-        Assert.assertNotNull(finalResponse);
-        Assert.assertTrue(finalResponse instanceof CloseableHttpResponse);
-    }
-
-    @Test
-    public void testExecRequestPersistentConnection() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpClientContext context = new HttpClientContext();
-        final ClassicHttpRequest request = new HttpGet("http://bar/test");
-        final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
-        // The entity is streaming
-        response.setEntity(EntityBuilder.create()
-                .setStream(new ByteArrayInputStream(new byte[]{}))
-                .build());
-
-        final ConnectionState connectionState = new ConnectionState();
-        Mockito.doAnswer(connectionState.connectAnswer()).when(endpoint).connect(Mockito.<HttpClientContext>any());
-        Mockito.when(endpoint.isConnected()).thenAnswer(connectionState.isConnectedAnswer());
-        Mockito.when(endpoint.execute(
-                Mockito.same(request),
-                Mockito.<HttpClientContext>any())).thenReturn(response);
-        Mockito.when(reuseStrategy.keepAlive(
-                Mockito.same(request),
-                Mockito.same(response),
-                Mockito.<HttpClientContext>any())).thenReturn(true);
-        Mockito.when(keepAliveStrategy.getKeepAliveDuration(
-                Mockito.same(response),
-                Mockito.<HttpClientContext>any())).thenReturn(TimeValue.ofMillis(678L));
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        final ClassicHttpResponse finalResponse = mainClientExec.execute(request, scope, null);
-
-        Mockito.verify(endpoint).execute(request, context);
-        Mockito.verify(endpoint).markConnectionReusable();
-        Mockito.verify(endpoint, Mockito.never()).releaseConnection();
-
-        Assert.assertNotNull(finalResponse);
-        Assert.assertTrue(finalResponse instanceof CloseableHttpResponse);
-    }
-
-    @Test
-    public void testExecRequestPersistentConnectionNoResponseEntity() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpClientContext context = new HttpClientContext();
-        final ClassicHttpRequest request = new HttpGet("http://bar/test");
-        final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
-
-        final ConnectionState connectionState = new ConnectionState();
-        Mockito.doAnswer(connectionState.connectAnswer()).when(endpoint).connect(Mockito.<HttpClientContext>any());
-        Mockito.when(endpoint.isConnected()).thenAnswer(connectionState.isConnectedAnswer());
-        Mockito.when(endpoint.execute(
-                Mockito.same(request),
-                Mockito.<HttpClientContext>any())).thenReturn(response);
-        Mockito.when(reuseStrategy.keepAlive(
-                Mockito.same(request),
-                Mockito.same(response),
-                Mockito.<HttpClientContext>any())).thenReturn(true);
-        Mockito.when(keepAliveStrategy.getKeepAliveDuration(
-                Mockito.same(response),
-                Mockito.<HttpClientContext>any())).thenReturn(TimeValue.ofMillis(678L));
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        final ClassicHttpResponse finalResponse = mainClientExec.execute(request, scope, null);
-
-        Mockito.verify(endpoint).execute(request, context);
-        Mockito.verify(endpoint).releaseConnection();
-
-        Assert.assertNotNull(finalResponse);
-        Assert.assertTrue(finalResponse instanceof CloseableHttpResponse);
-    }
-
-    @Test
-    public void testExecRequestConnectionRelease() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpClientContext context = new HttpClientContext();
-        final ClassicHttpRequest request = new HttpGet("http://bar/test");
-        final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
-        // The entity is streaming
-        response.setEntity(EntityBuilder.create()
-                .setStream(new ByteArrayInputStream(new byte[]{}))
-                .build());
-
-        final ConnectionState connectionState = new ConnectionState();
-        Mockito.doAnswer(connectionState.connectAnswer()).when(endpoint).connect(Mockito.<HttpClientContext>any());
-        Mockito.when(endpoint.isConnected()).thenAnswer(connectionState.isConnectedAnswer());
-        Mockito.when(endpoint.execute(
-                Mockito.same(request),
-                Mockito.<HttpClientContext>any())).thenReturn(response);
-        Mockito.when(reuseStrategy.keepAlive(
-                Mockito.same(request),
-                Mockito.same(response),
-                Mockito.<HttpClientContext>any())).thenReturn(Boolean.FALSE);
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        final ClassicHttpResponse finalResponse = mainClientExec.execute(request, scope, null);
-        Mockito.verify(endpoint, Mockito.times(1)).execute(request, context);
-        Mockito.verify(endpoint, Mockito.never()).disconnect();
-        Mockito.verify(endpoint, Mockito.never()).releaseConnection();
-
-        Assert.assertNotNull(finalResponse);
-        Assert.assertTrue(finalResponse instanceof CloseableHttpResponse);
-        finalResponse.close();
-
-        Mockito.verify(endpoint).disconnect();
-        Mockito.verify(endpoint).discardConnection();
-    }
-
-    @Test(expected=InterruptedIOException.class)
-    public void testExecConnectionShutDown() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpClientContext context = new HttpClientContext();
-        final ClassicHttpRequest request = new HttpGet("http://bar/test");
-
-        Mockito.when(endpoint.execute(
-                Mockito.same(request),
-                Mockito.<HttpClientContext>any())).thenThrow(new ConnectionShutdownException());
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        try {
-            mainClientExec.execute(request, scope, null);
-        } catch (Exception ex) {
-            Mockito.verify(endpoint).discardConnection();
-            throw ex;
-        }
-    }
-
-    @Test(expected=RuntimeException.class)
-    public void testExecRuntimeException() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpClientContext context = new HttpClientContext();
-        final ClassicHttpRequest request = new HttpGet("http://bar/test");
-
-        Mockito.when(endpoint.execute(
-                Mockito.same(request),
-                Mockito.<HttpClientContext>any())).thenThrow(new RuntimeException("Ka-boom"));
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        try {
-            mainClientExec.execute(request, scope, null);
-        } catch (final Exception ex) {
-            Mockito.verify(endpoint).discardConnection();
-            throw ex;
-        }
-    }
-
-    @Test(expected=HttpException.class)
-    public void testExecHttpException() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpClientContext context = new HttpClientContext();
-        final ClassicHttpRequest request = new HttpGet("http://bar/test");
-
-        Mockito.when(endpoint.execute(
-                Mockito.same(request),
-                Mockito.<HttpClientContext>any())).thenThrow(new HttpException("Ka-boom"));
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        try {
-            mainClientExec.execute(request, scope, null);
-        } catch (final Exception ex) {
-            Mockito.verify(endpoint).discardConnection();
-            throw ex;
-        }
-    }
-
-    @Test(expected=IOException.class)
-    public void testExecIOException() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpClientContext context = new HttpClientContext();
-        final ClassicHttpRequest request = new HttpGet("http://bar/test");
-
-        Mockito.when(endpoint.execute(
-                Mockito.same(request),
-                Mockito.<HttpClientContext>any())).thenThrow(new IOException("Ka-boom"));
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        try {
-            mainClientExec.execute(request, scope, null);
-        } catch (final Exception ex) {
-            Mockito.verify(endpoint).discardConnection();
-            throw ex;
-        }
-    }
-
-    static class ConnectionState {
-
-        private boolean connected;
-
-        public Answer connectAnswer() {
-
-            return new Answer() {
-
-                @Override
-                public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
-                    connected = true;
-                    return null;
-                }
-
-            };
-        }
-
-        public Answer<Boolean> isConnectedAnswer() {
-
-            return new Answer<Boolean>() {
-
-                @Override
-                public Boolean answer(final InvocationOnMock invocationOnMock) throws Throwable {
-                    return connected;
-                }
-
-            };
-
-        };
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestNullBackoffStrategy.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestNullBackoffStrategy.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestNullBackoffStrategy.java
deleted file mode 100644
index 5784420..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestNullBackoffStrategy.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * ====================================================================
- * 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.hc.client5.http.impl.sync;
-
-import static org.junit.Assert.assertFalse;
-
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.HttpStatus;
-import org.apache.hc.core5.http.message.BasicHttpResponse;
-import org.junit.Before;
-import org.junit.Test;
-
-
-public class TestNullBackoffStrategy {
-
-    private NullBackoffStrategy impl;
-
-    @Before
-    public void setUp() {
-        impl = new NullBackoffStrategy();
-    }
-
-    @Test
-    public void doesNotBackoffForThrowables() {
-        assertFalse(impl.shouldBackoff(new Exception()));
-    }
-
-    @Test
-    public void doesNotBackoffForResponses() {
-        final HttpResponse resp = new BasicHttpResponse(HttpStatus.SC_SERVICE_UNAVAILABLE, "Service Unavailable");
-        assertFalse(impl.shouldBackoff(resp));
-    }
-}

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestProtocolExec.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestProtocolExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestProtocolExec.java
deleted file mode 100644
index a9ca4a5..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestProtocolExec.java
+++ /dev/null
@@ -1,340 +0,0 @@
-/*
- * ====================================================================
- * 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.hc.client5.http.impl.sync;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.Collections;
-import java.util.Map;
-
-import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.auth.AuthChallenge;
-import org.apache.hc.client5.http.auth.AuthExchange;
-import org.apache.hc.client5.http.auth.AuthScheme;
-import org.apache.hc.client5.http.auth.AuthScope;
-import org.apache.hc.client5.http.auth.ChallengeType;
-import org.apache.hc.client5.http.auth.Credentials;
-import org.apache.hc.client5.http.auth.CredentialsProvider;
-import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
-import org.apache.hc.client5.http.entity.EntityBuilder;
-import org.apache.hc.client5.http.impl.auth.BasicScheme;
-import org.apache.hc.client5.http.impl.auth.NTLMScheme;
-import org.apache.hc.client5.http.protocol.AuthenticationStrategy;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.protocol.NonRepeatableRequestException;
-import org.apache.hc.client5.http.sync.ExecChain;
-import org.apache.hc.client5.http.sync.ExecRuntime;
-import org.apache.hc.client5.http.sync.methods.HttpGet;
-import org.apache.hc.client5.http.sync.methods.HttpPost;
-import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.ClassicHttpResponse;
-import org.apache.hc.core5.http.EntityDetails;
-import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpHeaders;
-import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
-import org.apache.hc.core5.http.protocol.HttpContext;
-import org.apache.hc.core5.http.protocol.HttpProcessor;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-@SuppressWarnings({"static-access"}) // test code
-public class TestProtocolExec {
-
-    @Mock
-    private HttpProcessor httpProcessor;
-    @Mock
-    private AuthenticationStrategy targetAuthStrategy;
-    @Mock
-    private AuthenticationStrategy proxyAuthStrategy;
-    @Mock
-    private ExecChain chain;
-    @Mock
-    private ExecRuntime execRuntime;
-
-    private ProtocolExec protocolExec;
-    private HttpHost target;
-    private HttpHost proxy;
-
-    @Before
-    public void setup() throws Exception {
-        MockitoAnnotations.initMocks(this);
-        protocolExec = new ProtocolExec(httpProcessor, targetAuthStrategy, proxyAuthStrategy);
-        target = new HttpHost("foo", 80);
-        proxy = new HttpHost("bar", 8888);
-    }
-
-    @Test
-    public void testFundamentals() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final ClassicHttpRequest request = new HttpGet("/test");
-        final HttpClientContext context = HttpClientContext.create();
-
-        final ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
-
-        Mockito.when(chain.proceed(
-                Mockito.<ClassicHttpRequest>any(),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response);
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
-        protocolExec.execute(request, scope, chain);
-
-        Mockito.verify(httpProcessor).process(request, null, context);
-        Mockito.verify(chain).proceed(request, scope);
-        Mockito.verify(httpProcessor).process(response, null, context);
-
-        Assert.assertEquals(route, context.getHttpRoute());
-        Assert.assertSame(request, context.getRequest());
-        Assert.assertSame(response, context.getResponse());
-    }
-
-    @Test
-    public void testUserInfoInRequestURI() throws Exception {
-        final HttpRoute route = new HttpRoute(new HttpHost("somehost", 8080));
-        final ClassicHttpRequest request = new HttpGet("http://somefella:secret@bar/test");
-        final HttpClientContext context = HttpClientContext.create();
-        context.setCredentialsProvider(new BasicCredentialsProvider());
-
-        final ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
-        Mockito.when(chain.proceed(
-                Mockito.<ClassicHttpRequest>any(),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response);
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
-        protocolExec.execute(request, scope, chain);
-        Assert.assertEquals(new URI("http://bar/test"), request.getUri());
-        final CredentialsProvider credentialsProvider = context.getCredentialsProvider();
-        final Credentials creds = credentialsProvider.getCredentials(new AuthScope("bar", -1, null), null);
-        Assert.assertNotNull(creds);
-        Assert.assertEquals("somefella", creds.getUserPrincipal().getName());
-    }
-
-    @Test(expected = HttpException.class)
-    public void testPostProcessHttpException() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final ClassicHttpRequest request = new HttpGet("/test");
-        final HttpClientContext context = HttpClientContext.create();
-
-        final ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
-
-        Mockito.when(chain.proceed(
-                Mockito.<ClassicHttpRequest>any(),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response);
-        Mockito.doThrow(new HttpException("Ooopsie")).when(httpProcessor).process(
-                Mockito.same(response), Mockito.<EntityDetails>isNull(), Mockito.<HttpContext>any());
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
-        try {
-            protocolExec.execute(request, scope, chain);
-        } catch (final Exception ex) {
-            Mockito.verify(execRuntime).discardConnection();
-            throw ex;
-        }
-    }
-
-    @Test(expected = IOException.class)
-    public void testPostProcessIOException() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final ClassicHttpRequest request = new HttpGet("/test");
-        final HttpClientContext context = HttpClientContext.create();
-
-        final ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
-        Mockito.when(chain.proceed(
-                Mockito.<ClassicHttpRequest>any(),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response);
-        Mockito.doThrow(new IOException("Ooopsie")).when(httpProcessor).process(
-                Mockito.same(response), Mockito.<EntityDetails>isNull(), Mockito.<HttpContext>any());
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
-        try {
-            protocolExec.execute(request, scope, chain);
-        } catch (final Exception ex) {
-            Mockito.verify(execRuntime).discardConnection();
-            throw ex;
-        }
-    }
-
-    @Test(expected = RuntimeException.class)
-    public void testPostProcessRuntimeException() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final ClassicHttpRequest request = new HttpGet("/test");
-        final HttpClientContext context = HttpClientContext.create();
-
-        final ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
-        Mockito.when(chain.proceed(
-                Mockito.<ClassicHttpRequest>any(),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response);
-        Mockito.doThrow(new RuntimeException("Ooopsie")).when(httpProcessor).process(
-                Mockito.same(response), Mockito.<EntityDetails>isNull(), Mockito.<HttpContext>any());
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
-        try {
-            protocolExec.execute(request, scope, chain);
-        } catch (final Exception ex) {
-            Mockito.verify(execRuntime).discardConnection();
-            throw ex;
-        }
-    }
-
-    @Test
-    public void testExecRequestRetryOnAuthChallenge() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpClientContext context = new HttpClientContext();
-        final ClassicHttpRequest request = new HttpGet("http://foo/test");
-        final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?");
-        response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
-        final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
-        response1.setEntity(EntityBuilder.create()
-                .setStream(instream1)
-                .build());
-        final ClassicHttpResponse response2 = new BasicClassicHttpResponse(200, "OK");
-        final InputStream instream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {2, 3, 4}));
-        response2.setEntity(EntityBuilder.create()
-                .setStream(instream2)
-                .build());
-
-        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
-        credentialsProvider.setCredentials(new AuthScope(target), new UsernamePasswordCredentials("user", "pass".toCharArray()));
-        context.setCredentialsProvider(credentialsProvider);
-
-        Mockito.when(chain.proceed(
-                Mockito.same(request),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response1, response2);
-        Mockito.when(targetAuthStrategy.select(
-                Mockito.eq(ChallengeType.TARGET),
-                Mockito.<Map<String, AuthChallenge>>any(),
-                Mockito.<HttpClientContext>any())).thenReturn(Collections.<AuthScheme>singletonList(new BasicScheme()));
-        Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true);
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
-        final ClassicHttpResponse finalResponse = protocolExec.execute(request, scope, chain);
-        Mockito.verify(chain, Mockito.times(2)).proceed(request, scope);
-        Mockito.verify(instream1).close();
-        Mockito.verify(instream2, Mockito.never()).close();
-
-        Assert.assertNotNull(finalResponse);
-        Assert.assertEquals(200, finalResponse.getCode());
-    }
-
-    @Test
-    public void testExecEntityEnclosingRequestRetryOnAuthChallenge() throws Exception {
-        final HttpRoute route = new HttpRoute(target, proxy);
-        final ClassicHttpRequest request = new HttpGet("http://foo/test");
-        final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?");
-        response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
-        final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
-        response1.setEntity(EntityBuilder.create()
-                .setStream(instream1)
-                .build());
-        final ClassicHttpResponse response2 = new BasicClassicHttpResponse(200, "OK");
-        final InputStream instream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {2, 3, 4}));
-        response2.setEntity(EntityBuilder.create()
-                .setStream(instream2)
-                .build());
-
-        final HttpClientContext context = new HttpClientContext();
-
-        final AuthExchange proxyAuthExchange = new AuthExchange();
-        proxyAuthExchange.setState(AuthExchange.State.SUCCESS);
-        proxyAuthExchange.select(new NTLMScheme());
-        context.setAuthExchange(proxy, proxyAuthExchange);
-
-        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
-        credentialsProvider.setCredentials(new AuthScope(target), new UsernamePasswordCredentials("user", "pass".toCharArray()));
-        context.setCredentialsProvider(credentialsProvider);
-
-        Mockito.when(chain.proceed(
-                Mockito.same(request),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response1, response2);
-
-        Mockito.when(targetAuthStrategy.select(
-                Mockito.eq(ChallengeType.TARGET),
-                Mockito.<Map<String, AuthChallenge>>any(),
-                Mockito.<HttpClientContext>any())).thenReturn(Collections.<AuthScheme>singletonList(new BasicScheme()));
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
-        final ClassicHttpResponse finalResponse = protocolExec.execute(request, scope, chain);
-        Mockito.verify(chain, Mockito.times(2)).proceed(request, scope);
-        Mockito.verify(execRuntime).disconnect();
-        Mockito.verify(instream2, Mockito.never()).close();
-
-        Assert.assertNotNull(finalResponse);
-        Assert.assertEquals(200, finalResponse.getCode());
-        Assert.assertNull(proxyAuthExchange.getAuthScheme());
-    }
-
-    @Test(expected = NonRepeatableRequestException.class)
-    public void testExecEntityEnclosingRequest() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpClientContext context = new HttpClientContext();
-        final HttpPost request = new HttpPost("http://foo/test");
-        final InputStream instream0 = new ByteArrayInputStream(new byte[] {1, 2, 3});
-        request.setEntity(EntityBuilder.create()
-                .setStream(instream0)
-                .build());
-        final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?");
-        response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
-        final InputStream instream1 = new ByteArrayInputStream(new byte[] {1, 2, 3});
-        response1.setEntity(EntityBuilder.create()
-                .setStream(instream1)
-                .build());
-
-        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
-        credentialsProvider.setCredentials(new AuthScope(target), new UsernamePasswordCredentials("user", "pass".toCharArray()));
-        context.setCredentialsProvider(credentialsProvider);
-
-        Mockito.when(chain.proceed(
-                Mockito.same(request),
-                Mockito.<ExecChain.Scope>any())).thenAnswer(new Answer<HttpResponse>() {
-
-            @Override
-            public HttpResponse answer(final InvocationOnMock invocationOnMock) throws Throwable {
-                final Object[] args = invocationOnMock.getArguments();
-                final ClassicHttpRequest requestEE = (ClassicHttpRequest) args[0];
-                requestEE.getEntity().writeTo(new ByteArrayOutputStream());
-                return response1;
-            }
-
-        });
-
-        Mockito.when(targetAuthStrategy.select(
-                Mockito.eq(ChallengeType.TARGET),
-                Mockito.<Map<String, AuthChallenge>>any(),
-                Mockito.<HttpClientContext>any())).thenReturn(Collections.<AuthScheme>singletonList(new BasicScheme()));
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context);
-        protocolExec.execute(request, scope, chain);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/6d17126c/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestRedirectExec.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestRedirectExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestRedirectExec.java
deleted file mode 100644
index 05ba193..0000000
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestRedirectExec.java
+++ /dev/null
@@ -1,350 +0,0 @@
-/*
- * ====================================================================
- * 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.hc.client5.http.impl.sync;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.List;
-
-import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.auth.AuthExchange;
-import org.apache.hc.client5.http.config.RequestConfig;
-import org.apache.hc.client5.http.entity.EntityBuilder;
-import org.apache.hc.client5.http.impl.auth.BasicScheme;
-import org.apache.hc.client5.http.impl.auth.NTLMScheme;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.protocol.RedirectException;
-import org.apache.hc.client5.http.protocol.RedirectStrategy;
-import org.apache.hc.client5.http.routing.HttpRoutePlanner;
-import org.apache.hc.client5.http.sync.ExecChain;
-import org.apache.hc.client5.http.sync.ExecRuntime;
-import org.apache.hc.client5.http.sync.methods.HttpGet;
-import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.ClassicHttpResponse;
-import org.apache.hc.core5.http.HttpEntity;
-import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.ProtocolException;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.ArgumentMatcher;
-import org.mockito.ArgumentMatchers;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-@SuppressWarnings({"boxing","static-access"}) // test code
-public class TestRedirectExec {
-
-    @Mock
-    private HttpRoutePlanner httpRoutePlanner;
-    @Mock
-    private RedirectStrategy redirectStrategy;
-    @Mock
-    private ExecChain chain;
-    @Mock
-    private ExecRuntime endpoint;
-
-    private RedirectExec redirectExec;
-    private HttpHost target;
-
-    @Before
-    public void setup() throws Exception {
-        MockitoAnnotations.initMocks(this);
-        redirectExec = new RedirectExec(httpRoutePlanner, redirectStrategy);
-        target = new HttpHost("localhost", 80);
-    }
-
-    @Test
-    public void testFundamentals() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpGet request = new HttpGet("/test");
-        final HttpClientContext context = HttpClientContext.create();
-
-        final ClassicHttpResponse response1 = Mockito.mock(ClassicHttpResponse.class);
-        final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
-        final HttpEntity entity1 = EntityBuilder.create()
-                .setStream(instream1)
-                .build();
-        Mockito.when(response1.getEntity()).thenReturn(entity1);
-        final ClassicHttpResponse response2 = Mockito.mock(ClassicHttpResponse.class);
-        final InputStream instream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
-        final HttpEntity entity2 = EntityBuilder.create()
-                .setStream(instream2)
-                .build();
-        Mockito.when(response2.getEntity()).thenReturn(entity2);
-        final URI redirect = new URI("http://localhost:80/redirect");
-
-        Mockito.when(chain.proceed(
-                Mockito.same(request),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response1);
-        Mockito.when(chain.proceed(
-                HttpRequestMatcher.matchesRequestUri(redirect),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response2);
-        Mockito.when(redirectStrategy.isRedirected(
-                Mockito.same(request),
-                Mockito.same(response1),
-                Mockito.<HttpClientContext>any())).thenReturn(Boolean.TRUE);
-        Mockito.when(redirectStrategy.getLocationURI(
-                Mockito.same(request),
-                Mockito.same(response1),
-                Mockito.<HttpClientContext>any())).thenReturn(redirect);
-        Mockito.when(httpRoutePlanner.determineRoute(
-                Mockito.eq(target),
-                Mockito.<HttpClientContext>any())).thenReturn(route);
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        redirectExec.execute(request, scope, chain);
-
-        final ArgumentCaptor<ClassicHttpRequest> reqCaptor = ArgumentCaptor.forClass(
-                ClassicHttpRequest.class);
-        Mockito.verify(chain, Mockito.times(2)).proceed(
-                reqCaptor.capture(),
-                Mockito.same(scope));
-
-        final List<ClassicHttpRequest> allValues = reqCaptor.getAllValues();
-        Assert.assertNotNull(allValues);
-        Assert.assertEquals(2, allValues.size());
-        Assert.assertSame(request, allValues.get(0));
-
-        Mockito.verify(response1, Mockito.times(1)).close();
-        Mockito.verify(instream1, Mockito.times(1)).close();
-        Mockito.verify(response2, Mockito.never()).close();
-        Mockito.verify(instream2, Mockito.never()).close();
-    }
-
-    @Test(expected = RedirectException.class)
-    public void testMaxRedirect() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpGet request = new HttpGet("/test");
-        final HttpClientContext context = HttpClientContext.create();
-        final RequestConfig config = RequestConfig.custom()
-                .setRedirectsEnabled(true)
-                .setMaxRedirects(3)
-                .build();
-        context.setRequestConfig(config);
-
-        final ClassicHttpResponse response1 = Mockito.mock(ClassicHttpResponse.class);
-        final URI redirect = new URI("http://localhost:80/redirect");
-
-        Mockito.when(chain.proceed(
-                Mockito.<ClassicHttpRequest>any(),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response1);
-        Mockito.when(redirectStrategy.isRedirected(
-                Mockito.<ClassicHttpRequest>any(),
-                Mockito.<HttpResponse>any(),
-                Mockito.<HttpClientContext>any())).thenReturn(Boolean.TRUE);
-        Mockito.when(redirectStrategy.getLocationURI(
-                Mockito.<ClassicHttpRequest>any(),
-                Mockito.<HttpResponse>any(),
-                Mockito.<HttpClientContext>any())).thenReturn(redirect);
-        Mockito.when(httpRoutePlanner.determineRoute(
-                Mockito.eq(target),
-                Mockito.<HttpClientContext>any())).thenReturn(route);
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        redirectExec.execute(request, scope, chain);
-    }
-
-    @Test(expected = HttpException.class)
-    public void testRelativeRedirect() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpGet request = new HttpGet("/test");
-        final HttpClientContext context = HttpClientContext.create();
-
-        final ClassicHttpResponse response1 = Mockito.mock(ClassicHttpResponse.class);
-        final ClassicHttpResponse response2 = Mockito.mock(ClassicHttpResponse.class);
-        final URI redirect = new URI("/redirect");
-        Mockito.when(chain.proceed(
-                Mockito.same(request),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response1);
-        Mockito.when(chain.proceed(
-                HttpRequestMatcher.matchesRequestUri(redirect),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response2);
-        Mockito.when(redirectStrategy.isRedirected(
-                Mockito.same(request),
-                Mockito.same(response1),
-                Mockito.<HttpClientContext>any())).thenReturn(Boolean.TRUE);
-        Mockito.when(redirectStrategy.getLocationURI(
-                Mockito.same(request),
-                Mockito.same(response1),
-                Mockito.<HttpClientContext>any())).thenReturn(redirect);
-        Mockito.when(httpRoutePlanner.determineRoute(
-                Mockito.eq(target),
-                Mockito.<HttpClientContext>any())).thenReturn(route);
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        redirectExec.execute(request, scope, chain);
-    }
-
-    @Test
-    public void testCrossSiteRedirect() throws Exception {
-
-        final HttpHost proxy = new HttpHost("proxy");
-        final HttpRoute route = new HttpRoute(target, proxy);
-        final HttpGet request = new HttpGet("/test");
-        final HttpClientContext context = HttpClientContext.create();
-
-        final AuthExchange targetAuthExchange = new AuthExchange();
-        targetAuthExchange.setState(AuthExchange.State.SUCCESS);
-        targetAuthExchange.select(new BasicScheme());
-        final AuthExchange proxyAuthExchange = new AuthExchange();
-        proxyAuthExchange.setState(AuthExchange.State.SUCCESS);
-        proxyAuthExchange.select(new NTLMScheme());
-        context.setAuthExchange(target, targetAuthExchange);
-        context.setAuthExchange(proxy, proxyAuthExchange);
-
-        final ClassicHttpResponse response1 = Mockito.mock(ClassicHttpResponse.class);
-        final ClassicHttpResponse response2 = Mockito.mock(ClassicHttpResponse.class);
-        final HttpHost otherHost = new HttpHost("otherhost", 8888);
-        final URI redirect = new URI("http://otherhost:8888/redirect");
-        Mockito.when(chain.proceed(
-                Mockito.same(request),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response1);
-        Mockito.when(chain.proceed(
-                HttpRequestMatcher.matchesRequestUri(redirect),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response2);
-        Mockito.when(redirectStrategy.isRedirected(
-                Mockito.same(request),
-                Mockito.same(response1),
-                Mockito.<HttpClientContext>any())).thenReturn(Boolean.TRUE);
-        Mockito.when(redirectStrategy.getLocationURI(
-                Mockito.same(request),
-                Mockito.same(response1),
-                Mockito.<HttpClientContext>any())).thenReturn(redirect);
-        Mockito.when(httpRoutePlanner.determineRoute(
-                Mockito.eq(target),
-                Mockito.<HttpClientContext>any())).thenReturn(new HttpRoute(target));
-        Mockito.when(httpRoutePlanner.determineRoute(
-                Mockito.eq(otherHost),
-                Mockito.<HttpClientContext>any())).thenReturn(new HttpRoute(otherHost));
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        redirectExec.execute(request, scope, chain);
-
-        final AuthExchange authExchange1 = context.getAuthExchange(target);
-        Assert.assertNotNull(authExchange1);
-        Assert.assertEquals(AuthExchange.State.UNCHALLENGED, authExchange1.getState());
-        Assert.assertEquals(null, authExchange1.getAuthScheme());
-        final AuthExchange authExchange2 = context.getAuthExchange(proxy);
-        Assert.assertNotNull(authExchange2);
-        Assert.assertEquals(AuthExchange.State.UNCHALLENGED, authExchange2.getState());
-        Assert.assertEquals(null, authExchange2.getAuthScheme());
-    }
-
-    @Test(expected = RuntimeException.class)
-    public void testRedirectRuntimeException() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpGet request = new HttpGet("/test");
-        final HttpClientContext context = HttpClientContext.create();
-
-        final ClassicHttpResponse response1 = Mockito.mock(ClassicHttpResponse.class);
-        Mockito.when(chain.proceed(
-                Mockito.same(request),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response1);
-        Mockito.when(redirectStrategy.isRedirected(
-                Mockito.same(request),
-                Mockito.same(response1),
-                Mockito.<HttpClientContext>any())).thenReturn(Boolean.TRUE);
-        Mockito.doThrow(new RuntimeException("Oppsie")).when(redirectStrategy.getLocationURI(
-                Mockito.same(request),
-                Mockito.same(response1),
-                Mockito.<HttpClientContext>any()));
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        try {
-            redirectExec.execute(request, scope, chain);
-        } catch (final Exception ex) {
-            Mockito.verify(response1).close();
-            throw ex;
-        }
-    }
-
-    @Test(expected = ProtocolException.class)
-    public void testRedirectProtocolException() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpGet request = new HttpGet("/test");
-        final HttpClientContext context = HttpClientContext.create();
-
-        final ClassicHttpResponse response1 = Mockito.mock(ClassicHttpResponse.class);
-        final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
-        final HttpEntity entity1 = EntityBuilder.create()
-                .setStream(instream1)
-                .build();
-        Mockito.when(response1.getEntity()).thenReturn(entity1);
-        Mockito.when(chain.proceed(
-                Mockito.same(request),
-                Mockito.<ExecChain.Scope>any())).thenReturn(response1);
-        Mockito.when(redirectStrategy.isRedirected(
-                Mockito.same(request),
-                Mockito.same(response1),
-                Mockito.<HttpClientContext>any())).thenReturn(Boolean.TRUE);
-        Mockito.doThrow(new ProtocolException("Oppsie")).when(redirectStrategy).getLocationURI(
-                Mockito.same(request),
-                Mockito.same(response1),
-                Mockito.<HttpClientContext>any());
-
-        final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context);
-        try {
-            redirectExec.execute(request, scope, chain);
-        } catch (final Exception ex) {
-            Mockito.verify(instream1).close();
-            Mockito.verify(response1).close();
-            throw ex;
-        }
-    }
-
-    private static class HttpRequestMatcher implements ArgumentMatcher<ClassicHttpRequest> {
-
-        private final URI requestUri;
-
-        HttpRequestMatcher(final URI requestUri) {
-            super();
-            this.requestUri = requestUri;
-        }
-
-        @Override
-        public boolean matches(final ClassicHttpRequest argument) {
-            try {
-                return requestUri.equals(argument.getUri());
-            } catch (URISyntaxException e) {
-                return false;
-            }
-        }
-
-        static ClassicHttpRequest matchesRequestUri(final URI requestUri) {
-            return ArgumentMatchers.argThat(new HttpRequestMatcher(requestUri));
-        }
-
-    }
-
-}


Mime
View raw message