You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2016/10/31 22:21:31 UTC

svn commit: r1767384 [2/3] - in /httpcomponents/httpcore/trunk: ./ httpcore5-h2/ httpcore5-testing/ httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ httpcore5-te...

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFramework.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFramework.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFramework.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFramework.java Mon Oct 31 22:21:30 2016
@@ -1,492 +1,449 @@
-/*
- * ====================================================================
- * 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.core5.testing.framework;
-
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.BODY;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.CONTENT_TYPE;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.HEADERS;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.METHOD;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.REQUEST;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.RESPONSE;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.STATUS;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.hc.core5.http.HttpVersion;
-import org.apache.hc.core5.http.ProtocolVersion;
-import org.apache.hc.core5.http.config.SocketConfig;
-import org.apache.hc.core5.http.impl.io.bootstrap.HttpServer;
-import org.apache.hc.core5.http.impl.io.bootstrap.ServerBootstrap;
-
-/**
- * <p>This testing framework starts an in-process {@link HttpServer} which will use an
- * {@link TestingFrameworkRequestHandler} to check HTTP requests that are sent
- * to it.  Before the request is sent, the handler is told what request to expect.
- * If the received request does not match the request expectations, an exception
- * is thrown.</p>
- *
- * <p>The handler is also told what response to return.  This testing framework will
- * then check the response it receives with what it desired.  If they do not
- * match, an exception is thrown.</p>
- *
- * <p>This has been designed to work with any HTTP client.  So, for instance, Groovy's
- * HttpBuilder or RESTClient which uses Apache HttpClient can also be tested with this
- * testing framework.  A different {@link ClientTestingAdapter} is used with
- * different HTTP clients.  If testing Apache HttpClient5, the {@link ClassicTestClientTestingAdapter}
- * is used.  Since use of this testing framework with other projects is desired,
- * the testframework package has been placed outside the test directory.  Care has
- * been taken to make sure no testing dependency such as JUnit or EasyMock is used
- * in the framework.</p>
- *
- * <p>The {@link ClassicTestClientTestingAdapter} that is used is either passed into the
- * constructor or set with setAdapter().</p>
- *
- * <p>By default, this framework will go through a series of tests that will exercise
- * all HTTP methods.  If the default tests are not desired, then the deleteTests()
- * method can be called.  Then, custom tests can be added with the addTest() methods.
- * Of course additional tests can be added with the addTest() method without first
- * calling deleteTests().  In that case, the default tests and the additional tests
- * will all run.</p>
- *
- * <p>Since this framework has been designed to be used with any HTTP client, the test
- * is specified with POJO's such as Map, List, and primitives.  The test is a Map with
- * two keys - request and response.  See {@link ClientPOJOAdapter} for details
- * on the format of the request and response.</p>
- *
- * <p>Once any additional tests have been added, the runTests() method is called to
- * actually do the testing.</p>
- *
- * @since 5.0
- *
- */
-public class TestingFramework {
-    /**
-     * Use the ALL_METHODS list to conveniently cycle through all HTTP methods.
-     */
-    public static final List<String> ALL_METHODS = Arrays.asList("HEAD", "GET", "DELETE", "POST", "PUT", "PATCH");
-
-    /**
-     * If an {@link ClassicTestClientTestingAdapter} is unable to return a response in
-     * the format this testing framework is needing, then it will need to check the
-     * item in the response (such as body, status, headers, or contentType) itself and set
-     * the returned value of the item as ALREADY_CHECKED.
-     */
-    public static final Object ALREADY_CHECKED = new Object();
-
-    /**
-     * If a test does not specify a path, this one is used.
-     */
-    public static final String DEFAULT_REQUEST_PATH = "a/path";
-
-    /**
-     * If a test does not specify a body, this one is used.
-     */
-    public static final String DEFAULT_REQUEST_BODY = "{\"location\":\"home\"}";
-
-    /**
-     * If a test does not specify a request contentType, this one is used.
-     */
-    public static final String DEFAULT_REQUEST_CONTENT_TYPE = "application/json";
-
-    /**
-     * If a test does not specify query parameters, these are used.
-     */
-    public static final Map<String, String> DEFAULT_REQUEST_QUERY;
-
-    /**
-     * If a test does not specify a request headers, these are used.
-     */
-    public static final Map<String, String> DEFAULT_REQUEST_HEADERS;
-
-    /**
-     * If a test does not specify a protocol version, this one is used.
-     */
-    public static final ProtocolVersion DEFAULT_REQUEST_PROTOCOL_VERSION = HttpVersion.HTTP_1_1;
-
-    /**
-     * If a test does not specify an expected response status, this one is used.
-     */
-    public static final int DEFAULT_RESPONSE_STATUS = 200;
-
-    /**
-     * If a test does not specify an expected response body, this one is used.
-     */
-    public static final String DEFAULT_RESPONSE_BODY = "{\"location\":\"work\"}";
-
-    /**
-     * If a test does not specify an expected response contentType, this one is used.
-     */
-    public static final String DEFAULT_RESPONSE_CONTENT_TYPE = "application/json";
-
-    /**
-     * If a test does not specify expected response headers, these are used.
-     */
-    public static final Map<String, String> DEFAULT_RESPONSE_HEADERS;
-
-    static {
-        final Map<String, String> request = new HashMap<String, String>();
-        request.put("p1", "this");
-        request.put("p2", "that");
-        DEFAULT_REQUEST_QUERY = Collections.unmodifiableMap(request);
-
-        Map<String, String> headers = new HashMap<String, String>();
-        headers.put("header1", "stuff");
-        headers.put("header2", "more stuff");
-        DEFAULT_REQUEST_HEADERS = Collections.unmodifiableMap(headers);
-
-        headers = new HashMap<String, String>();
-        headers.put("header3", "header_three");
-        headers.put("header4", "header_four");
-        DEFAULT_RESPONSE_HEADERS = Collections.unmodifiableMap(headers);
-    }
-
-    private ClientTestingAdapter adapter;
-    private TestingFrameworkRequestHandler requestHandler = new TestingFrameworkRequestHandler();
-    private List<FrameworkTest> tests = new ArrayList<FrameworkTest>();
-
-    private HttpServer server;
-    private int port;
-
-    public TestingFramework() throws TestingFrameworkException {
-        this(null);
-    }
-
-    public TestingFramework(final ClientTestingAdapter adapter) throws TestingFrameworkException {
-        this.adapter = adapter;
-
-        /*
-         * By default, a set of tests that will exercise each HTTP method are pre-loaded.
-         */
-        for (String method : ALL_METHODS) {
-            final List<Integer> statusList = Arrays.asList(200, 201);
-            for (Integer status : statusList) {
-                final Map<String, Object> request = new HashMap<String, Object>();
-                request.put(METHOD, method);
-
-                final Map<String, Object> response = new HashMap<String, Object>();
-                response.put(STATUS, status);
-
-                final Map<String, Object> test = new HashMap<String, Object>();
-                test.put(REQUEST, request);
-                test.put(RESPONSE, response);
-
-                addTest(test);
-            }
-        }
-    }
-
-    /**
-     * This is not likely to be used except during the testing of this class.
-     * It is used to inject a mocked request handler.
-     *
-     * @param requestHandler
-     */
-    public void setRequestHandler(final TestingFrameworkRequestHandler requestHandler) {
-        this.requestHandler = requestHandler;
-    }
-
-    /**
-     * Run the tests that have been previously added.  First, an in-process {@link HttpServer} is
-     * started.  Then, all the tests are completed by passing each test to the adapter
-     * which will make the HTTP request.
-     *
-     * @throws TestingFrameworkException if there is a test failure or unexpected problem.
-     */
-    public void runTests() throws TestingFrameworkException {
-        if (adapter == null) {
-            throw new TestingFrameworkException("adapter should not be null");
-        }
-
-        startServer();
-
-        try {
-            for (FrameworkTest test : tests) {
-                try {
-                    callAdapter(test);
-                } catch (Throwable t) {
-                    processThrowable(t, test);
-                }
-            }
-        } finally {
-            stopServer();
-        }
-    }
-
-    private void processThrowable(final Throwable t, final FrameworkTest test) throws TestingFrameworkException {
-        final TestingFrameworkException e;
-        if (t instanceof TestingFrameworkException) {
-            e = (TestingFrameworkException) t;
-        } else {
-            e = new TestingFrameworkException(t);
-        }
-        e.setAdapter(adapter);
-        e.setTest(test);
-        throw e;
-    }
-
-    private void startServer() throws TestingFrameworkException {
-        /*
-         * Start an in-process server and handle all HTTP requests
-         * with the requestHandler.
-         */
-        final SocketConfig socketConfig = SocketConfig.custom()
-                                          .setSoTimeout(15000)
-                                          .build();
-
-        final ServerBootstrap serverBootstrap = ServerBootstrap.bootstrap()
-                                          .setSocketConfig(socketConfig)
-                                          .registerHandler("/*", requestHandler);
-
-        server = serverBootstrap.create();
-        try {
-            server.start();
-        } catch (IOException e) {
-            throw new TestingFrameworkException(e);
-        }
-
-        port = server.getLocalPort();
-    }
-
-    private void stopServer() {
-        if (server != null) {
-            server.shutdown(0, TimeUnit.SECONDS);
-            server = null;
-        }
-    }
-
-    private void callAdapter(final FrameworkTest test) throws TestingFrameworkException {
-        Map<String, Object> request = test.initRequest();
-
-        /*
-         * If the adapter does not support the particular request, skip the test.
-         */
-        if (! adapter.isRequestSupported(request)) {
-            return;
-        }
-
-        /*
-         * Allow the adapter to modify the request before the request expectations
-         * are given to the requestHandler.  Typically, adapters should not have
-         * to modify the request.
-         */
-        request = adapter.modifyRequest(request);
-
-        // Tell the request handler what to expect in the request.
-        requestHandler.setRequestExpectations(request);
-
-        Map<String, Object> responseExpectations = test.initResponseExpectations();
-        /*
-         * Allow the adapter to modify the response expectations before the handler
-         * is told what to return.  Typically, adapters should not have to modify
-         * the response expectations.
-         */
-        responseExpectations = adapter.modifyResponseExpectations(request, responseExpectations);
-
-        // Tell the request handler what response to return.
-        requestHandler.setDesiredResponse(responseExpectations);
-
-        /*
-         * Use the adapter to make the HTTP call.  Make sure the responseExpectations are not changed
-         * since they have already been sent to the request handler and they will later be used
-         * to check the response.
-         */
-        final String defaultURI = getDefaultURI();
-        final Map<String, Object> response = adapter.execute(
-                                                defaultURI,
-                                                request,
-                                                requestHandler,
-                                                Collections.unmodifiableMap(responseExpectations));
-        /*
-         * The adapter is welcome to call assertNothingThrown() earlier, but we will
-         * do it here to make sure it is done.  If the handler threw any exception
-         * while checking the request it received, it will be re-thrown here.
-         */
-        requestHandler.assertNothingThrown();
-
-        assertResponseMatchesExpectation(request.get(METHOD), response, responseExpectations);
-    }
-
-    @SuppressWarnings("unchecked")
-    private void assertResponseMatchesExpectation(final Object method, final Map<String, Object> actualResponse,
-                                                  final Map<String, Object> expectedResponse)
-                                                  throws TestingFrameworkException {
-        if (actualResponse == null) {
-            throw new TestingFrameworkException("response should not be null");
-        }
-        /*
-         * Now check the items in the response unless the adapter says they
-         * already checked something.
-         */
-        if (actualResponse.get(STATUS) != TestingFramework.ALREADY_CHECKED) {
-            assertStatusMatchesExpectation(actualResponse.get(STATUS), expectedResponse.get(STATUS));
-        }
-        if (! method.equals("HEAD")) {
-            if (actualResponse.get(BODY) != TestingFramework.ALREADY_CHECKED) {
-                assertBodyMatchesExpectation(actualResponse.get(BODY), expectedResponse.get(BODY));
-            }
-            if (actualResponse.get(CONTENT_TYPE) != TestingFramework.ALREADY_CHECKED) {
-                assertContentTypeMatchesExpectation(actualResponse.get(CONTENT_TYPE), expectedResponse.get(CONTENT_TYPE));
-            }
-        }
-        if (actualResponse.get(HEADERS) != TestingFramework.ALREADY_CHECKED) {
-            assertHeadersMatchExpectation((Map<String, String>) actualResponse.get(HEADERS),
-                                          (Map<String, String>) expectedResponse.get(HEADERS));
-        }
-    }
-
-    private void assertStatusMatchesExpectation(final Object actualStatus, final Object expectedStatus)
-            throws TestingFrameworkException {
-        if (actualStatus == null) {
-            throw new TestingFrameworkException("Returned status is null.");
-        }
-        if ((expectedStatus != null) && (! actualStatus.equals(expectedStatus))) {
-            throw new TestingFrameworkException("Expected status not found. expected="
-                                                  + expectedStatus + "; actual=" + actualStatus);
-        }
-    }
-
-    private void assertBodyMatchesExpectation(final Object actualBody, final Object expectedBody)
-        throws TestingFrameworkException {
-        if (actualBody == null) {
-            throw new TestingFrameworkException("Returned body is null.");
-        }
-        if ((expectedBody != null) && (! actualBody.equals(expectedBody))) {
-            throw new TestingFrameworkException("Expected body not found. expected="
-                                    + expectedBody + "; actual=" + actualBody);
-        }
-    }
-
-    private void assertContentTypeMatchesExpectation(final Object actualContentType, final Object expectedContentType)
-        throws TestingFrameworkException {
-        if (expectedContentType != null) {
-            if (actualContentType == null) {
-                throw new TestingFrameworkException("Returned contentType is null.");
-            }
-            if (! actualContentType.equals(expectedContentType)) {
-                throw new TestingFrameworkException("Expected content type not found.  expected="
-                                    + expectedContentType + "; actual=" + actualContentType);
-            }
-        }
-    }
-
-    private void assertHeadersMatchExpectation(final Map<String, String> actualHeaders,
-                                               final Map<String, String>  expectedHeaders)
-            throws TestingFrameworkException {
-        if (expectedHeaders == null) {
-            return;
-        }
-        for (Map.Entry<String, String> expectedHeader : ((Map<String, String>) expectedHeaders).entrySet()) {
-            final String expectedHeaderName = expectedHeader.getKey();
-            if (! actualHeaders.containsKey(expectedHeaderName)) {
-                throw new TestingFrameworkException("Expected header not found: name=" + expectedHeaderName);
-            }
-            if (! actualHeaders.get(expectedHeaderName).equals(expectedHeaders.get(expectedHeaderName))) {
-                throw new TestingFrameworkException("Header value not expected: name=" + expectedHeaderName
-                        + "; expected=" + expectedHeaders.get(expectedHeaderName)
-                        + "; actual=" + actualHeaders.get(expectedHeaderName));
-            }
-        }
-    }
-
-    private String getDefaultURI() {
-        return "http://localhost:" + port  + "/";
-    }
-
-    /**
-     * Sets the {@link ClientTestingAdapter}.
-     *
-     * @param adapter
-     */
-    public void setAdapter(final ClientTestingAdapter adapter) {
-        this.adapter = adapter;
-    }
-
-    /**
-     * Deletes all tests.
-     */
-    public void deleteTests() {
-        tests = new ArrayList<FrameworkTest>();
-    }
-
-    /**
-     * Call to add a test with defaults.
-     *
-     * @throws TestingFrameworkException
-     */
-    public void addTest() throws TestingFrameworkException {
-        addTest(null);
-    }
-
-    /**
-     * Call to add a test.  The test is a map with a REQUEST and a RESPONSE key.
-     * See {@link ClientPOJOAdapter} for details on the format of the request and response.
-     *
-     * @param test Map with a REQUEST and a RESPONSE key.
-     * @throws TestingFrameworkException
-     */
-    @SuppressWarnings("unchecked")
-    public void addTest(final Map<String, Object> test) throws TestingFrameworkException {
-        final Map<String, Object> testCopy = (Map<String, Object>) deepcopy(test);
-
-        tests.add(new FrameworkTest(testCopy));
-    }
-
-    /**
-     * Used to make a "deep" copy of an object.  This testing framework makes deep copies
-     * of tests that are added as well as requestExpectations Maps and response Maps.
-     *
-     * @param orig a serializable object.
-     * @return a deep copy of the orig object.
-     * @throws TestingFrameworkException
-     */
-    public static Object deepcopy(final Object orig) throws TestingFrameworkException {
-        try {
-            // this is from http://stackoverflow.com/questions/13155127/deep-copy-map-in-groovy
-            final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-            final ObjectOutputStream oos = new ObjectOutputStream(bos);
-            oos.writeObject(orig);
-            oos.flush();
-            final ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
-            final ObjectInputStream ois = new ObjectInputStream(bin);
-            return ois.readObject();
-        } catch (ClassNotFoundException | IOException e) {
-            throw new TestingFrameworkException(e);
-        }
-    }
-}
+/*
+ * ====================================================================
+ * 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.core5.testing.framework;
+
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.BODY;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.CONTENT_TYPE;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.HEADERS;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.METHOD;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.REQUEST;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.RESPONSE;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.STATUS;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hc.core5.http.HttpVersion;
+import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.config.SocketConfig;
+import org.apache.hc.core5.http.impl.io.bootstrap.HttpServer;
+import org.apache.hc.core5.http.impl.io.bootstrap.ServerBootstrap; public class TestingFramework {
+    /**
+     * Use the ALL_METHODS list to conveniently cycle through all HTTP methods.
+     */
+    public static final List<String> ALL_METHODS = Arrays.asList("HEAD", "GET", "DELETE", "POST", "PUT", "PATCH");
+
+    /**
+     * If an {@link ClassicTestClientTestingAdapter} is unable to return a response in
+     * the format this testing framework is needing, then it will need to check the
+     * item in the response (such as body, status, headers, or contentType) itself and set
+     * the returned value of the item as ALREADY_CHECKED.
+     */
+    public static final Object ALREADY_CHECKED = new Object();
+
+    /**
+     * If a test does not specify a path, this one is used.
+     */
+    public static final String DEFAULT_REQUEST_PATH = "a/path";
+
+    /**
+     * If a test does not specify a body, this one is used.
+     */
+    public static final String DEFAULT_REQUEST_BODY = "{\"location\":\"home\"}";
+
+    /**
+     * If a test does not specify a request contentType, this one is used.
+     */
+    public static final String DEFAULT_REQUEST_CONTENT_TYPE = "application/json";
+
+    /**
+     * If a test does not specify query parameters, these are used.
+     */
+    public static final Map<String, String> DEFAULT_REQUEST_QUERY;
+
+    /**
+     * If a test does not specify a request headers, these are used.
+     */
+    public static final Map<String, String> DEFAULT_REQUEST_HEADERS;
+
+    /**
+     * If a test does not specify a protocol version, this one is used.
+     */
+    public static final ProtocolVersion DEFAULT_REQUEST_PROTOCOL_VERSION = HttpVersion.HTTP_1_1;
+
+    /**
+     * If a test does not specify an expected response status, this one is used.
+     */
+    public static final int DEFAULT_RESPONSE_STATUS = 200;
+
+    /**
+     * If a test does not specify an expected response body, this one is used.
+     */
+    public static final String DEFAULT_RESPONSE_BODY = "{\"location\":\"work\"}";
+
+    /**
+     * If a test does not specify an expected response contentType, this one is used.
+     */
+    public static final String DEFAULT_RESPONSE_CONTENT_TYPE = "application/json";
+
+    /**
+     * If a test does not specify expected response headers, these are used.
+     */
+    public static final Map<String, String> DEFAULT_RESPONSE_HEADERS;
+
+    static {
+        final Map<String, String> request = new HashMap<String, String>();
+        request.put("p1", "this");
+        request.put("p2", "that");
+        DEFAULT_REQUEST_QUERY = Collections.unmodifiableMap(request);
+
+        Map<String, String> headers = new HashMap<String, String>();
+        headers.put("header1", "stuff");
+        headers.put("header2", "more stuff");
+        DEFAULT_REQUEST_HEADERS = Collections.unmodifiableMap(headers);
+
+        headers = new HashMap<String, String>();
+        headers.put("header3", "header_three");
+        headers.put("header4", "header_four");
+        DEFAULT_RESPONSE_HEADERS = Collections.unmodifiableMap(headers);
+    }
+
+    private ClientTestingAdapter adapter;
+    private TestingFrameworkRequestHandler requestHandler = new TestingFrameworkRequestHandler();
+    private List<FrameworkTest> tests = new ArrayList<FrameworkTest>();
+
+    private HttpServer server;
+    private int port;
+
+    public TestingFramework() throws TestingFrameworkException {
+        this(null);
+    }
+
+    public TestingFramework(final ClientTestingAdapter adapter) throws TestingFrameworkException {
+        this.adapter = adapter;
+
+        /*
+         * By default, a set of tests that will exercise each HTTP method are pre-loaded.
+         */
+        for (String method : ALL_METHODS) {
+            final List<Integer> statusList = Arrays.asList(200, 201);
+            for (Integer status : statusList) {
+                final Map<String, Object> request = new HashMap<String, Object>();
+                request.put(METHOD, method);
+
+                final Map<String, Object> response = new HashMap<String, Object>();
+                response.put(STATUS, status);
+
+                final Map<String, Object> test = new HashMap<String, Object>();
+                test.put(REQUEST, request);
+                test.put(RESPONSE, response);
+
+                addTest(test);
+            }
+        }
+    }
+
+    /**
+     * This is not likely to be used except during the testing of this class.
+     * It is used to inject a mocked request handler.
+     *
+     * @param requestHandler
+     */
+    public void setRequestHandler(final TestingFrameworkRequestHandler requestHandler) {
+        this.requestHandler = requestHandler;
+    }
+
+    /**
+     * Run the tests that have been previously added.  First, an in-process {@link HttpServer} is
+     * started.  Then, all the tests are completed by passing each test to the adapter
+     * which will make the HTTP request.
+     *
+     * @throws TestingFrameworkException if there is a test failure or unexpected problem.
+     */
+    public void runTests() throws TestingFrameworkException {
+        if (adapter == null) {
+            throw new TestingFrameworkException("adapter should not be null");
+        }
+
+        startServer();
+
+        try {
+            for (FrameworkTest test : tests) {
+                try {
+                    callAdapter(test);
+                } catch (Throwable t) {
+                    processThrowable(t, test);
+                }
+            }
+        } finally {
+            stopServer();
+        }
+    }
+
+    private void processThrowable(final Throwable t, final FrameworkTest test) throws TestingFrameworkException {
+        final TestingFrameworkException e;
+        if (t instanceof TestingFrameworkException) {
+            e = (TestingFrameworkException) t;
+        } else {
+            e = new TestingFrameworkException(t);
+        }
+        e.setAdapter(adapter);
+        e.setTest(test);
+        throw e;
+    }
+
+    private void startServer() throws TestingFrameworkException {
+        /*
+         * Start an in-process server and handle all HTTP requests
+         * with the requestHandler.
+         */
+        final SocketConfig socketConfig = SocketConfig.custom()
+                                          .setSoTimeout(15000)
+                                          .build();
+
+        final ServerBootstrap serverBootstrap = ServerBootstrap.bootstrap()
+                                          .setSocketConfig(socketConfig)
+                                          .registerHandler("/*", requestHandler);
+
+        server = serverBootstrap.create();
+        try {
+            server.start();
+        } catch (IOException e) {
+            throw new TestingFrameworkException(e);
+        }
+
+        port = server.getLocalPort();
+    }
+
+    private void stopServer() {
+        if (server != null) {
+            server.shutdown(0, TimeUnit.SECONDS);
+            server = null;
+        }
+    }
+
+    private void callAdapter(final FrameworkTest test) throws TestingFrameworkException {
+        Map<String, Object> request = test.initRequest();
+
+        /*
+         * If the adapter does not support the particular request, skip the test.
+         */
+        if (! adapter.isRequestSupported(request)) {
+            return;
+        }
+
+        /*
+         * Allow the adapter to modify the request before the request expectations
+         * are given to the requestHandler.  Typically, adapters should not have
+         * to modify the request.
+         */
+        request = adapter.modifyRequest(request);
+
+        // Tell the request handler what to expect in the request.
+        requestHandler.setRequestExpectations(request);
+
+        Map<String, Object> responseExpectations = test.initResponseExpectations();
+        /*
+         * Allow the adapter to modify the response expectations before the handler
+         * is told what to return.  Typically, adapters should not have to modify
+         * the response expectations.
+         */
+        responseExpectations = adapter.modifyResponseExpectations(request, responseExpectations);
+
+        // Tell the request handler what response to return.
+        requestHandler.setDesiredResponse(responseExpectations);
+
+        /*
+         * Use the adapter to make the HTTP call.  Make sure the responseExpectations are not changed
+         * since they have already been sent to the request handler and they will later be used
+         * to check the response.
+         */
+        final String defaultURI = getDefaultURI();
+        final Map<String, Object> response = adapter.execute(
+                                                defaultURI,
+                                                request,
+                                                requestHandler,
+                                                Collections.unmodifiableMap(responseExpectations));
+        /*
+         * The adapter is welcome to call assertNothingThrown() earlier, but we will
+         * do it here to make sure it is done.  If the handler threw any exception
+         * while checking the request it received, it will be re-thrown here.
+         */
+        requestHandler.assertNothingThrown();
+
+        assertResponseMatchesExpectation(request.get(METHOD), response, responseExpectations);
+    }
+
+    @SuppressWarnings("unchecked")
+    private void assertResponseMatchesExpectation(final Object method, final Map<String, Object> actualResponse,
+                                                  final Map<String, Object> expectedResponse)
+                                                  throws TestingFrameworkException {
+        if (actualResponse == null) {
+            throw new TestingFrameworkException("response should not be null");
+        }
+        /*
+         * Now check the items in the response unless the adapter says they
+         * already checked something.
+         */
+        if (actualResponse.get(STATUS) != TestingFramework.ALREADY_CHECKED) {
+            assertStatusMatchesExpectation(actualResponse.get(STATUS), expectedResponse.get(STATUS));
+        }
+        if (! method.equals("HEAD")) {
+            if (actualResponse.get(BODY) != TestingFramework.ALREADY_CHECKED) {
+                assertBodyMatchesExpectation(actualResponse.get(BODY), expectedResponse.get(BODY));
+            }
+            if (actualResponse.get(CONTENT_TYPE) != TestingFramework.ALREADY_CHECKED) {
+                assertContentTypeMatchesExpectation(actualResponse.get(CONTENT_TYPE), expectedResponse.get(CONTENT_TYPE));
+            }
+        }
+        if (actualResponse.get(HEADERS) != TestingFramework.ALREADY_CHECKED) {
+            assertHeadersMatchExpectation((Map<String, String>) actualResponse.get(HEADERS),
+                                          (Map<String, String>) expectedResponse.get(HEADERS));
+        }
+    }
+
+    private void assertStatusMatchesExpectation(final Object actualStatus, final Object expectedStatus)
+            throws TestingFrameworkException {
+        if (actualStatus == null) {
+            throw new TestingFrameworkException("Returned status is null.");
+        }
+        if ((expectedStatus != null) && (! actualStatus.equals(expectedStatus))) {
+            throw new TestingFrameworkException("Expected status not found. expected="
+                                                  + expectedStatus + "; actual=" + actualStatus);
+        }
+    }
+
+    private void assertBodyMatchesExpectation(final Object actualBody, final Object expectedBody)
+        throws TestingFrameworkException {
+        if (actualBody == null) {
+            throw new TestingFrameworkException("Returned body is null.");
+        }
+        if ((expectedBody != null) && (! actualBody.equals(expectedBody))) {
+            throw new TestingFrameworkException("Expected body not found. expected="
+                                    + expectedBody + "; actual=" + actualBody);
+        }
+    }
+
+    private void assertContentTypeMatchesExpectation(final Object actualContentType, final Object expectedContentType)
+        throws TestingFrameworkException {
+        if (expectedContentType != null) {
+            if (actualContentType == null) {
+                throw new TestingFrameworkException("Returned contentType is null.");
+            }
+            if (! actualContentType.equals(expectedContentType)) {
+                throw new TestingFrameworkException("Expected content type not found.  expected="
+                                    + expectedContentType + "; actual=" + actualContentType);
+            }
+        }
+    }
+
+    private void assertHeadersMatchExpectation(final Map<String, String> actualHeaders,
+                                               final Map<String, String>  expectedHeaders)
+            throws TestingFrameworkException {
+        if (expectedHeaders == null) {
+            return;
+        }
+        for (Map.Entry<String, String> expectedHeader : ((Map<String, String>) expectedHeaders).entrySet()) {
+            final String expectedHeaderName = expectedHeader.getKey();
+            if (! actualHeaders.containsKey(expectedHeaderName)) {
+                throw new TestingFrameworkException("Expected header not found: name=" + expectedHeaderName);
+            }
+            if (! actualHeaders.get(expectedHeaderName).equals(expectedHeaders.get(expectedHeaderName))) {
+                throw new TestingFrameworkException("Header value not expected: name=" + expectedHeaderName
+                        + "; expected=" + expectedHeaders.get(expectedHeaderName)
+                        + "; actual=" + actualHeaders.get(expectedHeaderName));
+            }
+        }
+    }
+
+    private String getDefaultURI() {
+        return "http://localhost:" + port  + "/";
+    }
+
+    /**
+     * Sets the {@link ClientTestingAdapter}.
+     *
+     * @param adapter
+     */
+    public void setAdapter(final ClientTestingAdapter adapter) {
+        this.adapter = adapter;
+    }
+
+    /**
+     * Deletes all tests.
+     */
+    public void deleteTests() {
+        tests = new ArrayList<FrameworkTest>();
+    }
+
+    /**
+     * Call to add a test with defaults.
+     *
+     * @throws TestingFrameworkException
+     */
+    public void addTest() throws TestingFrameworkException {
+        addTest(null);
+    }
+
+    /**
+     * Call to add a test.  The test is a map with a REQUEST and a RESPONSE key.
+     * See {@link ClientPOJOAdapter} for details on the format of the request and response.
+     *
+     * @param test Map with a REQUEST and a RESPONSE key.
+     * @throws TestingFrameworkException
+     */
+    @SuppressWarnings("unchecked")
+    public void addTest(final Map<String, Object> test) throws TestingFrameworkException {
+        final Map<String, Object> testCopy = (Map<String, Object>) deepcopy(test);
+
+        tests.add(new FrameworkTest(testCopy));
+    }
+
+    /**
+     * Used to make a "deep" copy of an object.  This testing framework makes deep copies
+     * of tests that are added as well as requestExpectations Maps and response Maps.
+     *
+     * @param orig a serializable object.
+     * @return a deep copy of the orig object.
+     * @throws TestingFrameworkException
+     */
+    public static Object deepcopy(final Object orig) throws TestingFrameworkException {
+        try {
+            // this is from http://stackoverflow.com/questions/13155127/deep-copy-map-in-groovy
+            final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            final ObjectOutputStream oos = new ObjectOutputStream(bos);
+            oos.writeObject(orig);
+            oos.flush();
+            final ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
+            final ObjectInputStream ois = new ObjectInputStream(bin);
+            return ois.readObject();
+        } catch (ClassNotFoundException | IOException e) {
+            throw new TestingFrameworkException(e);
+        }
+    }
+}

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFrameworkException.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFrameworkException.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFrameworkException.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFrameworkException.java Mon Oct 31 22:21:30 2016
@@ -1,91 +1,81 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.hc.core5.testing.framework;
-
-
-/**
- * <p>Signals a problem or an assertion failure while using the {@link TestingFramework}.</p>
- *
- * <p>Optionally, an adapter and a test can be added to the exception.  If this is done,
- * the adapter name and the test information is appended to the exception message to help
- * determine what test is having a problem.</p>
- *
- * @since 5.0
- */
-public class TestingFrameworkException extends Exception {
-    public static final String NO_HTTP_CLIENT = "none";
-
-    private ClientTestingAdapter adapter;
-
-    private FrameworkTest test;
-
-    /**
-     *
-     */
-    private static final long serialVersionUID = -1010516169283589675L;
-
-    /**
-     * Creates a WebServerTestingFrameworkException with the specified detail message.
-     */
-    public TestingFrameworkException(final String message) {
-        super(message);
-    }
-
-    public TestingFrameworkException(final Throwable cause) {
-        super(cause);
-    }
-
-    @Override
-    public String getMessage() {
-        String message = super.getMessage();
-        if (adapter != null) {
-            final ClientPOJOAdapter pojoAdapter = adapter.getClientPOJOAdapter();
-            final String tempHttpClient = pojoAdapter == null ? null : pojoAdapter.getClientName();
-            final String httpClient = tempHttpClient == null ? NO_HTTP_CLIENT : tempHttpClient;
-            if (message == null) {
-                message = "null";
-            }
-            message += "\nHTTP Client=" + httpClient;
-        }
-        if (test != null) {
-            if (message == null) {
-                message = "null";
-            }
-            message += "\ntest:\n" + test;
-        }
-        return message;
-    }
-
-    public void setAdapter(final ClientTestingAdapter adapter) {
-        this.adapter = adapter;
-    }
-
-    public void setTest(final FrameworkTest test) {
-        this.test = test;
-    }
-}
+/*
+ * ====================================================================
+ * 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.core5.testing.framework;
+
+public class TestingFrameworkException extends Exception {
+    public static final String NO_HTTP_CLIENT = "none";
+
+    private ClientTestingAdapter adapter;
+
+    private FrameworkTest test;
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = -1010516169283589675L;
+
+    /**
+     * Creates a WebServerTestingFrameworkException with the specified detail message.
+     */
+    public TestingFrameworkException(final String message) {
+        super(message);
+    }
+
+    public TestingFrameworkException(final Throwable cause) {
+        super(cause);
+    }
+
+    @Override
+    public String getMessage() {
+        String message = super.getMessage();
+        if (adapter != null) {
+            final ClientPOJOAdapter pojoAdapter = adapter.getClientPOJOAdapter();
+            final String tempHttpClient = pojoAdapter == null ? null : pojoAdapter.getClientName();
+            final String httpClient = tempHttpClient == null ? NO_HTTP_CLIENT : tempHttpClient;
+            if (message == null) {
+                message = "null";
+            }
+            message += "\nHTTP Client=" + httpClient;
+        }
+        if (test != null) {
+            if (message == null) {
+                message = "null";
+            }
+            message += "\ntest:\n" + test;
+        }
+        return message;
+    }
+
+    public void setAdapter(final ClientTestingAdapter adapter) {
+        this.adapter = adapter;
+    }
+
+    public void setTest(final FrameworkTest test) {
+        this.test = test;
+    }
+}

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFrameworkRequestHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFrameworkRequestHandler.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFrameworkRequestHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFrameworkRequestHandler.java Mon Oct 31 22:21:30 2016
@@ -1,267 +1,251 @@
-/*
- * ====================================================================
- * 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.core5.testing.framework;
-
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.BODY;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.CONTENT_TYPE;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.HEADERS;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.METHOD;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.PROTOCOL_VERSION;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.QUERY;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.STATUS;
-
-import java.io.IOException;
-import java.net.URI;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.ClassicHttpResponse;
-import org.apache.hc.core5.http.Header;
-import org.apache.hc.core5.http.HttpEntity;
-import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.NameValuePair;
-import org.apache.hc.core5.http.ProtocolVersion;
-import org.apache.hc.core5.http.io.HttpRequestHandler;
-import org.apache.hc.core5.http.io.entity.ContentType;
-import org.apache.hc.core5.http.io.entity.EntityUtils;
-import org.apache.hc.core5.http.io.entity.StringEntity;
-import org.apache.hc.core5.http.protocol.HttpContext;
-import org.apache.hc.core5.util.URLEncodedUtils;
-
-/**
- * <p>This request handler is used with an in-process instance of HttpServer during testing.
- * The handler is told what to expect in the request.  If the request does not match
- * the expectations, the handler will throw an exception which is then caught and
- * saved in the "thrown" member.  The testing framework will later call assertNothingThrown().
- * If something was thrown earlier by the handler, an exception will be thrown by the method.</p>
- *
- * <p>The handler is also told what response to return.</p>
- *
- * <p>See {@link ClientPOJOAdapter} for details on the format of the request and response.</p>
- *
- * @since 5.0
- *
- */
-public class TestingFrameworkRequestHandler implements HttpRequestHandler {
-    protected Throwable thrown;
-    protected Map<String, Object> requestExpectations;
-    protected Map<String, Object> desiredResponse;
-
-    /**
-     * Sets the request expectations.
-     *
-     * @param requestExpectations the expected values of the request.
-     * @throws TestingFrameworkException
-     */
-    @SuppressWarnings("unchecked")
-    public void setRequestExpectations(final Map<String, Object> requestExpectations) throws TestingFrameworkException {
-        this.requestExpectations = (Map<String, Object>) TestingFramework.deepcopy(requestExpectations);
-    }
-
-    /**
-     * Sets the desired response.  The handler will return a response that matches this.
-     *
-     * @param desiredResponse the desired response.
-     * @throws TestingFrameworkException
-     */
-    @SuppressWarnings("unchecked")
-    public void setDesiredResponse(final Map<String, Object> desiredResponse) throws TestingFrameworkException {
-        this.desiredResponse = (Map<String, Object>) TestingFramework.deepcopy(desiredResponse);
-    }
-
-    /**
-     * After the handler returns the response, any exception or failed assertion will be
-     * in the member called "thrown".  A testing framework can later call this method
-     * which will rethrow the exception that was thrown before.
-     *
-     * @throws TestingFrameworkException
-     */
-    public void assertNothingThrown() throws TestingFrameworkException {
-        if (thrown != null) {
-            final TestingFrameworkException e = (thrown instanceof TestingFrameworkException ?
-                                                          (TestingFrameworkException) thrown :
-                                                          new TestingFrameworkException(thrown));
-            thrown = null;
-            throw e;
-        }
-    }
-
-    /**
-     * <p>Checks the HTTP request against the requestExpectations that it was previously given.
-     * If there is a mismatch, an exception will be saved in the "thrown" member.</p>
-     *
-     * <p>Also, a response will be returned that matches the desiredResponse.</p>
-     */
-    @Override
-    public void handle(final ClassicHttpRequest request, final ClassicHttpResponse response, final HttpContext context)
-            throws HttpException, IOException {
-
-        try {
-            /*
-             * Check the method against the method in the requestExpectations.
-             */
-            final String actualMethod = request.getMethod();
-            final String expectedMethod = (String) requestExpectations.get(METHOD);
-            if (! actualMethod.equals(expectedMethod)) {
-                throw new TestingFrameworkException("Method not expected. " +
-                    " expected=" + expectedMethod + "; actual=" + actualMethod);
-            }
-
-            /*
-             * Set the status to the status that is in the desiredResponse.
-             */
-            final Object desiredStatus = desiredResponse.get(STATUS);
-            if (desiredStatus != null) {
-                response.setCode((int) desiredStatus);
-            }
-
-            /*
-             * Check the query parameters against the parameters in requestExpectations.
-             */
-            @SuppressWarnings("unchecked")
-            final Map<String, String> expectedQuery = (Map<String, String>) requestExpectations.get(QUERY);
-            if (expectedQuery != null) {
-                final URI uri = request.getUri();
-                final List<NameValuePair> actualParams = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8);
-                final Map<String, String> actualParamsMap = new HashMap<String, String>();
-                for (NameValuePair actualParam : actualParams) {
-                    actualParamsMap.put(actualParam.getName(), actualParam.getValue());
-                }
-                for (Map.Entry<String, String> expectedParam : expectedQuery.entrySet()) {
-                    final String key = expectedParam.getKey();
-                    if (! actualParamsMap.containsKey(key)) {
-                        throw new TestingFrameworkException("Expected parameter not found: " + key);
-                    }
-                    final String actualParamValue = actualParamsMap.get(key);
-                    final String expectedParamValue = expectedParam.getValue();
-                    if (! actualParamValue.equals(expectedParamValue)) {
-                        throw new TestingFrameworkException("Expected parameter value not found. " +
-                            " Parameter=" + key + "; expected=" + expectedParamValue + "; actual=" + actualParamValue);
-                    }
-                }
-            }
-
-            /*
-             * Check the headers against the headers in requestExpectations.
-             */
-            @SuppressWarnings("unchecked")
-            final Map<String, String> expectedHeaders = (Map<String, String>) requestExpectations.get(HEADERS);
-            if (expectedHeaders != null) {
-                final Map<String, String> actualHeadersMap = new HashMap<String, String>();
-                final Header[] actualHeaders = request.getAllHeaders();
-                for (Header header : actualHeaders) {
-                    actualHeadersMap.put(header.getName(), header.getValue());
-                }
-                for (Entry<String, String> expectedHeader : expectedHeaders.entrySet()) {
-                    final String key = expectedHeader.getKey();
-                    if (! actualHeadersMap.containsKey(key)) {
-                        throw new TestingFrameworkException("Expected header not found: " + key);
-                    }
-                    final String actualHeaderValue = actualHeadersMap.get(key);
-                    final String expectedHeaderValue = expectedHeader.getValue();
-                    if (! actualHeaderValue.equals(expectedHeaderValue)) {
-                        throw new TestingFrameworkException("Expected header value not found. " +
-                                " Name=" + key + "; expected=" + expectedHeaderValue + "; actual=" + actualHeaderValue);
-                    }
-                }
-            }
-
-            /*
-             * Check the body.
-             */
-            final String expectedBody = (String) requestExpectations.get(BODY);
-            if (expectedBody != null) {
-                final HttpEntity entity = request.getEntity();
-                final String data = EntityUtils.toString(entity);
-                if (! data.equals(expectedBody)) {
-                    throw new TestingFrameworkException("Expected body not found. " +
-                            " Body=" + data + "; expected=" + expectedBody);
-                }
-            }
-
-            /*
-             * Check the contentType of the request.
-             */
-            final String requestContentType = (String) requestExpectations.get(CONTENT_TYPE);
-            if (requestContentType != null) {
-                final HttpEntity entity = request.getEntity();
-                final String contentType = entity.getContentType();
-                final String expectedContentType = (String) requestExpectations.get(CONTENT_TYPE);
-                if (! contentType.equals(expectedContentType)) {
-                    throw new TestingFrameworkException("Expected request content type not found. " +
-                            " Content Type=" + contentType + "; expected=" + expectedContentType);
-                }
-            }
-
-            /*
-             * Check the protocolVersion.
-             */
-            if (requestExpectations.containsKey(PROTOCOL_VERSION)) {
-                final ProtocolVersion protocolVersion = request.getVersion();
-                final ProtocolVersion expectedProtocolVersion = (ProtocolVersion) requestExpectations.get(PROTOCOL_VERSION);
-                if (! protocolVersion.equals(expectedProtocolVersion)) {
-                    throw new TestingFrameworkException("Expected request protocol version not found. " +
-                            " Protocol Version=" + protocolVersion + "; expected=" + expectedProtocolVersion);
-                }
-            }
-
-            /*
-             * Return the body in desiredResponse using the contentType in desiredResponse.
-             */
-            final String desiredBody = (String) desiredResponse.get(BODY);
-            if (desiredBody != null) {
-                final String desiredContentType = (String) desiredResponse.get(CONTENT_TYPE);
-                final StringEntity entity = desiredContentType != null ?
-                                new StringEntity(desiredBody, ContentType.parse(desiredContentType)) :
-                                new StringEntity(desiredBody);
-                response.setEntity(entity);
-            }
-
-            /*
-             * Return the headers in desiredResponse.
-             */
-            @SuppressWarnings("unchecked")
-            final Map<String, String> desiredHeaders = (Map<String, String>) desiredResponse.get(HEADERS);
-            if (desiredHeaders != null) {
-                for (Entry<String, String> entry : desiredHeaders.entrySet()) {
-                    response.setHeader(entry.getKey(), entry.getValue());
-                }
-            }
-
-        } catch (Throwable t) {
-            /*
-             * Save the throwable to be later retrieved by a call to assertNothingThrown().
-             */
-            thrown = t;
-        }
-    }
-}
+/*
+ * ====================================================================
+ * 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.core5.testing.framework;
+
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.BODY;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.CONTENT_TYPE;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.HEADERS;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.METHOD;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.PROTOCOL_VERSION;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.QUERY;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.STATUS;
+
+import java.io.IOException;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.NameValuePair;
+import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.io.HttpRequestHandler;
+import org.apache.hc.core5.http.io.entity.ContentType;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.util.URLEncodedUtils; public class TestingFrameworkRequestHandler implements HttpRequestHandler {
+    protected Throwable thrown;
+    protected Map<String, Object> requestExpectations;
+    protected Map<String, Object> desiredResponse;
+
+    /**
+     * Sets the request expectations.
+     *
+     * @param requestExpectations the expected values of the request.
+     * @throws TestingFrameworkException
+     */
+    @SuppressWarnings("unchecked")
+    public void setRequestExpectations(final Map<String, Object> requestExpectations) throws TestingFrameworkException {
+        this.requestExpectations = (Map<String, Object>) TestingFramework.deepcopy(requestExpectations);
+    }
+
+    /**
+     * Sets the desired response.  The handler will return a response that matches this.
+     *
+     * @param desiredResponse the desired response.
+     * @throws TestingFrameworkException
+     */
+    @SuppressWarnings("unchecked")
+    public void setDesiredResponse(final Map<String, Object> desiredResponse) throws TestingFrameworkException {
+        this.desiredResponse = (Map<String, Object>) TestingFramework.deepcopy(desiredResponse);
+    }
+
+    /**
+     * After the handler returns the response, any exception or failed assertion will be
+     * in the member called "thrown".  A testing framework can later call this method
+     * which will rethrow the exception that was thrown before.
+     *
+     * @throws TestingFrameworkException
+     */
+    public void assertNothingThrown() throws TestingFrameworkException {
+        if (thrown != null) {
+            final TestingFrameworkException e = (thrown instanceof TestingFrameworkException ?
+                                                          (TestingFrameworkException) thrown :
+                                                          new TestingFrameworkException(thrown));
+            thrown = null;
+            throw e;
+        }
+    }
+
+    /**
+     * <p>Checks the HTTP request against the requestExpectations that it was previously given.
+     * If there is a mismatch, an exception will be saved in the "thrown" member.</p>
+     *
+     * <p>Also, a response will be returned that matches the desiredResponse.</p>
+     */
+    @Override
+    public void handle(final ClassicHttpRequest request, final ClassicHttpResponse response, final HttpContext context)
+            throws HttpException, IOException {
+
+        try {
+            /*
+             * Check the method against the method in the requestExpectations.
+             */
+            final String actualMethod = request.getMethod();
+            final String expectedMethod = (String) requestExpectations.get(METHOD);
+            if (! actualMethod.equals(expectedMethod)) {
+                throw new TestingFrameworkException("Method not expected. " +
+                    " expected=" + expectedMethod + "; actual=" + actualMethod);
+            }
+
+            /*
+             * Set the status to the status that is in the desiredResponse.
+             */
+            final Object desiredStatus = desiredResponse.get(STATUS);
+            if (desiredStatus != null) {
+                response.setCode((int) desiredStatus);
+            }
+
+            /*
+             * Check the query parameters against the parameters in requestExpectations.
+             */
+            @SuppressWarnings("unchecked")
+            final Map<String, String> expectedQuery = (Map<String, String>) requestExpectations.get(QUERY);
+            if (expectedQuery != null) {
+                final URI uri = request.getUri();
+                final List<NameValuePair> actualParams = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8);
+                final Map<String, String> actualParamsMap = new HashMap<String, String>();
+                for (NameValuePair actualParam : actualParams) {
+                    actualParamsMap.put(actualParam.getName(), actualParam.getValue());
+                }
+                for (Map.Entry<String, String> expectedParam : expectedQuery.entrySet()) {
+                    final String key = expectedParam.getKey();
+                    if (! actualParamsMap.containsKey(key)) {
+                        throw new TestingFrameworkException("Expected parameter not found: " + key);
+                    }
+                    final String actualParamValue = actualParamsMap.get(key);
+                    final String expectedParamValue = expectedParam.getValue();
+                    if (! actualParamValue.equals(expectedParamValue)) {
+                        throw new TestingFrameworkException("Expected parameter value not found. " +
+                            " Parameter=" + key + "; expected=" + expectedParamValue + "; actual=" + actualParamValue);
+                    }
+                }
+            }
+
+            /*
+             * Check the headers against the headers in requestExpectations.
+             */
+            @SuppressWarnings("unchecked")
+            final Map<String, String> expectedHeaders = (Map<String, String>) requestExpectations.get(HEADERS);
+            if (expectedHeaders != null) {
+                final Map<String, String> actualHeadersMap = new HashMap<String, String>();
+                final Header[] actualHeaders = request.getAllHeaders();
+                for (Header header : actualHeaders) {
+                    actualHeadersMap.put(header.getName(), header.getValue());
+                }
+                for (Entry<String, String> expectedHeader : expectedHeaders.entrySet()) {
+                    final String key = expectedHeader.getKey();
+                    if (! actualHeadersMap.containsKey(key)) {
+                        throw new TestingFrameworkException("Expected header not found: " + key);
+                    }
+                    final String actualHeaderValue = actualHeadersMap.get(key);
+                    final String expectedHeaderValue = expectedHeader.getValue();
+                    if (! actualHeaderValue.equals(expectedHeaderValue)) {
+                        throw new TestingFrameworkException("Expected header value not found. " +
+                                " Name=" + key + "; expected=" + expectedHeaderValue + "; actual=" + actualHeaderValue);
+                    }
+                }
+            }
+
+            /*
+             * Check the body.
+             */
+            final String expectedBody = (String) requestExpectations.get(BODY);
+            if (expectedBody != null) {
+                final HttpEntity entity = request.getEntity();
+                final String data = EntityUtils.toString(entity);
+                if (! data.equals(expectedBody)) {
+                    throw new TestingFrameworkException("Expected body not found. " +
+                            " Body=" + data + "; expected=" + expectedBody);
+                }
+            }
+
+            /*
+             * Check the contentType of the request.
+             */
+            final String requestContentType = (String) requestExpectations.get(CONTENT_TYPE);
+            if (requestContentType != null) {
+                final HttpEntity entity = request.getEntity();
+                final String contentType = entity.getContentType();
+                final String expectedContentType = (String) requestExpectations.get(CONTENT_TYPE);
+                if (! contentType.equals(expectedContentType)) {
+                    throw new TestingFrameworkException("Expected request content type not found. " +
+                            " Content Type=" + contentType + "; expected=" + expectedContentType);
+                }
+            }
+
+            /*
+             * Check the protocolVersion.
+             */
+            if (requestExpectations.containsKey(PROTOCOL_VERSION)) {
+                final ProtocolVersion protocolVersion = request.getVersion();
+                final ProtocolVersion expectedProtocolVersion = (ProtocolVersion) requestExpectations.get(PROTOCOL_VERSION);
+                if (! protocolVersion.equals(expectedProtocolVersion)) {
+                    throw new TestingFrameworkException("Expected request protocol version not found. " +
+                            " Protocol Version=" + protocolVersion + "; expected=" + expectedProtocolVersion);
+                }
+            }
+
+            /*
+             * Return the body in desiredResponse using the contentType in desiredResponse.
+             */
+            final String desiredBody = (String) desiredResponse.get(BODY);
+            if (desiredBody != null) {
+                final String desiredContentType = (String) desiredResponse.get(CONTENT_TYPE);
+                final StringEntity entity = desiredContentType != null ?
+                                new StringEntity(desiredBody, ContentType.parse(desiredContentType)) :
+                                new StringEntity(desiredBody);
+                response.setEntity(entity);
+            }
+
+            /*
+             * Return the headers in desiredResponse.
+             */
+            @SuppressWarnings("unchecked")
+            final Map<String, String> desiredHeaders = (Map<String, String>) desiredResponse.get(HEADERS);
+            if (desiredHeaders != null) {
+                for (Entry<String, String> entry : desiredHeaders.entrySet()) {
+                    response.setHeader(entry.getKey(), entry.getValue());
+                }
+            }
+
+        } catch (Throwable t) {
+            /*
+             * Save the throwable to be later retrieved by a call to assertNothingThrown().
+             */
+            thrown = t;
+        }
+    }
+}

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java Mon Oct 31 22:21:30 2016
@@ -30,22 +30,21 @@ package org.apache.hc.core5.testing.nio;
 import java.io.IOException;
 import java.net.SocketAddress;
 
