Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CA4407DD0 for ; Thu, 3 Nov 2011 22:42:38 +0000 (UTC) Received: (qmail 83269 invoked by uid 500); 3 Nov 2011 22:42:38 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 83210 invoked by uid 500); 3 Nov 2011 22:42:38 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 83203 invoked by uid 99); 3 Nov 2011 22:42:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Nov 2011 22:42:38 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Nov 2011 22:42:36 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9377423889FD for ; Thu, 3 Nov 2011 22:42:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: ggregory@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111103224216.9377423889FD@eris.apache.org> 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. --> - - + + 4.0.0 @@ -78,6 +81,22 @@ junit test + + + org.apache.ftpserver + ftpserver-core + test + + + org.slf4j + slf4j-api + test + + + org.slf4j + slf4j-log4j12 + test + @@ -97,7 +116,7 @@ META-INF NOTICE.txt - LICENSE.txt + LICENSE.txt @@ -136,7 +155,9 @@ process-test-classes - + 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 Adam Murdoch */ -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