commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1200021 - in /commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider: ftp/test/FtpProviderTestCase.java sftp/test/SftpProviderTestCase.java
Date Wed, 09 Nov 2011 22:57:53 GMT
Author: ggregory
Date: Wed Nov  9 22:57:53 2011
New Revision: 1200021

URL: http://svn.apache.org/viewvc?rev=1200021&view=rev
Log:
Testing FTP: Find a free socket port at runtime instead of hard-coding one.

Modified:
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java?rev=1200021&r1=1200020&r2=1200021&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java
(original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java
Wed Nov  9 22:57:53 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.vfs2.provider.ftp.test;
 
+import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 
@@ -30,6 +31,7 @@ import org.apache.commons.vfs2.provider.
 import org.apache.commons.vfs2.test.AbstractProviderTestConfig;
 import org.apache.commons.vfs2.test.ProviderTestConfig;
 import org.apache.commons.vfs2.test.ProviderTestSuite;
+import org.apache.commons.vfs2.util.FreeSocketPortUtil;
 import org.apache.ftpserver.FtpServer;
 import org.apache.ftpserver.FtpServerFactory;
 import org.apache.ftpserver.ftplet.FtpException;
@@ -46,12 +48,12 @@ import org.junit.Assert;
  */
 public class FtpProviderTestCase extends AbstractProviderTestConfig implements ProviderTestConfig
 {
-    private static final int DEFAULT_PORT = 2121;
+    private static int SocketPort;
 
     /**
      * Use %40 for @ in the FTP URL password
      */
-    private static final String DEFAULT_URI = "ftp://test:test@localhost:" + DEFAULT_PORT;
+    private static String ConnectionUri;
 
     private static FtpServer Server;
 
@@ -89,7 +91,7 @@ public class FtpProviderTestCase extends
         serverFactory.setUserManager(userManager);
         ListenerFactory factory = new ListenerFactory();
         // set the port of the listener
-        factory.setPort(DEFAULT_PORT);
+        factory.setPort(SocketPort);
 
         // replace the default listener
         serverFactory.addListener("default", factory.createListener());
@@ -136,6 +138,13 @@ public class FtpProviderTestCase extends
         }
     }
 
+    public FtpProviderTestCase() throws IOException
+    {
+        SocketPort = FreeSocketPortUtil.findFreeLocalPort();
+        // Use %40 for @ in the a URL a @
+        ConnectionUri = "ftp://test:test@localhost:" + SocketPort;
+    }
+
     /**
      * Returns the base folder for tests. You can override the DEFAULT_URI by using the system
property name defined by TEST_URI.
      */
@@ -145,7 +154,7 @@ public class FtpProviderTestCase extends
         String uri = getSystemTestUriOverride();
         if (uri == null)
         {
-            uri = DEFAULT_URI;
+            uri = ConnectionUri;
         }
         FileSystemOptions opts = new FileSystemOptions();
         FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java?rev=1200021&r1=1200020&r2=1200021&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java
(original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/sftp/test/SftpProviderTestCase.java
Wed Nov  9 22:57:53 2011
@@ -276,7 +276,7 @@ public class SftpProviderTestCase extend
     public SftpProviderTestCase() throws IOException
     {
         SocketPort = FreeSocketPortUtil.findFreeLocalPort();
-        // Use %40 for @ in the FTP URL password if you need a @
+        // Use %40 for @ in the a URL a @
         ConnectionUri = String.format("sftp://%s@localhost:%d", DEFAULT_USER, SocketPort);
     }
 



Mime
View raw message