camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bvah...@apache.org
Subject camel git commit: Rename and reorganize the test to effectively verify the usage of the useSystemProperties option without a false-positive effect. Also fix the CS by another test
Date Sun, 08 May 2016 09:23:18 GMT
Repository: camel
Updated Branches:
  refs/heads/master a1705aa09 -> f18fe8ade


Rename and reorganize the test to effectively verify the usage of the useSystemProperties
option without a false-positive effect. Also fix the CS by another test

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f18fe8ad
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f18fe8ad
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f18fe8ad

Branch: refs/heads/master
Commit: f18fe8ade1b6cc36ec774f71456bbe6ca48617a9
Parents: a1705aa
Author: Babak Vahdat <bvahdat@apache.org>
Authored: Sun May 8 11:22:52 2016 +0200
Committer: Babak Vahdat <bvahdat@apache.org>
Committed: Sun May 8 11:22:52 2016 +0200

----------------------------------------------------------------------
 .../HttpProducerWithSystemPropertiesTest.java   | 167 +++++++++++++++++++
 .../component/http4/HttpProxyServerTest.java    |   4 +-
 ...HttpProxyServerWithSystemPropertiesTest.java | 165 ------------------
 3 files changed, 169 insertions(+), 167 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f18fe8ad/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerWithSystemPropertiesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerWithSystemPropertiesTest.java
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerWithSystemPropertiesTest.java
new file mode 100644
index 0000000..0ff680c
--- /dev/null
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerWithSystemPropertiesTest.java
@@ -0,0 +1,167 @@
+/**
+ * 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.
+ */
+package org.apache.camel.component.http4;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.http4.handler.HeaderValidationHandler;
+import org.apache.commons.codec.BinaryDecoder;
+import org.apache.commons.codec.DecoderException;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.http.Header;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseInterceptor;
+import org.apache.http.HttpStatus;
+import org.apache.http.ProtocolException;
+import org.apache.http.auth.AUTH;
+import org.apache.http.impl.bootstrap.HttpServer;
+import org.apache.http.impl.bootstrap.ServerBootstrap;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
+import org.apache.http.protocol.ImmutableHttpProcessor;
+import org.apache.http.protocol.ResponseContent;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ * @version 
+ */
+public class HttpProducerWithSystemPropertiesTest extends BaseHttpTest {
+
+    private static Object defaultSystemHttpAgent;
+    private HttpServer localServer;
+
+    @BeforeClass
+    public static void setUpSystemProperties() throws Exception {
+        // the 'http.agent' java system-property corresponds to the http 'User-Agent' header
+        defaultSystemHttpAgent = System.getProperties().setProperty("http.agent", "myCoolCamelCaseAgent");
+    }
+
+    @AfterClass
+    public static void resetSystemProperties() throws Exception {
+        System.getProperties().setProperty("http.agent", String.valueOf(defaultSystemHttpAgent));
+    }
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        Map<String, String> expectedHeaders = new HashMap<>();
+        expectedHeaders.put("User-Agent", "myCoolCamelCaseAgent");
+
+        localServer = ServerBootstrap.bootstrap().
+                setHttpProcessor(getBasicHttpProcessor()).
+                setConnectionReuseStrategy(getConnectionReuseStrategy()).
+                setResponseFactory(getHttpResponseFactory()).
+                setExpectationVerifier(getHttpExpectationVerifier()).
+                setSslContext(getSSLContext()).
+                registerHandler("*", new HeaderValidationHandler("GET", null, null, getExpectedContent(),
expectedHeaders)).create();
+        localServer.start();
+
+        super.setUp();
+    }
+
+    @After
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        if (localServer != null) {
+            localServer.stop();
+        }
+    }
+
+    @Override
+    protected HttpProcessor getBasicHttpProcessor() {
+        List<HttpRequestInterceptor> requestInterceptors = new ArrayList<HttpRequestInterceptor>();
+        requestInterceptors.add(new RequestProxyBasicAuth());
+        List<HttpResponseInterceptor> responseInterceptors = new ArrayList<HttpResponseInterceptor>();
+        responseInterceptors.add(new ResponseContent());
+        responseInterceptors.add(new ResponseProxyBasicUnauthorized());
+        ImmutableHttpProcessor httpproc = new ImmutableHttpProcessor(requestInterceptors,
responseInterceptors);
+        return httpproc;
+    }
+
+    @Test
+    public void httpGetWithProxyFromSystemProperties() throws Exception {
+
+        Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName()
+ ":" + localServer.getLocalPort() + "?useSystemProperties=true", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+            }
+        });
+
+        assertExchange(exchange);
+    }
+
+    private static class RequestProxyBasicAuth implements HttpRequestInterceptor {
+        public void process(final HttpRequest request, final HttpContext context) throws
HttpException, IOException {
+            String auth = null;
+
+            String requestLine = request.getRequestLine().toString();
+            // assert we set a write GET URI
+            if (requestLine.contains("http4://localhost")) {
+                throw new HttpException("Get a wrong proxy GET url");
+            }
+            Header h = request.getFirstHeader(AUTH.PROXY_AUTH_RESP);
+            if (h != null) {
+                String s = h.getValue();
+                if (s != null) {
+                    auth = s.trim();
+                }
+            }
+
+            if (auth != null) {
+                int i = auth.indexOf(' ');
+                if (i == -1) {
+                    throw new ProtocolException("Invalid Authorization header: " + auth);
+                }
+                String authscheme = auth.substring(0, i);
+                if (authscheme.equalsIgnoreCase("basic")) {
+                    String s = auth.substring(i + 1).trim();
+                    byte[] credsRaw = s.getBytes("ASCII");
+                    BinaryDecoder codec = new Base64();
+                    try {
+                        String creds = new String(codec.decode(credsRaw), "ASCII");
+                        context.setAttribute("proxy-creds", creds);
+                    } catch (DecoderException ex) {
+                        throw new ProtocolException("Malformed BASIC credentials");
+                    }
+                }
+            }
+        }
+    }
+
+    private static class ResponseProxyBasicUnauthorized implements HttpResponseInterceptor
{
+        public void process(final HttpResponse response, final HttpContext context) throws
HttpException, IOException {
+            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED)
{
+                response.addHeader(AUTH.PROXY_AUTH, "Basic realm=\"test realm\"");
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/f18fe8ad/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerTest.java
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerTest.java
index 90c26ca..d09202e 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerTest.java
@@ -97,12 +97,12 @@ public class HttpProxyServerTest extends BaseHttpTest {
     @Test
     public void testDifferentHttpProxyConfigured() throws Exception {
         HttpEndpoint http1 = context.getEndpoint("http4://www.google.com?proxyAuthHost=www.myproxy.com&proxyAuthPort=1234",
HttpEndpoint.class);
-        HttpEndpoint http2 = context.getEndpoint("http4://www.google.com?test=parameter&proxyAuthHost=www.myotherproxy.com&proxyAuthPort=2345",
HttpEndpoint.class);
+        HttpEndpoint http2 = context.getEndpoint("http4://www.google.com?test=parameter&proxyAuthHost=www.otherproxy.com&proxyAuthPort=2345",
HttpEndpoint.class);
         // HttpClientBuilder doesn't support get the configuration here
         
         //As the endpointUri is recreated, so the parameter could be in different place,
so we use the URISupport.normalizeUri
         assertEquals("Get a wrong endpoint uri of http1", "http4://www.google.com?proxyAuthHost=www.myproxy.com&proxyAuthPort=1234",
URISupport.normalizeUri(http1.getEndpointUri()));
-        assertEquals("Get a wrong endpoint uri of http2", "http4://www.google.com?proxyAuthHost=www.myotherproxy.com&proxyAuthPort=2345&test=parameter",
URISupport.normalizeUri(http2.getEndpointUri()));
+        assertEquals("Get a wrong endpoint uri of http2", "http4://www.google.com?proxyAuthHost=www.otherproxy.com&proxyAuthPort=2345&test=parameter",
URISupport.normalizeUri(http2.getEndpointUri()));
 
         assertEquals("Should get the same EndpointKey", http1.getEndpointKey(), http2.getEndpointKey());
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/f18fe8ad/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerWithSystemPropertiesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerWithSystemPropertiesTest.java
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerWithSystemPropertiesTest.java
deleted file mode 100644
index 5e686da..0000000
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProxyServerWithSystemPropertiesTest.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.http4;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.component.http4.handler.HeaderValidationHandler;
-import org.apache.commons.codec.BinaryDecoder;
-import org.apache.commons.codec.DecoderException;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.http.Header;
-import org.apache.http.HttpException;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpRequestInterceptor;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpResponseInterceptor;
-import org.apache.http.HttpStatus;
-import org.apache.http.ProtocolException;
-import org.apache.http.auth.AUTH;
-import org.apache.http.impl.bootstrap.HttpServer;
-import org.apache.http.impl.bootstrap.ServerBootstrap;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.protocol.HttpProcessor;
-import org.apache.http.protocol.ImmutableHttpProcessor;
-import org.apache.http.protocol.ResponseContent;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- *
- * @version 
- */
-public class HttpProxyServerWithSystemPropertiesTest extends BaseHttpTest {
-
-    private HttpServer proxy;
-
-    @Before
-    @Override
-    public void setUp() throws Exception {
-        Map<String, String> expectedHeaders = new HashMap<>();
-        proxy = ServerBootstrap.bootstrap().
-                setHttpProcessor(getBasicHttpProcessor()).
-                setConnectionReuseStrategy(getConnectionReuseStrategy()).
-                setResponseFactory(getHttpResponseFactory()).
-                setExpectationVerifier(getHttpExpectationVerifier()).
-                setSslContext(getSSLContext()).
-                registerHandler("*", new HeaderValidationHandler("GET", null, null, getExpectedContent(),
expectedHeaders)).create();
-        proxy.start();
-
-        expectedHeaders.put("Connection", "Keep-Alive");
-        expectedHeaders.put("Host", getProxyHost() + ":" + getProxyPort());
-
-        System.getProperties().setProperty("http.proxyHost", getProxyHost());
-        System.getProperties().setProperty("http.proxyPort", getProxyPort());
-
-        super.setUp();
-    }
-
-    @After
-    @Override
-    public void tearDown() throws Exception {
-        super.tearDown();
-
-        if (proxy != null) {
-            proxy.stop();
-        }
-    }
-
-    @Override
-    protected HttpProcessor getBasicHttpProcessor() {
-        List<HttpRequestInterceptor> requestInterceptors = new ArrayList<HttpRequestInterceptor>();
-        requestInterceptors.add(new RequestProxyBasicAuth());
-        List<HttpResponseInterceptor> responseInterceptors = new ArrayList<HttpResponseInterceptor>();
-        responseInterceptors.add(new ResponseContent());
-        responseInterceptors.add(new ResponseProxyBasicUnauthorized());
-        ImmutableHttpProcessor httpproc = new ImmutableHttpProcessor(requestInterceptors,
responseInterceptors);
-        return httpproc;
-    }
-
-    @Test
-    public void httpGetWithProxyFromSystemProperties() throws Exception {
-
-        Exchange exchange = template.request("http4://" + getProxyHost() + ":" + getProxyPort()
+ "?useSystemProperties=true", new Processor() {
-            public void process(Exchange exchange) throws Exception {
-            }
-        });
-
-        assertExchange(exchange);
-    }
-
-    private String getProxyHost() {
-        return proxy.getInetAddress().getHostName();
-    }
-
-    private String getProxyPort() {
-        return "" + proxy.getLocalPort();
-    }
-
-    private static class RequestProxyBasicAuth implements HttpRequestInterceptor {
-        public void process(final HttpRequest request, final HttpContext context) throws
HttpException, IOException {
-            String auth = null;
-
-            String requestLine = request.getRequestLine().toString();
-            // assert we set a write GET URI
-            if (requestLine.contains("http4://localhost")) {
-                throw new HttpException("Get a wrong proxy GET url");
-            }
-            Header h = request.getFirstHeader(AUTH.PROXY_AUTH_RESP);
-            if (h != null) {
-                String s = h.getValue();
-                if (s != null) {
-                    auth = s.trim();
-                }
-            }
-
-            if (auth != null) {
-                int i = auth.indexOf(' ');
-                if (i == -1) {
-                    throw new ProtocolException("Invalid Authorization header: " + auth);
-                }
-                String authscheme = auth.substring(0, i);
-                if (authscheme.equalsIgnoreCase("basic")) {
-                    String s = auth.substring(i + 1).trim();
-                    byte[] credsRaw = s.getBytes("ASCII");
-                    BinaryDecoder codec = new Base64();
-                    try {
-                        String creds = new String(codec.decode(credsRaw), "ASCII");
-                        context.setAttribute("proxy-creds", creds);
-                    } catch (DecoderException ex) {
-                        throw new ProtocolException("Malformed BASIC credentials");
-                    }
-                }
-            }
-        }
-    }
-
-    private static class ResponseProxyBasicUnauthorized implements HttpResponseInterceptor
{
-        public void process(final HttpResponse response, final HttpContext context) throws
HttpException, IOException {
-            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED)
{
-                response.addHeader(AUTH.PROXY_AUTH, "Basic realm=\"test realm\"");
-            }
-        }
-    }
-}


Mime
View raw message