Author: ggregory
Date: Wed Apr 25 18:26:50 2012
New Revision: 1330468

URL: http://svn.apache.org/viewvc?rev=1330468&view=rev
Log:
Refactor for a new test to check that we can make multiple connections to an 
FTP server via the underlying Commons Net code. This is OK with FTP but not 
with FTPS. The FTPS test is not committed yet.

Added:
    
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/MultipleConnectionTestCase.java
   (with props)
Modified:
    
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.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=1330468&r1=1330467&r2=1330468&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 Apr 25 18:26:50 2012
@@ -59,23 +59,36 @@ public class FtpProviderTestCase extends
 
     private static final String USER_PROPS_RES = 
"org.apache.ftpserver/users.properties";
 
+    static int getSocketPort()
+    {
+        return SocketPort;
+    }
+
     private static String getSystemTestUriOverride()
     {
         return System.getProperty(TEST_URI);
     }
 
+    static void init() throws IOException
+    {
+        SocketPort = FreeSocketPortUtil.findFreeLocalPort();
+        // Use %40 for @ in a URL
+        ConnectionUri = "ftp://test:test@localhost:"; + SocketPort;
+    }
+
     /**
      * Creates and starts an embedded Apache FTP Server (MINA).
      * 
      * @throws FtpException
-     * @throws MalformedURLException
+     * @throws IOException 
      */
-    private static void setUpClass() throws FtpException, MalformedURLException
+    static void setUpClass() throws FtpException, IOException
     {
         if (Server != null)
         {
             return;
         }
+        init();
         final FtpServerFactory serverFactory = new FtpServerFactory();
         final PropertiesUserManagerFactory propertiesUserManagerFactory = new 
PropertiesUserManagerFactory();
         final URL userPropsResource = 
ClassLoader.getSystemClassLoader().getResource(USER_PROPS_RES);
@@ -128,23 +141,18 @@ public class FtpProviderTestCase extends
     /**
      * Stops the embedded Apache FTP Server (MINA).
      */
-    private static void tearDownClass()
+    static void tearDownClass()
     {
         if (Server != null)
         {
             Server.stop();
+            Server = null;
         }
     }
 
-    public FtpProviderTestCase() throws IOException
-    {
-        SocketPort = FreeSocketPortUtil.findFreeLocalPort();
-        // Use %40 for @ in a URL
-        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.
+     * Returns the base folder for tests. You can override the DEFAULT_URI by 
using the system property name defined by
+     * TEST_URI.
      */
     @Override
     public FileObject getBaseTestFolder(final FileSystemManager manager) 
throws Exception

Added: 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/MultipleConnectionTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/MultipleConnectionTestCase.java?rev=1330468&view=auto
==============================================================================
--- 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/MultipleConnectionTestCase.java
 (added)
+++ 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/MultipleConnectionTestCase.java
 Wed Apr 25 18:26:50 2012
@@ -0,0 +1,50 @@
+package org.apache.commons.vfs2.provider.ftp.test;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.SocketException;
+
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.ftpserver.ftplet.FtpException;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class MultipleConnectionTestCase
+{
+
+    @BeforeClass
+    public static void setUpClass() throws FtpException, IOException
+    {
+        FtpProviderTestCase.setUpClass();
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws MalformedURLException, 
FtpException
+    {
+        FtpProviderTestCase.tearDownClass();
+    }
+
+    @Test
+    public void testUnderlyingConnect() throws SocketException, IOException
+    {
+        FTPClient client1 = new FTPClient();
+        FTPClient client2 = new FTPClient();
+        try
+        {
+            final String hostname = "localhost";
+            client1.connect(hostname, FtpProviderTestCase.getSocketPort());
+            client2.connect(hostname, FtpProviderTestCase.getSocketPort());
+        } finally
+        {
+            if (client1 != null)
+            {
+                client1.disconnect();
+            }
+            if (client2 != null)
+            {
+                client2.disconnect();
+            }
+        }
+    }
+}

Propchange: 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/MultipleConnectionTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/MultipleConnectionTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id


Reply via email to