hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1767384 [1/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...
Date Mon, 31 Oct 2016 22:21:31 GMT
Author: ggregory
Date: Mon Oct 31 22:21:30 2016
New Revision: 1767384

URL: http://svn.apache.org/viewvc?rev=1767384&view=rev
Log:
HTTPCORE-436: Port tests from Apache Commons Logging to Apache Log4j 2.

Added:
    httpcomponents/httpcore/trunk/httpcore5-testing/src/test/resources/
    httpcomponents/httpcore/trunk/httpcore5-testing/src/test/resources/log4j2.xml
Modified:
    httpcomponents/httpcore/trunk/   (props changed)
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    httpcomponents/httpcore/trunk/httpcore5-h2/pom.xml
    httpcomponents/httpcore/trunk/httpcore5-testing/   (props changed)
    httpcomponents/httpcore/trunk/httpcore5-testing/pom.xml
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/Wire.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientTestingAdapter.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientPOJOAdapter.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientTestingAdapter.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/FrameworkTest.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFramework.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFrameworkException.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/TestingFrameworkRequestHandler.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestServer.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalClientHttp1EventHandlerFactory.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalServerHttp1EventHandlerFactory.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestServer.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalClientHttp2EventHandlerFactory.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalHttp2StreamListener.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalServerHttp2EventHandlerFactory.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/LogAppendable.java
    httpcomponents/httpcore/trunk/httpcore5/pom.xml
    httpcomponents/httpcore/trunk/pom.xml

Propchange: httpcomponents/httpcore/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Oct 31 22:21:30 2016
@@ -1,4 +1,3 @@
-
 .project
 .classpath
 bin
@@ -9,3 +8,4 @@ target
 .pmd
 .idea
 *.iml
+.checkstyle

Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Mon Oct 31 22:21:30 2016
@@ -30,6 +30,8 @@ Changelog
 
 * HTTPCORE-418: Add a HttpHost constructor for hostname and scheme.
   Based on contribution by Joshua Hendrickson <joshua dot hendrickson at live dot com>
+  
+* HTTPCORE-436: Port tests from Apache Commons Logging to Apache Log4j 2.
 
 
 Release 5.0-ALPHA1

Modified: httpcomponents/httpcore/trunk/httpcore5-h2/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/pom.xml?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/pom.xml (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/pom.xml Mon Oct 31 22:21:30 2016
@@ -54,8 +54,13 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>commons-logging</groupId>
-      <artifactId>commons-logging</artifactId>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-api</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
       <scope>test</scope>
     </dependency>
   </dependencies>

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct 31 22:21:30 2016
@@ -0,0 +1,4 @@
+target
+.settings
+.classpath
+.project

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/pom.xml?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/pom.xml (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/pom.xml Mon Oct 31 22:21:30 2016
@@ -50,8 +50,13 @@
       <scope>compile</scope>
     </dependency>
     <dependency>
-      <groupId>commons-logging</groupId>
-      <artifactId>commons-logging</artifactId>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-api</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
       <scope>compile</scope>
     </dependency>
     <dependency>

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java Mon Oct 31 22:21:30 2016
@@ -33,8 +33,6 @@ import java.net.Socket;
 import java.net.SocketException;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.hc.core5.http.ConnectionClosedException;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.config.SocketConfig;
@@ -45,7 +43,8 @@ import org.apache.hc.core5.http.io.HttpE
 import org.apache.hc.core5.http.io.HttpRequestHandler;
 import org.apache.hc.core5.http.io.UriHttpRequestHandlerMapper;
 import org.apache.hc.core5.util.Asserts;
-
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 public class ClassicTestServer {
 
     private final UriHttpRequestHandlerMapper reqistry;
@@ -133,7 +132,7 @@ public class ClassicTestServer {
 
     static class SimpleExceptionListener implements ExceptionListener {
 
-        private final Log log = LogFactory.getLog(ClassicTestServer.class);
+        private final Logger log = LogManager.getLogger(ClassicTestServer.class);
 
         @Override
         public void onError(final Exception ex) {

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpClientConnection.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpClientConnection.java Mon Oct 31 22:21:30 2016
@@ -36,12 +36,10 @@ import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CharsetEncoder;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hc.core5.http.ContentLengthStrategy;
-import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.ContentLengthStrategy;
+import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnection;
@@ -49,14 +47,15 @@ import org.apache.hc.core5.http.io.HttpM
 import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
 import org.apache.hc.core5.http.message.RequestLine;
 import org.apache.hc.core5.http.message.StatusLine;
-
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 public class LoggingBHttpClientConnection extends DefaultBHttpClientConnection {
 
     private static final AtomicLong COUNT = new AtomicLong();
 
     private final String id;
-    private final Log log;
-    private final Log headerlog;
+    private final Logger log;
+    private final Logger headerlog;
     private final Wire wire;
 
     public LoggingBHttpClientConnection(
@@ -73,9 +72,9 @@ public class LoggingBHttpClientConnectio
                 constraints, incomingContentStrategy, outgoingContentStrategy,
                 requestWriterFactory, responseParserFactory);
         this.id = "http-outgoing-" + COUNT.incrementAndGet();
-        this.log = LogFactory.getLog(getClass());
-        this.headerlog = LogFactory.getLog("org.apache.http.headers");
-        this.wire = new Wire(LogFactory.getLog("org.apache.http.wire"), this.id);
+        this.log = LogManager.getLogger(getClass());
+        this.headerlog = LogManager.getLogger("org.apache.http.headers");
+        this.wire = new Wire(LogManager.getLogger("org.apache.http.wire"), this.id);
     }
 
     public LoggingBHttpClientConnection(final int buffersize) {

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java Mon Oct 31 22:21:30 2016
@@ -36,12 +36,10 @@ import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CharsetEncoder;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hc.core5.http.ContentLengthStrategy;
-import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.ContentLengthStrategy;
+import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnection;
@@ -49,14 +47,15 @@ import org.apache.hc.core5.http.io.HttpM
 import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
 import org.apache.hc.core5.http.message.RequestLine;
 import org.apache.hc.core5.http.message.StatusLine;
-
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 public class LoggingBHttpServerConnection extends DefaultBHttpServerConnection {
 
     private static final AtomicLong COUNT = new AtomicLong();
 
     private final String id;
-    private final Log log;
-    private final Log headerlog;
+    private final Logger log;
+    private final Logger headerlog;
     private final Wire wire;
 
     public LoggingBHttpServerConnection(
@@ -73,9 +72,9 @@ public class LoggingBHttpServerConnectio
                 incomingContentStrategy, outgoingContentStrategy,
                 requestParserFactory, responseWriterFactory);
         this.id = "http-incoming-" + COUNT.incrementAndGet();
-        this.log = LogFactory.getLog(getClass());
-        this.headerlog = LogFactory.getLog("org.apache.http.headers");
-        this.wire = new Wire(LogFactory.getLog("org.apache.http.wire"), this.id);
+        this.log = LogManager.getLogger(getClass());
+        this.headerlog = LogManager.getLogger("org.apache.http.headers");
+        this.wire = new Wire(LogManager.getLogger("org.apache.http.wire"), this.id);
     }
 
     public LoggingBHttpServerConnection(final int buffersize) {

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/Wire.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/Wire.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/Wire.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/Wire.java Mon Oct 31 22:21:30 2016
@@ -29,14 +29,13 @@ package org.apache.hc.core5.testing.clas
 
 import java.nio.ByteBuffer;
 
-import org.apache.commons.logging.Log;
-
+import org.apache.logging.log4j.Logger;
 public class Wire {
 
-    private final Log log;
+    private final Logger log;
     private final String id;
 
-    public Wire(final Log log, final String id) {
+    public Wire(final Logger log, final String id) {
         super();
         this.log = log;
         this.id = id;

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java Mon Oct 31 22:21:30 2016
@@ -1,175 +1,168 @@
-/*
- * ====================================================================
- * 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 java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-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.HttpHost;
-import org.apache.hc.core5.http.ProtocolVersion;
-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.message.BasicClassicHttpRequest;
-import org.apache.hc.core5.http.protocol.HttpCoreContext;
-import org.apache.hc.core5.testing.classic.ClassicTestClient;
-
-/**
- * Implementation of {@link ClientPOJOAdapter} for ClassicTestClient.
- *
- * @since 5.0
- */
-public class ClassicTestClientAdapter extends ClientPOJOAdapter {
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Map<String, Object> execute(final String defaultURI, final Map<String, Object> request) throws Exception {
-        // check the request for missing items.
-        if (defaultURI == null) {
-            throw new HttpException("defaultURL cannot be null");
-        }
-        if (request == null) {
-            throw new HttpException("request cannot be null");
-        }
-        if (! request.containsKey(PATH)) {
-            throw new HttpException("Request path should be set.");
-        }
-        if (! request.containsKey(METHOD)) {
-            throw new HttpException("Request method should be set.");
-        }
-
-        final ClassicTestClient client = new ClassicTestClient();
-
-        // Append the path to the defaultURI.
-        String tempDefaultURI = defaultURI;
-        if (! defaultURI.endsWith("/")) {
-            tempDefaultURI += "/";
-        }
-        final URI startingURI = new URI(tempDefaultURI + request.get(PATH));
-        final URI uri;
-
-        // append each parameter in the query to the uri.
-        @SuppressWarnings("unchecked")
-        final Map<String, String> queryMap = (Map<String, String>) request.get(QUERY);
-        if (queryMap != null) {
-            final String existingQuery = startingURI.getRawQuery();
-            final StringBuilder newQuery = new StringBuilder(existingQuery == null ? "" : existingQuery);
-
-            // append each parm to the query
-            for (Entry<String, String> parm : queryMap.entrySet()) {
-                newQuery.append("&" + parm.getKey() + "=" + parm.getValue());
-            }
-            // create a uri with the new query.
-            uri = new URI(
-                    startingURI.getRawSchemeSpecificPart(),
-                    startingURI.getRawUserInfo(),
-                    startingURI.getHost(),
-                    startingURI.getPort(),
-                    startingURI.getRawPath(),
-                    newQuery.toString(),
-                    startingURI.getRawFragment());
-        } else {
-            uri = startingURI;
-        }
-
-        final BasicClassicHttpRequest httpRequest = new BasicClassicHttpRequest(request.get(METHOD).toString(), uri);
-
-        if (request.containsKey(PROTOCOL_VERSION)) {
-            httpRequest.setVersion((ProtocolVersion) request.get(PROTOCOL_VERSION));
-        }
-
-        // call addHeader for each header in headers.
-        @SuppressWarnings("unchecked")
-        final Map<String, String> headersMap = (Map<String, String>) request.get(HEADERS);
-        if (headersMap != null) {
-            for (Entry<String, String> header : headersMap.entrySet()) {
-                httpRequest.addHeader(header.getKey(), header.getValue());
-            }
-        }
-
-        // call setEntity if a body is specified.
-        final String requestBody = (String) request.get(BODY);
-        if (requestBody != null) {
-            final String requestContentType = (String) request.get(CONTENT_TYPE);
-            final StringEntity entity = requestContentType != null ?
-                                          new StringEntity(requestBody, ContentType.parse(requestContentType)) :
-                                          new StringEntity(requestBody);
-            httpRequest.setEntity(entity);
-        }
-
-        // timeout
-        if (request.containsKey(TIMEOUT)) {
-            final long timeout = (long) request.get(TIMEOUT);
-            client.setTimeout((int) timeout);
-        }
-        client.start();
-
-        // Now start the request.
-        final HttpHost host = new HttpHost(uri.getHost(), uri.getPort());
-        final HttpCoreContext context = HttpCoreContext.create();
-        final ClassicHttpResponse response = client.execute(host, httpRequest, context);
-
-        // Prepare the response.  It will contain status, body, headers, and contentType.
-        final HttpEntity entity = response.getEntity();
-        final String body = entity == null ? null : EntityUtils.toString(entity);
-        final String contentType = entity == null ? null : entity.getContentType();
-
-        client.keepAlive(httpRequest, response, context);
-
-        // prepare the returned information
-        final Map<String, Object> ret = new HashMap<String, Object>();
-        ret.put(STATUS, response.getCode());
-
-        // convert the headers to a Map
-        final Map<String, Object> headerMap = new HashMap<String, Object>();
-        for (Header header : response.getAllHeaders()) {
-            headerMap.put(header.getName(), header.getValue());
-        }
-        ret.put(HEADERS, headerMap);
-        ret.put(BODY, body);
-        ret.put(CONTENT_TYPE, contentType);
-
-        return ret ;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public String getClientName() {
-        return "ClassicTestClient";
-    }
-}
+/*
+ * ====================================================================
+ * 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 java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+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.HttpHost;
+import org.apache.hc.core5.http.ProtocolVersion;
+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.message.BasicClassicHttpRequest;
+import org.apache.hc.core5.http.protocol.HttpCoreContext;
+import org.apache.hc.core5.testing.classic.ClassicTestClient; public class ClassicTestClientAdapter extends ClientPOJOAdapter {
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Map<String, Object> execute(final String defaultURI, final Map<String, Object> request) throws Exception {
+        // check the request for missing items.
+        if (defaultURI == null) {
+            throw new HttpException("defaultURL cannot be null");
+        }
+        if (request == null) {
+            throw new HttpException("request cannot be null");
+        }
+        if (! request.containsKey(PATH)) {
+            throw new HttpException("Request path should be set.");
+        }
+        if (! request.containsKey(METHOD)) {
+            throw new HttpException("Request method should be set.");
+        }
+
+        final ClassicTestClient client = new ClassicTestClient();
+
+        // Append the path to the defaultURI.
+        String tempDefaultURI = defaultURI;
+        if (! defaultURI.endsWith("/")) {
+            tempDefaultURI += "/";
+        }
+        final URI startingURI = new URI(tempDefaultURI + request.get(PATH));
+        final URI uri;
+
+        // append each parameter in the query to the uri.
+        @SuppressWarnings("unchecked")
+        final Map<String, String> queryMap = (Map<String, String>) request.get(QUERY);
+        if (queryMap != null) {
+            final String existingQuery = startingURI.getRawQuery();
+            final StringBuilder newQuery = new StringBuilder(existingQuery == null ? "" : existingQuery);
+
+            // append each parm to the query
+            for (Entry<String, String> parm : queryMap.entrySet()) {
+                newQuery.append("&" + parm.getKey() + "=" + parm.getValue());
+            }
+            // create a uri with the new query.
+            uri = new URI(
+                    startingURI.getRawSchemeSpecificPart(),
+                    startingURI.getRawUserInfo(),
+                    startingURI.getHost(),
+                    startingURI.getPort(),
+                    startingURI.getRawPath(),
+                    newQuery.toString(),
+                    startingURI.getRawFragment());
+        } else {
+            uri = startingURI;
+        }
+
+        final BasicClassicHttpRequest httpRequest = new BasicClassicHttpRequest(request.get(METHOD).toString(), uri);
+
+        if (request.containsKey(PROTOCOL_VERSION)) {
+            httpRequest.setVersion((ProtocolVersion) request.get(PROTOCOL_VERSION));
+        }
+
+        // call addHeader for each header in headers.
+        @SuppressWarnings("unchecked")
+        final Map<String, String> headersMap = (Map<String, String>) request.get(HEADERS);
+        if (headersMap != null) {
+            for (Entry<String, String> header : headersMap.entrySet()) {
+                httpRequest.addHeader(header.getKey(), header.getValue());
+            }
+        }
+
+        // call setEntity if a body is specified.
+        final String requestBody = (String) request.get(BODY);
+        if (requestBody != null) {
+            final String requestContentType = (String) request.get(CONTENT_TYPE);
+            final StringEntity entity = requestContentType != null ?
+                                          new StringEntity(requestBody, ContentType.parse(requestContentType)) :
+                                          new StringEntity(requestBody);
+            httpRequest.setEntity(entity);
+        }
+
+        // timeout
+        if (request.containsKey(TIMEOUT)) {
+            final long timeout = (long) request.get(TIMEOUT);
+            client.setTimeout((int) timeout);
+        }
+        client.start();
+
+        // Now start the request.
+        final HttpHost host = new HttpHost(uri.getHost(), uri.getPort());
+        final HttpCoreContext context = HttpCoreContext.create();
+        final ClassicHttpResponse response = client.execute(host, httpRequest, context);
+
+        // Prepare the response.  It will contain status, body, headers, and contentType.
+        final HttpEntity entity = response.getEntity();
+        final String body = entity == null ? null : EntityUtils.toString(entity);
+        final String contentType = entity == null ? null : entity.getContentType();
+
+        client.keepAlive(httpRequest, response, context);
+
+        // prepare the returned information
+        final Map<String, Object> ret = new HashMap<String, Object>();
+        ret.put(STATUS, response.getCode());
+
+        // convert the headers to a Map
+        final Map<String, Object> headerMap = new HashMap<String, Object>();
+        for (Header header : response.getAllHeaders()) {
+            headerMap.put(header.getName(), header.getValue());
+        }
+        ret.put(HEADERS, headerMap);
+        ret.put(BODY, body);
+        ret.put(CONTENT_TYPE, contentType);
+
+        return ret ;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getClientName() {
+        return "ClassicTestClient";
+    }
+}

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientTestingAdapter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientTestingAdapter.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientTestingAdapter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientTestingAdapter.java Mon Oct 31 22:21:30 2016
@@ -1,40 +1,35 @@
-/*
- * ====================================================================
- * 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;
-
-/**
- * Implementation of {@link ClientTestingAdapter} for the ClassicTestClient.
- *
- * @since 5.0
- */
-public class ClassicTestClientTestingAdapter extends ClientTestingAdapter {
-
-    public ClassicTestClientTestingAdapter() {
-        super(new ClassicTestClientAdapter());
-    }
-}
+/*
+ * ====================================================================
+ * 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 ClassicTestClientTestingAdapter extends ClientTestingAdapter {
+
+    public ClassicTestClientTestingAdapter() {
+        super(new ClassicTestClientAdapter());
+    }
+}

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientPOJOAdapter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientPOJOAdapter.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientPOJOAdapter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientPOJOAdapter.java Mon Oct 31 22:21:30 2016
@@ -1,155 +1,155 @@
-/*
- * ====================================================================
- * 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 java.util.Map;
-
-/**
- *
- * <p>This adapter expects a request to be made up of POJOs such as Maps and Lists.  In Groovy
- * the request could be expressed like this:</p>
- *
- * <pre>
- *
- * def request = [
- *                   path    : "a/path",
- *                   method  : "GET",
- *                   query   : [
- *                                parm1 : "1",
- *                                parm2 : "2",
- *                             ]
- *                   headers : [
- *                                header1 : "stuff",
- *                                header2 : "more_stuff",
- *                             ]
- *                   contentType : "application/json",
- *                   body        : '{"location" : "home" }',
- *                ]
- * </pre>
- *
- * <p>The adapter will translate this request into calls specific to a particular HTTP client.</p>
- *
- * <p>The response is then returned with POJOs with this structure:</p>
- *
- * <pre>
- *
- * def response = [
- *                    status      : 200,
- *                    headers     : [
- *                                      header1 : "response_stuff",
- *                                  ]
- *                    contentType : "application/json",
- *                    body        : '{"location" : "work" }',
- *                ]
- * </pre>
- * @since 5.0
- */
-public abstract class ClientPOJOAdapter {
-    public static final String BODY = "body";
-    public static final String CONTENT_TYPE = "contentType";
-    public static final String HEADERS = "headers";
-    public static final String METHOD = "method";
-    public static final String NAME = "name";
-    public static final String PATH = "path";
-    public static final String PROTOCOL_VERSION = "protocolVersion";
-    public static final String QUERY = "query";
-    public static final String REQUEST = "request";
-    public static final String RESPONSE = "response";
-    public static final String STATUS = "status";
-    public static final String TIMEOUT = "timeout";
-
-    /**
-     * Name of the HTTP Client that this adapter uses.
-     *
-     * @return name of the HTTP Client.
-     */
-    public abstract String getClientName();
-
-    /**
-     * Execute an HTTP request.
-     *
-     * @param defaultURI   the URI used by default.  The path in the request is
-     *                     usually appended to it.
-     * @param request      the request as specified above.
-     *
-     * @return the response to the request as specified above.
-     *
-     * @throws Exception in case of a problem
-     */
-    public abstract Map<String, Object> execute(String defaultURI, Map<String, Object> request) throws Exception;
-
-    /**
-     * <p>Check if a request is supported.</p>
-     *
-     * <p>Usually called directly by a testing framework.  If an HTTP client does not support
-     * a particular request, a non-null reason should be returned.  Otherwise, if
-     * the request is supported, return null.</p>
-     *
-     * <p>If this method is overridden, then the start method should probably call
-     * assertRequestSupported() at the beginning.</p>
-     *
-     * @param request the request as specified above.
-     *
-     * @return null if the request is supported;  Otherwise, return a reason.
-     */
-    public String checkRequestSupport(final Map<String, Object> request) {
-        return null;
-    }
-
-    /**
-     * <p>Assert that the request is supported</p>
-     *
-     * <p>Usually called by the start method.  Throws an exception if the request
-     * is not supported.</p>
-     *
-     * @param request the request as specified above.
-     * @throws Exception if the request is not supported.
-     */
-    public void assertRequestSupported(final Map<String, Object> request) throws Exception {
-        final String reason = checkRequestSupport(request);
-        if (reason != null) {
-            throw new Exception(reason);
-        }
-    }
-
-    /**
-     * <p>Modify the request.</p>
-     *
-     * <p>In a testing context, a testing framework can call this method to allow
-     * the adapter to change the request.  The request is then given to a
-     * special request handler of the in-process HttpServer which will later check
-     * an actual HTTP request against what is expected.</p>
-     *
-     * <p>In a production context, this is called by the start method (if at all).</p>
-     *
-     * @param request the request as specified above.
-     * @return the same request or a modification of it.
-     */
-    public Map<String, Object> modifyRequest(final Map<String, Object> request) {
-        return request;
-    };
-}
+/*
+ * ====================================================================
+ * 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 java.util.Map;
+
+/**
+ *
+ * <p>This adapter expects a request to be made up of POJOs such as Maps and Lists.  In Groovy
+ * the request could be expressed like this:</p>
+ *
+ * <pre>
+ *
+ * def request = [
+ *                   path    : "a/path",
+ *                   method  : "GET",
+ *                   query   : [
+ *                                parm1 : "1",
+ *                                parm2 : "2",
+ *                             ]
+ *                   headers : [
+ *                                header1 : "stuff",
+ *                                header2 : "more_stuff",
+ *                             ]
+ *                   contentType : "application/json",
+ *                   body        : '{"location" : "home" }',
+ *                ]
+ * </pre>
+ *
+ * <p>The adapter will translate this request into calls specific to a particular HTTP client.</p>
+ *
+ * <p>The response is then returned with POJOs with this structure:</p>
+ *
+ * <pre>
+ *
+ * def response = [
+ *                    status      : 200,
+ *                    headers     : [
+ *                                      header1 : "response_stuff",
+ *                                  ]
+ *                    contentType : "application/json",
+ *                    body        : '{"location" : "work" }',
+ *                ]
+ * </pre>
+ * @since 5.0
+ */
+public abstract class ClientPOJOAdapter {
+    public static final String BODY = "body";
+    public static final String CONTENT_TYPE = "contentType";
+    public static final String HEADERS = "headers";
+    public static final String METHOD = "method";
+    public static final String NAME = "name";
+    public static final String PATH = "path";
+    public static final String PROTOCOL_VERSION = "protocolVersion";
+    public static final String QUERY = "query";
+    public static final String REQUEST = "request";
+    public static final String RESPONSE = "response";
+    public static final String STATUS = "status";
+    public static final String TIMEOUT = "timeout";
+
+    /**
+     * Name of the HTTP Client that this adapter uses.
+     *
+     * @return name of the HTTP Client.
+     */
+    public abstract String getClientName();
+
+    /**
+     * Execute an HTTP request.
+     *
+     * @param defaultURI   the URI used by default.  The path in the request is
+     *                     usually appended to it.
+     * @param request      the request as specified above.
+     *
+     * @return the response to the request as specified above.
+     *
+     * @throws Exception in case of a problem
+     */
+    public abstract Map<String, Object> execute(String defaultURI, Map<String, Object> request) throws Exception;
+
+    /**
+     * <p>Check if a request is supported.</p>
+     *
+     * <p>Usually called directly by a testing framework.  If an HTTP client does not support
+     * a particular request, a non-null reason should be returned.  Otherwise, if
+     * the request is supported, return null.</p>
+     *
+     * <p>If this method is overridden, then the start method should probably call
+     * assertRequestSupported() at the beginning.</p>
+     *
+     * @param request the request as specified above.
+     *
+     * @return null if the request is supported;  Otherwise, return a reason.
+     */
+    public String checkRequestSupport(final Map<String, Object> request) {
+        return null;
+    }
+
+    /**
+     * <p>Assert that the request is supported</p>
+     *
+     * <p>Usually called by the start method.  Throws an exception if the request
+     * is not supported.</p>
+     *
+     * @param request the request as specified above.
+     * @throws Exception if the request is not supported.
+     */
+    public void assertRequestSupported(final Map<String, Object> request) throws Exception {
+        final String reason = checkRequestSupport(request);
+        if (reason != null) {
+            throw new Exception(reason);
+        }
+    }
+
+    /**
+     * <p>Modify the request.</p>
+     *
+     * <p>In a testing context, a testing framework can call this method to allow
+     * the adapter to change the request.  The request is then given to a
+     * special request handler of the in-process HttpServer which will later check
+     * an actual HTTP request against what is expected.</p>
+     *
+     * <p>In a production context, this is called by the start method (if at all).</p>
+     *
+     * @param request the request as specified above.
+     * @return the same request or a modification of it.
+     */
+    public Map<String, Object> modifyRequest(final Map<String, Object> request) {
+        return request;
+    };
+}

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientTestingAdapter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientTestingAdapter.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientTestingAdapter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientTestingAdapter.java Mon Oct 31 22:21:30 2016
@@ -1,186 +1,155 @@
-/*
- * ====================================================================
- * 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 java.util.Map;
-
-/**
-*
-* <p>This adapter assists the testing of an HTTP client.  This adapter in turn uses an
-* {@link ClientPOJOAdapter} to actually use the HTTP client to make the request.
-* See {@link ClientPOJOAdapter} to see the format of the request and the returned
-* response.  The format of the returned response is also the format of the parameter
-* called responseExpectations.</p>
-*
-* <p>This adapter will generally call the {@link ClientPOJOAdapter} methods of the same
-* name when these methods are called:</p>
-*
-* <pre>
-*
-* isRequestSupported
-* modifyRequest
-* start
-*
-* </pre>
-*
-* <p>See these method's documentation in {@link ClientPOJOAdapter} for details.</p>
-*
-* <p>The value that this adapter adds is with the modifyResponseExpectations method.  Each
-* test will specify the response that is expected.  The HttpClient5 adapter is able
-* to use these unmodified expectations, but if a different HTTP client (such as Groovy's
-* RESTClient which uses HttpClient) for some reason needs to modify the expectations,
-* it would be done in the modifyResponseExpectations method.</p>
-*
-* @since 5.0
-*/
-public class ClientTestingAdapter {
-    /**
-     * This adapter will perform the HTTP request and return the response in the
-     * expected format.
-     */
-    protected ClientPOJOAdapter adapter;
-
-    /*
-     * The following is not expected to be changed to true, but it is to highlight
-     * where the start method can call the requestHandler's assertNothingThrown()
-     * method if desired.  Since this adapter's start method does not check
-     * the response, there is no need to call it.
-     */
-    protected boolean callAssertNothingThrown;
-
-    public ClientTestingAdapter() {
-    }
-
-    public ClientTestingAdapter(final ClientPOJOAdapter adapter) {
-        this.adapter = adapter;
-    }
-
-    /**
-     * See the documentation for the same method in {@link ClientPOJOAdapter}.  This
-     * method will typically call it.  However, this method also has access to the
-     * test's response expectations if that is needed for some reason.  Furthermore,
-     * this method also has access to the {@link TestingFrameworkRequestHandler} so
-     * it can optionally call assertNothingThrown() before checking the response
-     * further.  It is optional because the test framework will call it later.
-     *
-     * @param defaultURI           See start method of {@link ClientPOJOAdapter}.
-     * @param request              See start method of {@link ClientPOJOAdapter}.
-     * @param requestHandler       The request handler that checks the received HTTP request
-     *                             with the request that was intended.  If there is a
-     *                             mismatch of expectations, then the requestHandler will
-     *                             throw an exception.  If this start method does not want
-     *                             to make further checks of the response in the case
-     *                             the responseHandler threw, then the assertNothingThrown()
-     *                             method should be called before doing further checks.
-     * @param responseExpectations The response expectations of the test.
-     * @return See return of the start method of {@link ClientPOJOAdapter}.
-     * @throws TestingFrameworkException in the case of a problem.
-     */
-    public Map<String, Object> execute(final String defaultURI, final Map<String, Object> request,
-            final TestingFrameworkRequestHandler requestHandler,
-            final Map<String, Object> responseExpectations) throws TestingFrameworkException {
-
-        try {
-            if (adapter == null) {
-                throw new TestingFrameworkException("adapter cannot be null");
-            }
-            // Call the adapter's start method to actually make the HTTP request.
-            final Map<String, Object> response = adapter.execute(defaultURI, request);
-
-            /*
-             * Adapters may call assertNothingThrown() if they would like.  This would be to
-             * make sure the following code is not executed in the event there was something
-             * thrown in the request handler.
-             *
-             * Otherwise, the framework will call it when this method returns.  So, it is
-             * optional.
-             */
-            if (callAssertNothingThrown) {
-                if (requestHandler == null) {
-                    throw new TestingFrameworkException("requestHandler cannot be null");
-                }
-                requestHandler.assertNothingThrown();
-            }
-
-            return response;
-        } catch (TestingFrameworkException e) {
-            throw e;
-        } catch (Exception ex) {
-            throw new TestingFrameworkException(ex);
-        }
-    }
-
-    /**
-     * See the documentation for the same method in {@link ClientPOJOAdapter}.
-     *
-     * @param request
-     * @return
-     */
-    public boolean isRequestSupported(final Map<String, Object> request) {
-        return (adapter == null) ? true : adapter.checkRequestSupport(request) == null;
-    };
-
-    /**
-     * See the documentation for the same method in {@link ClientPOJOAdapter}.
-     *
-     * @param request
-     * @return
-     */
-    public Map<String, Object> modifyRequest(final Map<String, Object> request) {
-       return (adapter == null) ? request : adapter.modifyRequest(request);
-    };
-
-    /**
-     * Generally a test's response expectations should not need to be modified, but
-     * if a particular HTTP client (such as Groovy's RESTClient which uses HttpClient)
-     * needs to modify the response expectations, it should do so here.  After this
-     * method returns, the {@link TestingFrameworkRequestHandler} is sent the
-     * expectations so the request handler will return a response that matches the
-     * expectations.  When the HTTP response is obtained, the received response
-     * is matched against the expectations.
-     *
-     * @param request for the format, see the documentation for {@link ClientPOJOAdapter}.
-     * @param responseExpectations for the format, see the documentation for {@link ClientPOJOAdapter}.
-     * @return the same or modified response expectations.
-     */
-    public Map<String, Object> modifyResponseExpectations(final Map<String, Object> request,
-                                                          final Map<String, Object> responseExpectations) {
-        return responseExpectations;
-    }
-
-    /**
-     * Getter for the {@link ClientPOJOAdapter} that is actually used to make the
-     * HTTP request.
-     *
-     * @return the {@link ClientPOJOAdapter}.
-     */
-    public ClientPOJOAdapter getClientPOJOAdapter() {
-        return adapter;
-    }
-
-}
+/*
+ * ====================================================================
+ * 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 java.util.Map; public class ClientTestingAdapter {
+    /**
+     * This adapter will perform the HTTP request and return the response in the
+     * expected format.
+     */
+    protected ClientPOJOAdapter adapter;
+
+    /*
+     * The following is not expected to be changed to true, but it is to highlight
+     * where the start method can call the requestHandler's assertNothingThrown()
+     * method if desired.  Since this adapter's start method does not check
+     * the response, there is no need to call it.
+     */
+    protected boolean callAssertNothingThrown;
+
+    public ClientTestingAdapter() {
+    }
+
+    public ClientTestingAdapter(final ClientPOJOAdapter adapter) {
+        this.adapter = adapter;
+    }
+
+    /**
+     * See the documentation for the same method in {@link ClientPOJOAdapter}.  This
+     * method will typically call it.  However, this method also has access to the
+     * test's response expectations if that is needed for some reason.  Furthermore,
+     * this method also has access to the {@link TestingFrameworkRequestHandler} so
+     * it can optionally call assertNothingThrown() before checking the response
+     * further.  It is optional because the test framework will call it later.
+     *
+     * @param defaultURI           See start method of {@link ClientPOJOAdapter}.
+     * @param request              See start method of {@link ClientPOJOAdapter}.
+     * @param requestHandler       The request handler that checks the received HTTP request
+     *                             with the request that was intended.  If there is a
+     *                             mismatch of expectations, then the requestHandler will
+     *                             throw an exception.  If this start method does not want
+     *                             to make further checks of the response in the case
+     *                             the responseHandler threw, then the assertNothingThrown()
+     *                             method should be called before doing further checks.
+     * @param responseExpectations The response expectations of the test.
+     * @return See return of the start method of {@link ClientPOJOAdapter}.
+     * @throws TestingFrameworkException in the case of a problem.
+     */
+    public Map<String, Object> execute(final String defaultURI, final Map<String, Object> request,
+            final TestingFrameworkRequestHandler requestHandler,
+            final Map<String, Object> responseExpectations) throws TestingFrameworkException {
+
+        try {
+            if (adapter == null) {
+                throw new TestingFrameworkException("adapter cannot be null");
+            }
+            // Call the adapter's start method to actually make the HTTP request.
+            final Map<String, Object> response = adapter.execute(defaultURI, request);
+
+            /*
+             * Adapters may call assertNothingThrown() if they would like.  This would be to
+             * make sure the following code is not executed in the event there was something
+             * thrown in the request handler.
+             *
+             * Otherwise, the framework will call it when this method returns.  So, it is
+             * optional.
+             */
+            if (callAssertNothingThrown) {
+                if (requestHandler == null) {
+                    throw new TestingFrameworkException("requestHandler cannot be null");
+                }
+                requestHandler.assertNothingThrown();
+            }
+
+            return response;
+        } catch (TestingFrameworkException e) {
+            throw e;
+        } catch (Exception ex) {
+            throw new TestingFrameworkException(ex);
+        }
+    }
+
+    /**
+     * See the documentation for the same method in {@link ClientPOJOAdapter}.
+     *
+     * @param request
+     * @return
+     */
+    public boolean isRequestSupported(final Map<String, Object> request) {
+        return (adapter == null) ? true : adapter.checkRequestSupport(request) == null;
+    };
+
+    /**
+     * See the documentation for the same method in {@link ClientPOJOAdapter}.
+     *
+     * @param request
+     * @return
+     */
+    public Map<String, Object> modifyRequest(final Map<String, Object> request) {
+       return (adapter == null) ? request : adapter.modifyRequest(request);
+    };
+
+    /**
+     * Generally a test's response expectations should not need to be modified, but
+     * if a particular HTTP client (such as Groovy's RESTClient which uses HttpClient)
+     * needs to modify the response expectations, it should do so here.  After this
+     * method returns, the {@link TestingFrameworkRequestHandler} is sent the
+     * expectations so the request handler will return a response that matches the
+     * expectations.  When the HTTP response is obtained, the received response
+     * is matched against the expectations.
+     *
+     * @param request for the format, see the documentation for {@link ClientPOJOAdapter}.
+     * @param responseExpectations for the format, see the documentation for {@link ClientPOJOAdapter}.
+     * @return the same or modified response expectations.
+     */
+    public Map<String, Object> modifyResponseExpectations(final Map<String, Object> request,
+                                                          final Map<String, Object> responseExpectations) {
+        return responseExpectations;
+    }
+
+    /**
+     * Getter for the {@link ClientPOJOAdapter} that is actually used to make the
+     * HTTP request.
+     *
+     * @return the {@link ClientPOJOAdapter}.
+     */
+    public ClientPOJOAdapter getClientPOJOAdapter() {
+        return adapter;
+    }
+
+}

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/FrameworkTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/FrameworkTest.java?rev=1767384&r1=1767383&r2=1767384&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/FrameworkTest.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/FrameworkTest.java Mon Oct 31 22:21:30 2016
@@ -1,172 +1,154 @@
-/*
- * ====================================================================
- * 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.PATH;
-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.REQUEST;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.RESPONSE;
-import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.STATUS;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.hc.core5.http.NameValuePair;
-import org.apache.hc.core5.util.URLEncodedUtils;
-
-
-
-/**
- * <p>This class is not expected to be used directly by the user, but its job is to
- * supply helpful defaults for tests.</p>
- *
- * <p>A test is made up of an HTTP request that the HTTP client will send as well
- * as a response that is expected.</p>
- *
- * <p>See {@link ClientPOJOAdapter} for details on the request and response.</p>
- *
- * <p>Generally, if the request does not specify a method, it is assumed to be a GET.
- * There are also defaults for headers, query parameters, body, contentType, etc.</p>
- *
- * @since 5.0
- */
-public class FrameworkTest {
-    private Map<String, Object> request = new HashMap<String, Object>();
-    private Map<String, Object> response = new HashMap<String, Object>();
-
-    /**
-     * Constructs a test with default values.
-     */
-    public FrameworkTest() {
-        this(null);
-    }
-
-    /**
-     * Constructs a test with values that are passed in as well as defaults
-     * for values that are not passed in.
-     *
-     * @param test Contains a REQUEST and an expected RESPONSE.
-     *             See {@link ClientPOJOAdapter} for details.
-     */
-    @SuppressWarnings("unchecked")
-    public FrameworkTest(final Map<String, Object> test) {
-        if (test != null) {
-            if (test.containsKey(REQUEST)) {
-                request = (Map<String, Object>) test.get(REQUEST);
-            }
-            if (test.containsKey(RESPONSE)) {
-                response = (Map<String, Object>) test.get(RESPONSE);
-            }
-        }
-    }
-
-    /**
-     * Returns a request with defaults for any parameter that is not specified.
-     *
-     * @return a REQUEST map.
-     * @throws TestingFrameworkException a problem such as an invalid URL
-     */
-    public Map<String, Object> initRequest() throws TestingFrameworkException {
-        // initialize to some helpful defaults
-        final Map<String, Object> ret = new HashMap<String, Object>();
-        ret.put(PATH, TestingFramework.DEFAULT_REQUEST_PATH);
-        ret.put(BODY, TestingFramework.DEFAULT_REQUEST_BODY);
-        ret.put(CONTENT_TYPE, TestingFramework.DEFAULT_REQUEST_CONTENT_TYPE);
-        ret.put(QUERY, new HashMap<String, String>(TestingFramework.DEFAULT_REQUEST_QUERY));
-        ret.put(HEADERS, new HashMap<String, String>(TestingFramework.DEFAULT_REQUEST_HEADERS));
-        ret.put(PROTOCOL_VERSION, TestingFramework.DEFAULT_REQUEST_PROTOCOL_VERSION);
-
-        // GET is the default method.
-        if (! request.containsKey(METHOD)) {
-            request.put(METHOD, "GET");
-        }
-        ret.putAll(request);
-
-        moveAnyParametersInPathToQuery(ret);
-
-        return ret;
-    }
-
-    private void moveAnyParametersInPathToQuery(final Map<String, Object> request) throws TestingFrameworkException {
-        try {
-            final String path = (String) request.get(PATH);
-            if (path != null) {
-                final URI uri = path.startsWith("/") ? new URI("http://localhost:8080" + path) :
-                                                 new URI("http://localhost:8080/");
-                final List<NameValuePair> params = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8);
-                @SuppressWarnings("unchecked")
-                final Map<String, Object> queryMap = (Map<String, Object>) request.get(QUERY);
-                for (NameValuePair param : params) {
-                    queryMap.put(param.getName(), param.getValue());
-                }
-                if (! params.isEmpty()) {
-                    request.put(PATH, uri.getPath());
-                }
-            }
-        } catch (URISyntaxException e) {
-            throw new TestingFrameworkException(e);
-        }
-    }
-
-    /**
-     * Returns an expected response with defaults for any parameter that is not specified.
-     *
-     * @return the RESPONSE map.
-     */
-    public Map<String, Object> initResponseExpectations() {
-        // 200 is the default status.
-        if (! response.containsKey(STATUS)) {
-            response.put(STATUS, 200);
-        }
-
-        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
-        // initialize to some helpful defaults
-        responseExpectations.put(BODY, TestingFramework.DEFAULT_RESPONSE_BODY);
-        responseExpectations.put(CONTENT_TYPE, TestingFramework.DEFAULT_RESPONSE_CONTENT_TYPE);
-        responseExpectations.put(HEADERS, new HashMap<String, String>(TestingFramework.DEFAULT_RESPONSE_HEADERS));
-
-        // Now override any defaults with what is requested.
-        responseExpectations.putAll(response);
-
-        return responseExpectations;
-    }
-
-    @Override
-    public String toString() {
-        return "request: " + request + "\nresponse: " + response;
-    }
-}
+/*
+ * ====================================================================
+ * 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.PATH;
+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.REQUEST;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.RESPONSE;
+import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.STATUS;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hc.core5.http.NameValuePair;
+import org.apache.hc.core5.util.URLEncodedUtils; public class FrameworkTest {
+    private Map<String, Object> request = new HashMap<String, Object>();
+    private Map<String, Object> response = new HashMap<String, Object>();
+
+    /**
+     * Constructs a test with default values.
+     */
+    public FrameworkTest() {
+        this(null);
+    }
+
+    /**
+     * Constructs a test with values that are passed in as well as defaults
+     * for values that are not passed in.
+     *
+     * @param test Contains a REQUEST and an expected RESPONSE.
+     *             See {@link ClientPOJOAdapter} for details.
+     */
+    @SuppressWarnings("unchecked")
+    public FrameworkTest(final Map<String, Object> test) {
+        if (test != null) {
+            if (test.containsKey(REQUEST)) {
+                request = (Map<String, Object>) test.get(REQUEST);
+            }
+            if (test.containsKey(RESPONSE)) {
+                response = (Map<String, Object>) test.get(RESPONSE);
+            }
+        }
+    }
+
+    /**
+     * Returns a request with defaults for any parameter that is not specified.
+     *
+     * @return a REQUEST map.
+     * @throws TestingFrameworkException a problem such as an invalid URL
+     */
+    public Map<String, Object> initRequest() throws TestingFrameworkException {
+        // initialize to some helpful defaults
+        final Map<String, Object> ret = new HashMap<String, Object>();
+        ret.put(PATH, TestingFramework.DEFAULT_REQUEST_PATH);
+        ret.put(BODY, TestingFramework.DEFAULT_REQUEST_BODY);
+        ret.put(CONTENT_TYPE, TestingFramework.DEFAULT_REQUEST_CONTENT_TYPE);
+        ret.put(QUERY, new HashMap<String, String>(TestingFramework.DEFAULT_REQUEST_QUERY));
+        ret.put(HEADERS, new HashMap<String, String>(TestingFramework.DEFAULT_REQUEST_HEADERS));
+        ret.put(PROTOCOL_VERSION, TestingFramework.DEFAULT_REQUEST_PROTOCOL_VERSION);
+
+        // GET is the default method.
+        if (! request.containsKey(METHOD)) {
+            request.put(METHOD, "GET");
+        }
+        ret.putAll(request);
+
+        moveAnyParametersInPathToQuery(ret);
+
+        return ret;
+    }
+
+    private void moveAnyParametersInPathToQuery(final Map<String, Object> request) throws TestingFrameworkException {
+        try {
+            final String path = (String) request.get(PATH);
+            if (path != null) {
+                final URI uri = path.startsWith("/") ? new URI("http://localhost:8080" + path) :
+                                                 new URI("http://localhost:8080/");
+                final List<NameValuePair> params = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8);
+                @SuppressWarnings("unchecked")
+                final Map<String, Object> queryMap = (Map<String, Object>) request.get(QUERY);
+                for (NameValuePair param : params) {
+                    queryMap.put(param.getName(), param.getValue());
+                }
+                if (! params.isEmpty()) {
+                    request.put(PATH, uri.getPath());
+                }
+            }
+        } catch (URISyntaxException e) {
+            throw new TestingFrameworkException(e);
+        }
+    }
+
+    /**
+     * Returns an expected response with defaults for any parameter that is not specified.
+     *
+     * @return the RESPONSE map.
+     */
+    public Map<String, Object> initResponseExpectations() {
+        // 200 is the default status.
+        if (! response.containsKey(STATUS)) {
+            response.put(STATUS, 200);
+        }
+
+        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
+        // initialize to some helpful defaults
+        responseExpectations.put(BODY, TestingFramework.DEFAULT_RESPONSE_BODY);
+        responseExpectations.put(CONTENT_TYPE, TestingFramework.DEFAULT_RESPONSE_CONTENT_TYPE);
+        responseExpectations.put(HEADERS, new HashMap<String, String>(TestingFramework.DEFAULT_RESPONSE_HEADERS));
+
+        // Now override any defaults with what is requested.
+        responseExpectations.putAll(response);
+
+        return responseExpectations;
+    }
+
+    @Override
+    public String toString() {
+        return "request: " + request + "\nresponse: " + response;
+    }
+}



Mime
View raw message