hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1788709 [3/5] - in /httpcomponents: httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ httpclient/trunk/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/ httpclient/trunk/httpclient5-o...
Date Sun, 26 Mar 2017 02:43:05 GMT
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=1788709&r1=1788708&r2=1788709&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
Sun Mar 26 02:43:03 2017
@@ -152,9 +152,9 @@ public class TestingFramework {
         /*
          * By default, a set of tests that will exercise each HTTP method are pre-loaded.
          */
-        for (String method : ALL_METHODS) {
+        for (final String method : ALL_METHODS) {
             final List<Integer> statusList = Arrays.asList(200, 201);
-            for (Integer status : statusList) {
+            for (final Integer status : statusList) {
                 final Map<String, Object> request = new HashMap<String, Object>();
                 request.put(METHOD, method);
 
@@ -195,10 +195,10 @@ public class TestingFramework {
         startServer();
 
         try {
-            for (FrameworkTest test : tests) {
+            for (final FrameworkTest test : tests) {
                 try {
                     callAdapter(test);
-                } catch (Throwable t) {
+                } catch (final Throwable t) {
                     processThrowable(t, test);
                 }
             }
@@ -235,7 +235,7 @@ public class TestingFramework {
         server = serverBootstrap.create();
         try {
             server.start();
-        } catch (IOException e) {
+        } catch (final IOException e) {
             throw new TestingFrameworkException(e);
         }
 
@@ -370,7 +370,7 @@ public class TestingFramework {
         if (expectedHeaders == null) {
             return;
         }
-        for (Map.Entry<String, String> expectedHeader : ((Map<String, String>)
expectedHeaders).entrySet()) {
+        for (final 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);

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=1788709&r1=1788708&r2=1788709&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
Sun Mar 26 02:43:03 2017
@@ -139,10 +139,10 @@ public class TestingFrameworkRequestHand
                 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) {
+                for (final NameValuePair actualParam : actualParams) {
                     actualParamsMap.put(actualParam.getName(), actualParam.getValue());
                 }
-                for (Map.Entry<String, String> expectedParam : expectedQuery.entrySet())
{
+                for (final Map.Entry<String, String> expectedParam : expectedQuery.entrySet())
{
                     final String key = expectedParam.getKey();
                     if (! actualParamsMap.containsKey(key)) {
                         throw new TestingFrameworkException("Expected parameter not found:
" + key);
@@ -164,10 +164,10 @@ public class TestingFrameworkRequestHand
             if (expectedHeaders != null) {
                 final Map<String, String> actualHeadersMap = new HashMap<String,
String>();
                 final Header[] actualHeaders = request.getAllHeaders();
-                for (Header header : actualHeaders) {
+                for (final Header header : actualHeaders) {
                     actualHeadersMap.put(header.getName(), header.getValue());
                 }
-                for (Entry<String, String> expectedHeader : expectedHeaders.entrySet())
{
+                for (final Entry<String, String> expectedHeader : expectedHeaders.entrySet())
{
                     final String key = expectedHeader.getKey();
                     if (! actualHeadersMap.containsKey(key)) {
                         throw new TestingFrameworkException("Expected header not found: "
+ key);
@@ -238,12 +238,12 @@ public class TestingFrameworkRequestHand
             @SuppressWarnings("unchecked")
             final Map<String, String> desiredHeaders = (Map<String, String>)
desiredResponse.get(HEADERS);
             if (desiredHeaders != null) {
-                for (Entry<String, String> entry : desiredHeaders.entrySet()) {
+                for (final Entry<String, String> entry : desiredHeaders.entrySet())
{
                     response.setHeader(entry.getKey(), entry.getValue());
                 }
             }
 
-        } catch (Throwable t) {
+        } catch (final Throwable t) {
             /*
              * Save the throwable to be later retrieved by a call to assertNothingThrown().
              */

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/IOReactorExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/IOReactorExecutor.java?rev=1788709&r1=1788708&r2=1788709&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/IOReactorExecutor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/IOReactorExecutor.java
Sun Mar 26 02:43:03 2017
@@ -110,7 +110,7 @@ abstract class IOReactorExecutor<T exten
                     public void run() {
                         try {
                             ioReactorRef.get().execute();
-                        } catch (Exception ex) {
+                        } catch (final Exception ex) {
                             if (exceptionListener != null) {
                                 exceptionListener.onError(ex);
                             }

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalHttp2StreamListener.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalHttp2StreamListener.java?rev=1788709&r1=1788708&r2=1788709&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalHttp2StreamListener.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalHttp2StreamListener.java
Sun Mar 26 02:43:03 2017
@@ -61,7 +61,7 @@ class InternalHttp2StreamListener implem
             final LogAppendable logAppendable = new LogAppendable(frameLog, prefix);
             framePrinter.printFrameInfo(frame, logAppendable);
             logAppendable.flush();
-        } catch (IOException ignore) {
+        } catch (final IOException ignore) {
         }
     }
 
@@ -70,7 +70,7 @@ class InternalHttp2StreamListener implem
             final LogAppendable logAppendable = new LogAppendable(framePayloadLog, prefix);
             framePrinter.printPayload(frame, logAppendable);
             logAppendable.flush();
-        } catch (IOException ignore) {
+        } catch (final IOException ignore) {
         }
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/TestClassicHttp.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/TestClassicHttp.java?rev=1788709&r1=1788708&r2=1788709&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/TestClassicHttp.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/TestClassicHttp.java
Sun Mar 26 02:43:03 2017
@@ -91,7 +91,7 @@ public class TestClassicHttp {
                 try {
                     server.shutdown(3, TimeUnit.SECONDS);
                     server = null;
-                } catch (Exception ignore) {
+                } catch (final Exception ignore) {
                 }
             }
         }
@@ -115,7 +115,7 @@ public class TestClassicHttp {
                 try {
                     client.shutdown();
                     client = null;
-                } catch (Exception ignore) {
+                } catch (final Exception ignore) {
                 }
             }
         }

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestClassicTestClientTestingAdapter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestClassicTestClientTestingAdapter.java?rev=1788709&r1=1788708&r2=1788709&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestClassicTestClientTestingAdapter.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestClassicTestClientTestingAdapter.java
Sun Mar 26 02:43:03 2017
@@ -1,318 +1,318 @@
-/*
- * ====================================================================
- * 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.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.STATUS;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.ClassicHttpResponse;
-import org.apache.hc.core5.http.HttpEntity;
-import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.HttpStatus;
-import org.apache.hc.core5.http.io.HttpRequestHandler;
-import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
-import org.apache.hc.core5.http.io.entity.EntityUtils;
-import org.apache.hc.core5.http.protocol.HttpContext;
-import org.apache.hc.core5.testing.classic.ClassicTestServer;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-public class TestClassicTestClientTestingAdapter {
-    private static final String ECHO_PATH = "echo/something";
-    private static final String CUSTOM_PATH = "custom/something";
-
-    private ClassicTestServer server;
-
-   @Before
-    public void initServer() throws Exception {
-        this.server = new ClassicTestServer();
-        this.server.setTimeout(5000);
-    }
-
-    @After
-    public void shutDownServer() throws Exception {
-        if (this.server != null) {
-            this.server.shutdown(0, TimeUnit.SECONDS);
-        }
-    }
-
-    @Test
-    public void nullDefaultURI() throws Exception {
-        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
-
-        final String defaultURI = null;
-        final Map<String, Object> request = new HashMap<String, Object>();
-        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
-        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
-
-        try {
-            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
-            Assert.fail("WebServerTestingFrameworkException should have been thrown");
-        } catch (TestingFrameworkException e) {
-            // expected
-        }
-    }
-
-    @Test
-    public void nullRequest() throws Exception {
-        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
-
-        final String defaultURI = "";
-        final Map<String, Object> request = null;
-        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
-        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
-
-        try {
-            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
-            Assert.fail("WebServerTestingFrameworkException should have been thrown");
-        } catch (TestingFrameworkException e) {
-            // expected
-        }
-    }
-
-    @Test
-    public void nullRequestHandler() throws Exception {
-        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
-
-        final String defaultURI = "";
-        final Map<String, Object> request = new HashMap<String, Object>();
-        final TestingFrameworkRequestHandler requestHandler = null;
-        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
-
-        try {
-            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
-            Assert.fail("WebServerTestingFrameworkException should have been thrown");
-        } catch (TestingFrameworkException e) {
-            // expected
-        }
-    }
-
-    @Test
-    public void nullResponseExpectations() throws Exception {
-        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
-
-        final String defaultURI = "";
-        final Map<String, Object> request = new HashMap<String, Object>();
-        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
-        final Map<String, Object> responseExpectations = null;
-
-        try {
-            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
-            Assert.fail("WebServerTestingFrameworkException should have been thrown");
-        } catch (TestingFrameworkException e) {
-            // expected
-        }
-    }
-
-    @Test
-    public void noPath() throws Exception {
-        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
-
-        final String defaultURI = "";
-        final Map<String, Object> request = new HashMap<String, Object>();
-        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
-        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
-
-        try {
-            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
-            Assert.fail("WebServerTestingFrameworkException should have been thrown");
-        } catch (TestingFrameworkException e) {
-            // expected
-        }
-    }
-
-    @Test
-    public void noMethod() throws Exception {
-        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
-
-        final String defaultURI = "";
-
-        final Map<String, Object> request = new HashMap<String, Object>();
-        request.put(PATH, ECHO_PATH);
-
-        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
-        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
-
-        try {
-            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
-            Assert.fail("WebServerTestingFrameworkException should have been thrown");
-        } catch (TestingFrameworkException e) {
-            // expected
-        }
-    }
-
-    @Test
-    public void invalidMethod() throws Exception {
-        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
-
-        final String defaultURI = "";
-
-        final Map<String, Object> request = new HashMap<String, Object>();
-        request.put(PATH, ECHO_PATH);
-        request.put(METHOD, "JUNK");
-
-        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
-        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
-
-        try {
-            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
-            Assert.fail("WebServerTestingFrameworkException should have been thrown");
-        } catch (TestingFrameworkException e) {
-            // expected
-        }
-    }
-
-    @Test
-    public void withLiveServerEcho() throws Exception {
-        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
-
-        // Initialize the server-side request handler
-        server.registerHandler("/echo/*", new HttpRequestHandler() {
-
-            @Override
-            public void handle(
-                    final ClassicHttpRequest request,
-                    final ClassicHttpResponse response,
-                    final HttpContext context) throws HttpException, IOException {
-
-                final HttpEntity entity = request.getEntity();
-                // For some reason, just putting the incoming entity into
-                // the response will not work. We have to buffer the message.
-                final byte[] data;
-                if (entity == null) {
-                    data = new byte [0];
-                } else {
-                    data = EntityUtils.toByteArray(entity);
-                }
-
-                final ByteArrayEntity bae = new ByteArrayEntity(data);
-                if (entity != null) {
-                    bae.setContentType(entity.getContentType());
-                }
-
-                response.setCode(HttpStatus.SC_OK);
-                response.setEntity(bae);
-            }
-
-        });
-
-
-        this.server.start();
-        final HttpHost target = new HttpHost("localhost", this.server.getPort());
-
-        final String defaultURI = target.toString();
-        final Map<String, Object> request = new HashMap<String, Object>();
-        request.put(PATH, ECHO_PATH);
-        request.put(METHOD, "POST");
-        final String body = "mybody";
-        request.put(BODY, body);
-
-        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
-
-        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
-        final Map<String, Object> response = adapter.execute(defaultURI, request, requestHandler,
responseExpectations);
-
-        Assert.assertNotNull("response should not be null", response);
-        Assert.assertEquals("status unexpected", 200, response.get(STATUS));
-
-        @SuppressWarnings("unchecked")
-        final Map<String, Object> headers = (Map<String, Object>) response.get(HEADERS);
-        Assert.assertNotNull("headers should be in the response", headers);
-        Assert.assertFalse(headers.isEmpty());
-
-        final String returnedBody = (String) response.get(BODY);
-        Assert.assertNotNull("body should be in the response", returnedBody);
-        Assert.assertEquals("Body should be echoed", body, returnedBody);
-
-    }
-
-    @Test
-    public void withLiveServerCustomRequestHandler() throws Exception {
-        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
-
-        final TestingFrameworkRequestHandler requestHandler = new TestingFrameworkRequestHandler()
{
-            @Override
-            public void handle(final ClassicHttpRequest request, final ClassicHttpResponse
response, final HttpContext context)
-                    throws HttpException, IOException {
-                try {
-                    Assert.assertEquals("method not expected", "junk", request.getMethod());
-                } catch (Throwable t) {
-                    thrown = t;
-                }
-            }
-        };
-        server.registerHandler("/custom/*", requestHandler);
-
-        this.server.start();
-        final HttpHost target = new HttpHost("localhost", this.server.getPort());
-        final String defaultURI = target.toString();
-        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
-
-        final Map<String, Object> request = new HashMap<String, Object>();
-        request.put(PATH, CUSTOM_PATH);
-
-        for (String method : TestingFramework.ALL_METHODS) {
-            request.put(METHOD, method);
-
-            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
-        }
-    }
-
-    @Test
-    public void modifyRequest() {
-        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
-
-        final Map<String, Object> request = new HashMap<String, Object>();
-        final Map<String, Object> returnedRequest = adapter.modifyRequest(request);
-
-        Assert.assertSame("Same request was not returned as expected.", request, returnedRequest);
-    }
-
-    @Test
-    public void modifyResponseExpectations() {
-        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
-
-        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
-        final Map<String, Object> returnedResponseExpectations = adapter.modifyResponseExpectations(null,
responseExpectations);
-
-        Assert.assertSame("Same response expectations were not returned as expected.", responseExpectations,
returnedResponseExpectations);
-    }
-}
+/*
+ * ====================================================================
+ * 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.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.STATUS;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.io.HttpRequestHandler;
+import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.testing.classic.ClassicTestServer;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestClassicTestClientTestingAdapter {
+    private static final String ECHO_PATH = "echo/something";
+    private static final String CUSTOM_PATH = "custom/something";
+
+    private ClassicTestServer server;
+
+   @Before
+    public void initServer() throws Exception {
+        this.server = new ClassicTestServer();
+        this.server.setTimeout(5000);
+    }
+
+    @After
+    public void shutDownServer() throws Exception {
+        if (this.server != null) {
+            this.server.shutdown(0, TimeUnit.SECONDS);
+        }
+    }
+
+    @Test
+    public void nullDefaultURI() throws Exception {
+        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
+
+        final String defaultURI = null;
+        final Map<String, Object> request = new HashMap<String, Object>();
+        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
+        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
+
+        try {
+            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
+            Assert.fail("WebServerTestingFrameworkException should have been thrown");
+        } catch (final TestingFrameworkException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void nullRequest() throws Exception {
+        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
+
+        final String defaultURI = "";
+        final Map<String, Object> request = null;
+        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
+        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
+
+        try {
+            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
+            Assert.fail("WebServerTestingFrameworkException should have been thrown");
+        } catch (final TestingFrameworkException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void nullRequestHandler() throws Exception {
+        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
+
+        final String defaultURI = "";
+        final Map<String, Object> request = new HashMap<String, Object>();
+        final TestingFrameworkRequestHandler requestHandler = null;
+        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
+
+        try {
+            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
+            Assert.fail("WebServerTestingFrameworkException should have been thrown");
+        } catch (final TestingFrameworkException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void nullResponseExpectations() throws Exception {
+        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
+
+        final String defaultURI = "";
+        final Map<String, Object> request = new HashMap<String, Object>();
+        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
+        final Map<String, Object> responseExpectations = null;
+
+        try {
+            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
+            Assert.fail("WebServerTestingFrameworkException should have been thrown");
+        } catch (final TestingFrameworkException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void noPath() throws Exception {
+        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
+
+        final String defaultURI = "";
+        final Map<String, Object> request = new HashMap<String, Object>();
+        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
+        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
+
+        try {
+            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
+            Assert.fail("WebServerTestingFrameworkException should have been thrown");
+        } catch (final TestingFrameworkException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void noMethod() throws Exception {
+        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
+
+        final String defaultURI = "";
+
+        final Map<String, Object> request = new HashMap<String, Object>();
+        request.put(PATH, ECHO_PATH);
+
+        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
+        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
+
+        try {
+            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
+            Assert.fail("WebServerTestingFrameworkException should have been thrown");
+        } catch (final TestingFrameworkException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void invalidMethod() throws Exception {
+        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
+
+        final String defaultURI = "";
+
+        final Map<String, Object> request = new HashMap<String, Object>();
+        request.put(PATH, ECHO_PATH);
+        request.put(METHOD, "JUNK");
+
+        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
+        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
+
+        try {
+            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
+            Assert.fail("WebServerTestingFrameworkException should have been thrown");
+        } catch (final TestingFrameworkException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void withLiveServerEcho() throws Exception {
+        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
+
+        // Initialize the server-side request handler
+        server.registerHandler("/echo/*", new HttpRequestHandler() {
+
+            @Override
+            public void handle(
+                    final ClassicHttpRequest request,
+                    final ClassicHttpResponse response,
+                    final HttpContext context) throws HttpException, IOException {
+
+                final HttpEntity entity = request.getEntity();
+                // For some reason, just putting the incoming entity into
+                // the response will not work. We have to buffer the message.
+                final byte[] data;
+                if (entity == null) {
+                    data = new byte [0];
+                } else {
+                    data = EntityUtils.toByteArray(entity);
+                }
+
+                final ByteArrayEntity bae = new ByteArrayEntity(data);
+                if (entity != null) {
+                    bae.setContentType(entity.getContentType());
+                }
+
+                response.setCode(HttpStatus.SC_OK);
+                response.setEntity(bae);
+            }
+
+        });
+
+
+        this.server.start();
+        final HttpHost target = new HttpHost("localhost", this.server.getPort());
+
+        final String defaultURI = target.toString();
+        final Map<String, Object> request = new HashMap<String, Object>();
+        request.put(PATH, ECHO_PATH);
+        request.put(METHOD, "POST");
+        final String body = "mybody";
+        request.put(BODY, body);
+
+        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
+
+        final TestingFrameworkRequestHandler requestHandler = Mockito.mock(TestingFrameworkRequestHandler.class);
+        final Map<String, Object> response = adapter.execute(defaultURI, request, requestHandler,
responseExpectations);
+
+        Assert.assertNotNull("response should not be null", response);
+        Assert.assertEquals("status unexpected", 200, response.get(STATUS));
+
+        @SuppressWarnings("unchecked")
+        final Map<String, Object> headers = (Map<String, Object>) response.get(HEADERS);
+        Assert.assertNotNull("headers should be in the response", headers);
+        Assert.assertFalse(headers.isEmpty());
+
+        final String returnedBody = (String) response.get(BODY);
+        Assert.assertNotNull("body should be in the response", returnedBody);
+        Assert.assertEquals("Body should be echoed", body, returnedBody);
+
+    }
+
+    @Test
+    public void withLiveServerCustomRequestHandler() throws Exception {
+        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
+
+        final TestingFrameworkRequestHandler requestHandler = new TestingFrameworkRequestHandler()
{
+            @Override
+            public void handle(final ClassicHttpRequest request, final ClassicHttpResponse
response, final HttpContext context)
+                    throws HttpException, IOException {
+                try {
+                    Assert.assertEquals("method not expected", "junk", request.getMethod());
+                } catch (final Throwable t) {
+                    thrown = t;
+                }
+            }
+        };
+        server.registerHandler("/custom/*", requestHandler);
+
+        this.server.start();
+        final HttpHost target = new HttpHost("localhost", this.server.getPort());
+        final String defaultURI = target.toString();
+        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
+
+        final Map<String, Object> request = new HashMap<String, Object>();
+        request.put(PATH, CUSTOM_PATH);
+
+        for (final String method : TestingFramework.ALL_METHODS) {
+            request.put(METHOD, method);
+
+            adapter.execute(defaultURI, request, requestHandler, responseExpectations);
+        }
+    }
+
+    @Test
+    public void modifyRequest() {
+        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
+
+        final Map<String, Object> request = new HashMap<String, Object>();
+        final Map<String, Object> returnedRequest = adapter.modifyRequest(request);
+
+        Assert.assertSame("Same request was not returned as expected.", request, returnedRequest);
+    }
+
+    @Test
+    public void modifyResponseExpectations() {
+        final ClientTestingAdapter adapter = new ClassicTestClientTestingAdapter();
+
+        final Map<String, Object> responseExpectations = new HashMap<String, Object>();
+        final Map<String, Object> returnedResponseExpectations = adapter.modifyResponseExpectations(null,
responseExpectations);
+
+        Assert.assertSame("Same response expectations were not returned as expected.", responseExpectations,
returnedResponseExpectations);
+    }
+}

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestClientPOJOAdapter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestClientPOJOAdapter.java?rev=1788709&r1=1788708&r2=1788709&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestClientPOJOAdapter.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestClientPOJOAdapter.java
Sun Mar 26 02:43:03 2017
@@ -1,82 +1,82 @@
-/*
- * ====================================================================
- * 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.HashMap;
-import java.util.Map;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TestClientPOJOAdapter {
-    @Test
-    public void modifyRequest() throws Exception {
-        final ClientPOJOAdapter adapter = new ClassicTestClientAdapter();
-        final Map<String, Object> request = new HashMap<String, Object>();
-        final Map<String, Object> request2 = adapter.modifyRequest(request);
-
-        Assert.assertSame("request should have been returned", request, request2);
-    }
-
-    @Test
-    public void checkRequestSupport() throws Exception {
-        final ClientPOJOAdapter adapter = new ClassicTestClientAdapter();
-        final String reason = adapter.checkRequestSupport(null);
-
-        Assert.assertNull("reason should be null", reason);
-
-        adapter.assertRequestSupported(null);
-    }
-
-    @Test
-    public void checkRequestSupportThrows() throws Exception {
-        final ClientPOJOAdapter adapter = new ClientPOJOAdapter() {
-
-            @Override
-            public Map<String, Object> execute(final String defaultURI, final Map<String,
Object> request) throws Exception {
-                return null;
-            }
-
-            @Override
-            public String checkRequestSupport(final java.util.Map<String,Object> request)
{
-                return "A reason this request is not supported.";
-            }
-
-            @Override
-            public String getClientName() {
-                return null;
-            };
-        };
-
-        try {
-            adapter.assertRequestSupported(null);
-            Assert.fail("A Exception should have been thrown");
-        } catch (Exception e) {
-            // expected
-        }
-    }
-}
+/*
+ * ====================================================================
+ * 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.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestClientPOJOAdapter {
+    @Test
+    public void modifyRequest() throws Exception {
+        final ClientPOJOAdapter adapter = new ClassicTestClientAdapter();
+        final Map<String, Object> request = new HashMap<String, Object>();
+        final Map<String, Object> request2 = adapter.modifyRequest(request);
+
+        Assert.assertSame("request should have been returned", request, request2);
+    }
+
+    @Test
+    public void checkRequestSupport() throws Exception {
+        final ClientPOJOAdapter adapter = new ClassicTestClientAdapter();
+        final String reason = adapter.checkRequestSupport(null);
+
+        Assert.assertNull("reason should be null", reason);
+
+        adapter.assertRequestSupported(null);
+    }
+
+    @Test
+    public void checkRequestSupportThrows() throws Exception {
+        final ClientPOJOAdapter adapter = new ClientPOJOAdapter() {
+
+            @Override
+            public Map<String, Object> execute(final String defaultURI, final Map<String,
Object> request) throws Exception {
+                return null;
+            }
+
+            @Override
+            public String checkRequestSupport(final java.util.Map<String,Object> request)
{
+                return "A reason this request is not supported.";
+            }
+
+            @Override
+            public String getClientName() {
+                return null;
+            };
+        };
+
+        try {
+            adapter.assertRequestSupported(null);
+            Assert.fail("A Exception should have been thrown");
+        } catch (final Exception e) {
+            // expected
+        }
+    }
+}



Mime
View raw message