commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject [commons-vfs] branch master updated: Add proxy config for some http/https test (#108)
Date Mon, 03 Aug 2020 12:57:08 GMT
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e3d4dc  Add proxy config for some http/https test (#108)
6e3d4dc is described below

commit 6e3d4dce6ff3458d187948cee7b9f4f9fbdf36b5
Author: Lee <55973914+PeterAlfredLee@users.noreply.github.com>
AuthorDate: Mon Aug 3 20:52:31 2020 +0800

    Add proxy config for some http/https test (#108)
---
 .../http/test/GetContentInfoFunctionalTest.java    | 34 +++++++++++++++-
 .../http4/test/Http4GetContentInfoTest.java        | 34 +++++++++++++++-
 .../http4s/test/Http4sGetContentInfoTest.java      | 47 ++++++++++++----------
 .../http5/test/Http5GetContentInfoTest.java        | 34 +++++++++++++++-
 .../http5s/test/Http5sGetContentInfoTest.java      | 47 ++++++++++++----------
 .../https/test/GetContentInfoFunctionalTest.java   | 47 ++++++++++++----------
 6 files changed, 174 insertions(+), 69 deletions(-)

diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/test/GetContentInfoFunctionalTest.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/test/GetContentInfoFunctionalTest.java
index 91a0fea..26a2ec3 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/test/GetContentInfoFunctionalTest.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/test/GetContentInfoFunctionalTest.java
@@ -20,10 +20,15 @@ import org.apache.commons.vfs2.FileContent;
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileSystemException;
 import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.FileSystemOptions;
 import org.apache.commons.vfs2.VFS;
+import org.apache.commons.vfs2.provider.http.HttpFileSystemConfigBuilder;
 import org.junit.Assert;
 import org.junit.Test;
 
+import java.net.MalformedURLException;
+import java.net.URL;
+
 /**
  * Tests VFS-427 NPE on HttpFileObject.getContent().getContentInfo()
  *
@@ -37,13 +42,38 @@ public class GetContentInfoFunctionalTest {
      * @throws FileSystemException thrown when the getContentInfo API fails.
      */
     @Test
-    public void testGetContentInfo() throws FileSystemException {
+    public void testGetContentInfo() throws FileSystemException, MalformedURLException {
         final FileSystemManager fsManager = VFS.getManager();
-        try (final FileObject fo = fsManager.resolveFile("http://www.apache.org/licenses/LICENSE-2.0.txt");
+        final String uri = "http://www.apache.org/licenses/LICENSE-2.0.txt";
+        try (final FileObject fo = fsManager.resolveFile(uri, getOptionsWithProxy());
                 final FileContent content = fo.getContent();) {
             Assert.assertNotNull(content);
             // Used to NPE before fix:
             content.getContentInfo();
         }
     }
+
+    FileSystemOptions getOptionsWithProxy() throws MalformedURLException {
+        // get proxy host and port from env var "https_proxy"
+        String proxyHost = null;
+        int proxyPort = -1;
+        final String proxyUrl = System.getenv("https_proxy");
+        if (proxyUrl != null) {
+            final URL url = new URL(proxyUrl);
+            proxyHost = url.getHost();
+            proxyPort = url.getPort();
+        }
+
+        // return null if proxy host or port invalid
+        if (proxyHost == null || proxyPort == -1) {
+            return null;
+        }
+
+        // return options with proxy
+        final HttpFileSystemConfigBuilder builder = HttpFileSystemConfigBuilder.getInstance();
+        final FileSystemOptions opts = new FileSystemOptions();
+        builder.setProxyHost(opts, proxyHost);
+        builder.setProxyPort(opts, proxyPort);
+        return opts;
+    }
 }
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
index 693f2da..03d2c03 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
@@ -20,12 +20,17 @@ import org.apache.commons.vfs2.FileContent;
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileSystemException;
 import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.FileSystemOptions;
 import org.apache.commons.vfs2.VFS;
+import org.apache.commons.vfs2.provider.http4.Http4FileSystemConfigBuilder;
 import org.junit.Assert;
 import org.junit.Test;
 
 import junit.framework.TestCase;
 
+import java.net.MalformedURLException;
+import java.net.URL;
+
 /**
  * Tests VFS-427 NPE on Http4FileObject.getContent().getContentInfo().
  */
@@ -37,12 +42,37 @@ public class Http4GetContentInfoTest extends TestCase {
      * @throws FileSystemException thrown when the getContentInfo API fails.
      */
     @Test
-    public void testGetContentInfo() throws FileSystemException {
+    public void testGetContentInfo() throws FileSystemException, MalformedURLException {
         final FileSystemManager fsManager = VFS.getManager();
-        final FileObject fo = fsManager.resolveFile("http4://www.apache.org/licenses/LICENSE-2.0.txt");
+        final String uri = "http4://www.apache.org/licenses/LICENSE-2.0.txt";
+        final FileObject fo = fsManager.resolveFile(uri, getOptionsWithProxy());
         final FileContent content = fo.getContent();
         Assert.assertNotNull(content);
         // Used to NPE before fix:
         content.getContentInfo();
     }
+
+    FileSystemOptions getOptionsWithProxy() throws MalformedURLException {
+        // get proxy host and port from env var "https_proxy"
+        String proxyHost = null;
+        int proxyPort = -1;
+        final String proxyUrl = System.getenv("https_proxy");
+        if (proxyUrl != null) {
+            final URL url = new URL(proxyUrl);
+            proxyHost = url.getHost();
+            proxyPort = url.getPort();
+        }
+
+        // return null if proxy host or port invalid
+        if (proxyHost == null || proxyPort == -1) {
+            return null;
+        }
+
+        // return options with proxy
+        final Http4FileSystemConfigBuilder builder = Http4FileSystemConfigBuilder.getInstance();
+        final FileSystemOptions opts = new FileSystemOptions();
+        builder.setProxyHost(opts, proxyHost);
+        builder.setProxyPort(opts, proxyPort);
+        return opts;
+    }
 }
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4s/test/Http4sGetContentInfoTest.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4s/test/Http4sGetContentInfoTest.java
index 50295f1..f6a07eb 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4s/test/Http4sGetContentInfoTest.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4s/test/Http4sGetContentInfoTest.java
@@ -44,31 +44,36 @@ public class Http4sGetContentInfoTest extends TestCase {
      */
     @Test
     public void testGetContentInfo() throws FileSystemException, MalformedURLException {
-        String httpsProxyHost = null;
-        int httpsProxyPort = -1;
-        final String httpsProxy = System.getenv("https_proxy");
-        if (httpsProxy != null) {
-            final URL url = new URL(httpsProxy);
-            httpsProxyHost = url.getHost();
-            httpsProxyPort = url.getPort();
-        }
-        final FileSystemOptions opts;
-        if (httpsProxyHost != null) {
-            opts = new FileSystemOptions();
-            final Http4FileSystemConfigBuilder builder = Http4FileSystemConfigBuilder.getInstance();
-            builder.setProxyHost(opts, httpsProxyHost);
-            if (httpsProxyPort >= 0) {
-                builder.setProxyPort(opts, httpsProxyPort);
-            }
-        } else {
-            opts = null;
-        }
-
         final FileSystemManager fsManager = VFS.getManager();
-        final FileObject fo = fsManager.resolveFile("http4://www.apache.org/licenses/LICENSE-2.0.txt",
opts);
+        final String uri = "http4://www.apache.org/licenses/LICENSE-2.0.txt";
+        final FileObject fo = fsManager.resolveFile(uri, getOptionsWithProxy());
         final FileContent content = fo.getContent();
         Assert.assertNotNull(content);
         // Used to NPE before fix:
         content.getContentInfo();
     }
+
+    FileSystemOptions getOptionsWithProxy() throws MalformedURLException {
+        // get proxy host and port from env var "https_proxy"
+        String proxyHost = null;
+        int proxyPort = -1;
+        final String proxyUrl = System.getenv("https_proxy");
+        if (proxyUrl != null) {
+            final URL url = new URL(proxyUrl);
+            proxyHost = url.getHost();
+            proxyPort = url.getPort();
+        }
+
+        // return null if proxy host or port invalid
+        if (proxyHost == null || proxyPort == -1) {
+            return null;
+        }
+
+        // return options with proxy
+        final Http4FileSystemConfigBuilder builder = Http4FileSystemConfigBuilder.getInstance();
+        final FileSystemOptions opts = new FileSystemOptions();
+        builder.setProxyHost(opts, proxyHost);
+        builder.setProxyPort(opts, proxyPort);
+        return opts;
+    }
 }
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5GetContentInfoTest.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5GetContentInfoTest.java
index 905c301..301c3a9 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5GetContentInfoTest.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5GetContentInfoTest.java
@@ -20,12 +20,17 @@ import org.apache.commons.vfs2.FileContent;
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileSystemException;
 import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.FileSystemOptions;
 import org.apache.commons.vfs2.VFS;
+import org.apache.commons.vfs2.provider.http5.Http5FileSystemConfigBuilder;
 import org.junit.Assert;
 import org.junit.Test;
 
 import junit.framework.TestCase;
 
+import java.net.MalformedURLException;
+import java.net.URL;
+
 /**
  * Tests VFS-427 NPE on Http5FileObject.getContent().getContentInfo().
  */
@@ -37,12 +42,37 @@ public class Http5GetContentInfoTest extends TestCase {
      * @throws FileSystemException thrown when the getContentInfo API fails.
      */
     @Test
-    public void testGetContentInfo() throws FileSystemException {
+    public void testGetContentInfo() throws FileSystemException, MalformedURLException {
         final FileSystemManager fsManager = VFS.getManager();
-        final FileObject fo = fsManager.resolveFile("http5://www.apache.org/licenses/LICENSE-2.0.txt");
+        final String uri = "http5://www.apache.org/licenses/LICENSE-2.0.txt";
+        final FileObject fo = fsManager.resolveFile(uri, getOptionsWithProxy());
         final FileContent content = fo.getContent();
         Assert.assertNotNull(content);
         // Used to NPE before fix:
         content.getContentInfo();
     }
+
+    FileSystemOptions getOptionsWithProxy() throws MalformedURLException {
+        // get proxy host and port from env var "https_proxy"
+        String proxyHost = null;
+        int proxyPort = -1;
+        final String proxyUrl = System.getenv("https_proxy");
+        if (proxyUrl != null) {
+            final URL url = new URL(proxyUrl);
+            proxyHost = url.getHost();
+            proxyPort = url.getPort();
+        }
+
+        // return null if proxy host or port invalid
+        if (proxyHost == null || proxyPort == -1) {
+            return null;
+        }
+
+        // return options with proxy
+        final Http5FileSystemConfigBuilder builder = Http5FileSystemConfigBuilder.getInstance();
+        final FileSystemOptions opts = new FileSystemOptions();
+        builder.setProxyHost(opts, proxyHost);
+        builder.setProxyPort(opts, proxyPort);
+        return opts;
+    }
 }
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5s/test/Http5sGetContentInfoTest.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5s/test/Http5sGetContentInfoTest.java
index 19830ed..3b7e465 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5s/test/Http5sGetContentInfoTest.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5s/test/Http5sGetContentInfoTest.java
@@ -44,31 +44,36 @@ public class Http5sGetContentInfoTest extends TestCase {
      */
     @Test
     public void testGetContentInfo() throws FileSystemException, MalformedURLException {
-        String httpsProxyHost = null;
-        int httpsProxyPort = -1;
-        final String httpsProxy = System.getenv("https_proxy");
-        if (httpsProxy != null) {
-            final URL url = new URL(httpsProxy);
-            httpsProxyHost = url.getHost();
-            httpsProxyPort = url.getPort();
-        }
-        final FileSystemOptions opts;
-        if (httpsProxyHost != null) {
-            opts = new FileSystemOptions();
-            final Http5FileSystemConfigBuilder builder = Http5FileSystemConfigBuilder.getInstance();
-            builder.setProxyHost(opts, httpsProxyHost);
-            if (httpsProxyPort >= 0) {
-                builder.setProxyPort(opts, httpsProxyPort);
-            }
-        } else {
-            opts = null;
-        }
-
         final FileSystemManager fsManager = VFS.getManager();
-        final FileObject fo = fsManager.resolveFile("http5://www.apache.org/licenses/LICENSE-2.0.txt",
opts);
+        final String uri = "http5://www.apache.org/licenses/LICENSE-2.0.txt";
+        final FileObject fo = fsManager.resolveFile(uri, getOptionsWithProxy());
         final FileContent content = fo.getContent();
         Assert.assertNotNull(content);
         // Used to NPE before fix:
         content.getContentInfo();
     }
+
+    FileSystemOptions getOptionsWithProxy() throws MalformedURLException {
+        // get proxy host and port from env var "https_proxy"
+        String proxyHost = null;
+        int proxyPort = -1;
+        final String proxyUrl = System.getenv("https_proxy");
+        if (proxyUrl != null) {
+            final URL url = new URL(proxyUrl);
+            proxyHost = url.getHost();
+            proxyPort = url.getPort();
+        }
+
+        // return null if proxy host or port invalid
+        if (proxyHost == null || proxyPort == -1) {
+            return null;
+        }
+
+        // return options with proxy
+        final Http5FileSystemConfigBuilder builder = Http5FileSystemConfigBuilder.getInstance();
+        final FileSystemOptions opts = new FileSystemOptions();
+        builder.setProxyHost(opts, proxyHost);
+        builder.setProxyPort(opts, proxyPort);
+        return opts;
+    }
 }
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/https/test/GetContentInfoFunctionalTest.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/https/test/GetContentInfoFunctionalTest.java
index 9dd10c7..ccb6f90 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/https/test/GetContentInfoFunctionalTest.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/https/test/GetContentInfoFunctionalTest.java
@@ -45,32 +45,37 @@ public class GetContentInfoFunctionalTest {
      */
     @Test
     public void testGetContentInfo() throws FileSystemException, MalformedURLException {
-        String httpsProxyHost = null;
-        int httpsProxyPort = -1;
-        final String httpsProxy = System.getenv("https_proxy");
-        if (httpsProxy != null) {
-            final URL url = new URL(httpsProxy);
-            httpsProxyHost = url.getHost();
-            httpsProxyPort = url.getPort();
-        }
-        final FileSystemOptions opts;
-        if (httpsProxyHost != null) {
-            opts = new FileSystemOptions();
-            final HttpFileSystemConfigBuilder builder = HttpFileSystemConfigBuilder.getInstance();
-            builder.setProxyHost(opts, httpsProxyHost);
-            if (httpsProxyPort >= 0) {
-                builder.setProxyPort(opts, httpsProxyPort);
-            }
-        } else {
-            opts = null;
-        }
-
         final FileSystemManager fsManager = VFS.getManager();
-        try (final FileObject fo = fsManager.resolveFile("http://www.apache.org/licenses/LICENSE-2.0.txt",
opts);
+        final String uri = "http://www.apache.org/licenses/LICENSE-2.0.txt";
+        try (final FileObject fo = fsManager.resolveFile(uri, getOptionsWithProxy());
              final FileContent content = fo.getContent();) {
             Assert.assertNotNull(content);
             // Used to NPE before fix:
             content.getContentInfo();
         }
     }
+
+    FileSystemOptions getOptionsWithProxy() throws MalformedURLException {
+        // get proxy host and port from env var "https_proxy"
+        String proxyHost = null;
+        int proxyPort = -1;
+        final String proxyUrl = System.getenv("https_proxy");
+        if (proxyUrl != null) {
+            final URL url = new URL(proxyUrl);
+            proxyHost = url.getHost();
+            proxyPort = url.getPort();
+        }
+
+        // return null if proxy host or port invalid
+        if (proxyHost == null || proxyPort == -1) {
+            return null;
+        }
+
+        // return options with proxy
+        final HttpFileSystemConfigBuilder builder = HttpFileSystemConfigBuilder.getInstance();
+        final FileSystemOptions opts = new FileSystemOptions();
+        builder.setProxyHost(opts, proxyHost);
+        builder.setProxyPort(opts, proxyPort);
+        return opts;
+    }
 }


Mime
View raw message