commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1197333 - in /commons/proper/vfs/trunk/core: ./ src/test/java/org/apache/commons/vfs2/provider/ftp/test/ src/test/resources/ src/test/resources/org.apache.ftpserver/
Date Thu, 03 Nov 2011 22:42:16 GMT
Author: ggregory
Date: Thu Nov  3 22:42:15 2011
New Revision: 1197333

URL: http://svn.apache.org/viewvc?rev=1197333&view=rev
Log:
Use an embedded Apache FTP Server (MINA) to test the FTP provider. TODO: Refactor this for
SFTP tests.

Added:
    commons/proper/vfs/trunk/core/src/test/resources/log4j.properties
    commons/proper/vfs/trunk/core/src/test/resources/org.apache.ftpserver/
    commons/proper/vfs/trunk/core/src/test/resources/org.apache.ftpserver/users.properties
Modified:
    commons/proper/vfs/trunk/core/pom.xml
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java

Modified: commons/proper/vfs/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/pom.xml?rev=1197333&r1=1197332&r2=1197333&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/pom.xml (original)
+++ commons/proper/vfs/trunk/core/pom.xml Thu Nov  3 22:42:15 2011
@@ -16,8 +16,11 @@
    See the License for the specific language governing permissions and
    limitations under the License.
   -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ 
+<project
+  xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
   <modelVersion>4.0.0</modelVersion>
 
@@ -78,6 +81,22 @@
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
+    <!-- ftpserver-core -->
+    <dependency>
+      <groupId>org.apache.ftpserver</groupId>
+      <artifactId>ftpserver-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <properties>
@@ -97,7 +116,7 @@
         <targetPath>META-INF</targetPath>
         <includes>
           <include>NOTICE.txt</include>
-           <include>LICENSE.txt</include>
+          <include>LICENSE.txt</include>
         </includes>
       </resource>
     </resources>
@@ -136,7 +155,9 @@
             <phase>process-test-classes</phase>
             <configuration>
               <target>
-                <move todir="${project.build.testOutputDirectory}/test-data/code" failonerror="false">
+                <move
+                  todir="${project.build.testOutputDirectory}/test-data/code"
+                  failonerror="false">
                   <fileset dir="${project.build.testOutputDirectory}/code" />
                 </move>
 

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=1197333&r1=1197332&r2=1197333&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
Thu Nov  3 22:42:15 2011
@@ -16,6 +16,9 @@
  */
 package org.apache.commons.vfs2.provider.ftp.test;
 
+import java.net.MalformedURLException;
+import java.net.URL;
+
 import junit.framework.Test;
 
 import org.apache.commons.vfs2.FileObject;
@@ -27,51 +30,126 @@ 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.ftpserver.FtpServer;
+import org.apache.ftpserver.FtpServerFactory;
+import org.apache.ftpserver.ftplet.FtpException;
+import org.apache.ftpserver.ftplet.UserManager;
+import org.apache.ftpserver.listener.ListenerFactory;
+import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory;
+import org.apache.ftpserver.usermanager.impl.BaseUser;
+import org.junit.Assert;
 
 /**
  * Tests for FTP file systems.
- *
+ * 
  * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  */
-public class FtpProviderTestCase
-    extends AbstractProviderTestConfig
-    implements ProviderTestConfig
+public class FtpProviderTestCase extends AbstractProviderTestConfig implements ProviderTestConfig
 {
+    private static final String USER_PROP_RES = "org.apache.ftpserver/users.properties";
+
+    private static final int DEFAULT_PORT = 2121;
+
+    /**
+     * Use %40 for @ in the FTP URL password
+     */
+    private static final String DEFAULT_URI = "ftp://test:test@localhost:" + DEFAULT_PORT;
+
     private static final String TEST_URI = "test.ftp.uri";
-    
+
+    private static FtpServer Server;
+
     /**
-     * Creates the test suite for the ftp file system.
+     * Creates and starts an embedded Apache FTP Server (MINA).
+     * 
+     * @throws FtpException
+     * @throws MalformedURLException
      */
-    public static Test suite() throws Exception
+    private static void setUpClass() throws FtpException, MalformedURLException
     {
-        if (System.getProperty(TEST_URI) != null)
+        if (Server != null)
         {
-            return new ProviderTestSuite(new FtpProviderTestCase());
+            return;
         }
-        else
+        final FtpServerFactory serverFactory = new FtpServerFactory();
+        final PropertiesUserManagerFactory propertiesUserManagerFactory = new PropertiesUserManagerFactory();
+        final URL userResource = ClassLoader.getSystemClassLoader().getResource(USER_PROP_RES);
+        Assert.assertNotNull(USER_PROP_RES, userResource);
+        propertiesUserManagerFactory.setUrl(userResource);
+        final UserManager userManager = propertiesUserManagerFactory.createUserManager();
+        final BaseUser user = (BaseUser) userManager.getUserByName("test");
+        // Pickup the home dir value at runtime even though we have it set in the user prop
file
+        // The user prop file requires the "homedirectory" to be set
+        user.setHomeDirectory(getTestDirectory());
+        serverFactory.setUserManager(userManager);
+        ListenerFactory factory = new ListenerFactory();
+        // set the port of the listener
+        factory.setPort(DEFAULT_PORT);
+
+        // replace the default listener
+        serverFactory.addListener("default", factory.createListener());
+
+        // start the server
+        Server = serverFactory.createServer();
+        Server.start();
+    }
+
+    /**
+     * Creates the test suite for the ftp file system.
+     */
+    public static Test suite() throws Exception
+    {
+        return new ProviderTestSuite(new FtpProviderTestCase())
         {
-            return notConfigured(FtpProviderTestCase.class);
-        }
+            @Override
+            protected void setUp() throws Exception
+            {
+                setUpClass();
+                super.setUp();
+            }
+
+            @Override
+            protected void tearDown() throws Exception
+            {
+                tearDownClass();
+                super.tearDown();
+            }
+        };
     }
 
     /**
-     * Prepares the file system manager.
+     * Stops the embedded Apache FTP Server (MINA).
      */