-import org.apache.commons.logging.Log;
 import org.apache.hc.core5.http.HttpConnectionMetrics;
 import org.apache.hc.core5.http.ProtocolVersion;
 import org.apache.hc.core5.http.impl.nio.HttpConnectionEventHandler;
 import org.apache.hc.core5.reactor.IOSession;
-
+import org.apache.logging.log4j.Logger;
 public class LoggingIOEventHandler implements HttpConnectionEventHandler {
 
     private final HttpConnectionEventHandler handler;
     private final String id;
-    private final Log log;
+    private final Logger log;
 
     public LoggingIOEventHandler(
             final HttpConnectionEventHandler handler,
             final String id,
-            final Log log) {
+            final Logger log) {
         super();
         this.handler = handler;
         this.id = id;

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java Mon Oct 31 22:21:30 2016
@@ -34,26 +34,20 @@ import java.nio.channels.ByteChannel;
 import java.nio.channels.SelectionKey;
 import java.util.Deque;
 
-import org.apache.commons.logging.Log;
 import org.apache.hc.core5.reactor.Command;
 import org.apache.hc.core5.reactor.IOEventHandler;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.testing.classic.Wire;
-
-/**
- * Decorator class intended to transparently extend an {@link IOSession}
- * with basic event logging capabilities using Commons Logging.
- *
- */
+import org.apache.logging.log4j.Logger;
 public class LoggingIOSession implements IOSession {
 
-    private final Log log;
+    private final Logger log;
     private final Wire wirelog;
     private final String id;
     private final IOSession session;
     private final ByteChannel channel;
 
-    public LoggingIOSession(final IOSession session, final String id, final Log log, final Log wirelog) {
+    public LoggingIOSession(final IOSession session, final String id, final Logger log, final Logger wirelog) {
         super();
         this.session = session;
         this.id = id;
@@ -62,7 +56,7 @@ public class LoggingIOSession implements
         this.channel = wirelog != null ? new LoggingByteChannel() : session.channel();
     }
 
-    public LoggingIOSession(final IOSession session, final String id, final Log log) {
+    public LoggingIOSession(final IOSession session, final String id, final Logger log) {
         this(session, id, log, null);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java Mon Oct 31 22:21:30 2016
@@ -34,8 +34,6 @@ import java.nio.channels.SelectionKey;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.hc.core5.concurrent.BasicFuture;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.http.ExceptionListener;
@@ -54,13 +52,14 @@ import org.apache.hc.core5.reactor.IOSes
 import org.apache.hc.core5.reactor.IOSessionCallback;
 import org.apache.hc.core5.reactor.SessionRequest;
 import org.apache.hc.core5.reactor.SessionRequestCallback;
-
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 public class Http1TestClient extends AsyncRequester {
 
     public Http1TestClient(final IOReactorConfig ioReactorConfig) throws IOException {
         super(ioReactorConfig, new ExceptionListener() {
 
-            private final Log log = LogFactory.getLog(Http1TestClient.class);
+            private final Logger log = LogManager.getLogger(Http1TestClient.class);
 
             @Override
             public void onError(final Exception ex) {

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestServer.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestServer.java Mon Oct 31 22:21:30 2016
@@ -31,8 +31,6 @@ import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.nio.channels.SelectionKey;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.config.ConnectionConfig;
 import org.apache.hc.core5.http.config.H1Config;
@@ -53,7 +51,8 @@ import org.apache.hc.core5.reactor.IORea
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.IOSessionCallback;
 import org.apache.hc.core5.reactor.ListenerEndpoint;
-
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 public class Http1TestServer extends AsyncServer {
 
     private final AsyncServerExchangeHandlerRegistry handlerRegistry;
@@ -61,7 +60,7 @@ public class Http1TestServer extends Asy
     public Http1TestServer(final IOReactorConfig ioReactorConfig) throws IOException {
         super(ioReactorConfig, new ExceptionListener() {
 
-            private final Log log = LogFactory.getLog(Http1TestServer.class);
+            private final Logger log = LogManager.getLogger(Http1TestServer.class);
 
             @Override
             public void onError(final Exception ex) {

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalClientHttp1EventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalClientHttp1EventHandlerFactory.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalClientHttp1EventHandlerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalClientHttp1EventHandlerFactory.java Mon Oct 31 22:21:30 2016
@@ -30,8 +30,6 @@ package org.apache.hc.core5.testing.nio.
 import java.util.Iterator;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.ConnectionClosedException;
@@ -63,6 +61,8 @@ import org.apache.hc.core5.reactor.IOSes
 import org.apache.hc.core5.testing.nio.LoggingIOEventHandler;
 import org.apache.hc.core5.testing.nio.LoggingIOSession;
 import org.apache.hc.core5.util.Args;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 
 /**
  * @since 5.0
@@ -110,9 +110,9 @@ class InternalClientHttp1EventHandlerFac
     @Override
     public IOEventHandler createHandler(final IOSession ioSession) {
         final String id = "http1-outgoing-" + COUNT.incrementAndGet();
-        final Log sessionLog = LogFactory.getLog(ioSession.getClass());
-        final Log wireLog = LogFactory.getLog("org.apache.hc.core5.http.wire");
-        final Log headerLog = LogFactory.getLog("org.apache.hc.core5.http.headers");
+        final Logger sessionLog = LogManager.getLogger(ioSession.getClass());
+        final Logger wireLog = LogManager.getLogger("org.apache.hc.core5.http.wire");
+        final Logger headerLog = LogManager.getLogger("org.apache.hc.core5.http.headers");
         final ClientHttp1StreamDuplexer streamDuplexer = createClientHttp1StreamDuplexer(
                 new LoggingIOSession(ioSession, id, sessionLog, wireLog),
                 httpProcessor,

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalServerHttp1EventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalServerHttp1EventHandlerFactory.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalServerHttp1EventHandlerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalServerHttp1EventHandlerFactory.java Mon Oct 31 22:21:30 2016
@@ -30,8 +30,6 @@ package org.apache.hc.core5.testing.nio.
 import java.util.Iterator;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.ConnectionClosedException;
@@ -65,11 +63,12 @@ import org.apache.hc.core5.reactor.IOSes
 import org.apache.hc.core5.testing.nio.LoggingIOEventHandler;
 import org.apache.hc.core5.testing.nio.LoggingIOSession;
 import org.apache.hc.core5.util.Args;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger; @Contract(threading = ThreadingBehavior.IMMUTABLE)
 
 /**
  * @since 5.0
  */
-@Contract(threading = ThreadingBehavior.IMMUTABLE)
 class InternalServerHttp1EventHandlerFactory implements IOEventHandlerFactory {
 
     private static final AtomicLong COUNT = new AtomicLong();
@@ -115,9 +114,9 @@ class InternalServerHttp1EventHandlerFac
     @Override
     public IOEventHandler createHandler(final IOSession ioSession) {
         final String id = "http1-incoming-" + COUNT.incrementAndGet();
-        final Log sessionLog = LogFactory.getLog(ioSession.getClass());
-        final Log wireLog = LogFactory.getLog("org.apache.hc.core5.http.wire");
-        final Log headerLog = LogFactory.getLog("org.apache.hc.core5.http.headers");
+        final Logger sessionLog = LogManager.getLogger(ioSession.getClass());
+        final Logger wireLog = LogManager.getLogger("org.apache.hc.core5.http.wire");
+        final Logger headerLog = LogManager.getLogger("org.apache.hc.core5.http.headers");
 
         final ServerHttp1StreamDuplexer streamDuplexer = createServerHttp1StreamDuplexer(
                 new LoggingIOSession(ioSession, id, sessionLog, wireLog),

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java Mon Oct 31 22:21:30 2016
@@ -35,8 +35,6 @@ import java.nio.charset.StandardCharsets
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.hc.core5.concurrent.BasicFuture;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.http.ExceptionListener;
@@ -64,7 +62,8 @@ import org.apache.hc.core5.reactor.IOSes
 import org.apache.hc.core5.reactor.SessionRequest;
 import org.apache.hc.core5.reactor.SessionRequestCallback;
 import org.apache.hc.core5.util.Args;
-
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 public class Http2TestClient extends AsyncRequester {
 
     private final UriPatternMatcher<Supplier<AsyncPushConsumer>> pushHandlerMatcher;
@@ -72,7 +71,7 @@ public class Http2TestClient extends Asy
     public Http2TestClient(final IOReactorConfig ioReactorConfig) throws IOException {
         super(ioReactorConfig, new ExceptionListener() {
 
-            private final Log log = LogFactory.getLog(Http2TestClient.class);
+            private final Logger log = LogManager.getLogger(Http2TestClient.class);
 
             @Override
             public void onError(final Exception ex) {