-    @Override
-    public void prepare(final DefaultFileSystemManager manager) throws Exception
+    public static void tearDownClass()
     {
-        manager.addProvider("ftp", new FtpFileProvider());
+        if (Server != null)
+        {
+            Server.stop();
+        }
     }
 
     /**
-     * Returns the base folder for tests.
+     * 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
     {
-        final String uri = System.getProperty(TEST_URI);
+        String uri = System.getProperty(TEST_URI);
+        if (uri == null)
+        {
+            uri = DEFAULT_URI;
+        }
         FileSystemOptions opts = new FileSystemOptions();
         FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);
         return manager.resolveFile(uri, opts);
     }
+
+    /**
+     * Prepares the file system manager.
+     */
+    @Override
+    public void prepare(final DefaultFileSystemManager manager) throws Exception
+    {
+        manager.addProvider("ftp", new FtpFileProvider());
+    }
 }

Added: commons/proper/vfs/trunk/core/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/resources/log4j.properties?rev=1197333&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/resources/log4j.properties (added)
+++ commons/proper/vfs/trunk/core/src/test/resources/log4j.properties Thu Nov  3 22:42:15
2011
@@ -0,0 +1,36 @@
+# 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.
+
+# @version $Id: log4j.properties 27216 2011-09-14 02:34:00Z ggregory $
+
+log4j.rootLogger=ERROR, Console
+#log4j.rootLogger=WARN, Console
+#log4j.rootLogger=INFO, Console
+#log4j.rootLogger=DEBUG, Console
+
+###############################################################################
+# The console log
+#
+# Documentation: http://logging.apache.org/log4j/docs/api/org/apache/log4j/ConsoleAppender.html
+#
+# To enable this appender, add its name to the log4j.rootLogger list
+
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.ImmediateFlush=true
+log4j.appender.Console.Target=System.out
+log4j.appender.Console.layout=org.apache.log4j.PatternLayout
+log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} [%t] %-5p: %m%n

Added: commons/proper/vfs/trunk/core/src/test/resources/org.apache.ftpserver/users.properties
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/resources/org.apache.ftpserver/users.properties?rev=1197333&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/resources/org.apache.ftpserver/users.properties
(added)
+++ commons/proper/vfs/trunk/core/src/test/resources/org.apache.ftpserver/users.properties
Thu Nov  3 22:42:15 2011
@@ -0,0 +1,43 @@
+# 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.
+
+# Password is "admin"
+ftpserver.user.admin.userpassword=21232F297A57A5A743894A0E4A801FC3
+ftpserver.user.admin.homedirectory=target/test-classes/test-data
+ftpserver.user.admin.enableflag=true
+ftpserver.user.admin.writepermission=true
+ftpserver.user.admin.maxloginnumber=0
+ftpserver.user.admin.maxloginperip=0
+ftpserver.user.admin.idletime=0
+ftpserver.user.admin.uploadrate=0
+ftpserver.user.admin.downloadrate=0
+
+ftpserver.user.anonymous.userpassword=
+ftpserver.user.anonymous.homedirectory=target/test-classes/test-data
+ftpserver.user.anonymous.enableflag=true
+ftpserver.user.anonymous.writepermission=false
+ftpserver.user.anonymous.maxloginnumber=20
+ftpserver.user.anonymous.maxloginperip=2
+ftpserver.user.anonymous.idletime=300
+ftpserver.user.anonymous.uploadrate=4800
+ftpserver.user.anonymous.downloadrate=4800
+
+# password is "test"
+ftpserver.user.test.userpassword=098f6bcd4621d373cade4e832627b4f6
+ftpserver.user.test.homedirectory=target/test-classes/test-data
+ftpserver.user.test.enableflag=true
+ftpserver.user.test.writepermission=true



Mime
View raw message