Author: bfoster
Date: Sat Jun 4 02:31:08 2011
New Revision: 1131307
URL: http://svn.apache.org/viewvc?rev=1131307&view=rev
Log:
- formatting
- unit-tests improved
- bug fixes exposed by unit-tests
--------------------
OODT-194
Added:
oodt/branches/protocol/protocol-ftp/src/test/
oodt/branches/protocol/protocol-ftp/src/test/org/
oodt/branches/protocol/protocol-ftp/src/test/org/apache/
oodt/branches/protocol/protocol-ftp/src/test/org/apache/oodt/
oodt/branches/protocol/protocol-ftp/src/test/org/apache/oodt/cas/
oodt/branches/protocol/protocol-ftp/src/test/org/apache/oodt/cas/protocol/
oodt/branches/protocol/protocol-ftp/src/test/org/apache/oodt/cas/protocol/ftp/
oodt/branches/protocol/protocol-ftp/src/test/org/apache/oodt/cas/protocol/ftp/TestCogJGlobusFtpProtocol.java
(with props)
oodt/branches/protocol/protocol-ftp/src/testdata/
oodt/branches/protocol/protocol-ftp/src/testdata/users.properties (with
props)
Modified:
oodt/branches/protocol/protocol-ftp/pom.xml
oodt/branches/protocol/protocol-ftp/src/main/java/org/apache/oodt/cas/protocol/ftp/CogJGlobusFtpProtocol.java
oodt/branches/protocol/protocol-ftp/src/main/java/org/apache/oodt/cas/protocol/ftp/CommonsNetFtpProtocol.java
Modified: oodt/branches/protocol/protocol-ftp/pom.xml
URL:
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-ftp/pom.xml?rev=1131307&r1=1131306&r2=1131307&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-ftp/pom.xml (original)
+++ oodt/branches/protocol/protocol-ftp/pom.xml Sat Jun 4 02:31:08 2011
@@ -89,6 +89,18 @@
<version>1.4.0</version>
</dependency>
<dependency>
+ <groupId>org.apache.ftpserver</groupId>
+ <artifactId>ftpserver-core</artifactId>
+ <version>1.0.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
Modified:
oodt/branches/protocol/protocol-ftp/src/main/java/org/apache/oodt/cas/protocol/ftp/CogJGlobusFtpProtocol.java
URL:
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-ftp/src/main/java/org/apache/oodt/cas/protocol/ftp/CogJGlobusFtpProtocol.java?rev=1131307&r1=1131306&r2=1131307&view=diff
==============================================================================
---
oodt/branches/protocol/protocol-ftp/src/main/java/org/apache/oodt/cas/protocol/ftp/CogJGlobusFtpProtocol.java
(original)
+++
oodt/branches/protocol/protocol-ftp/src/main/java/org/apache/oodt/cas/protocol/ftp/CogJGlobusFtpProtocol.java
Sat Jun 4 02:31:08 2011
@@ -37,8 +37,17 @@ import org.globus.ftp.FileInfo;
public class CogJGlobusFtpProtocol implements Protocol {
private FTPClient ftp;
-
private boolean isConnected;
+ private int port;
+ private String homeDir;
+
+ public CogJGlobusFtpProtocol() {
+ this(21);
+ }
+
+ public CogJGlobusFtpProtocol(int port) {
+ this.port = port;
+ }
public void cd(ProtocolFile file) throws ProtocolException {
try {
@@ -48,22 +57,31 @@ public class CogJGlobusFtpProtocol imple
+ e.getMessage());
}
}
+
+ public void cdRoot() throws ProtocolException {
+ cd(new ProtocolFile(ProtocolFile.SEPARATOR, true));
+ }
+
+ public void cdHome() throws ProtocolException {
+ cd(new ProtocolFile(homeDir, true));
+ }
public void connect(String host, Authentication auth) throws
ProtocolException {
try {
- ftp = new FTPClient(host, 21);
+ ftp = new FTPClient(host, port);
} catch (Exception e) {
throw new ProtocolException("Failed to connect to: " + host + " : "
- + e.getMessage());
+ + e.getMessage(), e);
}
isConnected = true;
try {
ftp.authorize(auth.getUser(), auth.getPass());
ftp.setActive(ftp.setLocalPassive());
+ homeDir = ftp.getCurrentDir();
} catch (Exception e) {
throw new ProtocolException("Failed to login to: " + host + " : "
- + e.getMessage());
+ + e.getMessage(), e);
}
}
@@ -101,10 +119,8 @@ public class CogJGlobusFtpProtocol imple
ftp.setActive(ftp.setLocalPassive());
Vector<FileInfo> fileList = (Vector<FileInfo>) ftp.list("*", null);
Vector<ProtocolFile> returnList = new Vector<ProtocolFile>();
- String path = this.pwd().getPath();
for (FileInfo file : fileList) {
- returnList.add(new ProtocolFile(path + File.separator
- + file.getName(), file.isDirectory()));
+ returnList.add(new ProtocolFile(this.pwd(), file.getName(),
file.isDirectory()));
}
return returnList;
} catch (Exception e) {
Modified:
oodt/branches/protocol/protocol-ftp/src/main/java/org/apache/oodt/cas/protocol/ftp/CommonsNetFtpProtocol.java
URL:
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-ftp/src/main/java/org/apache/oodt/cas/protocol/ftp/CommonsNetFtpProtocol.java?rev=1131307&r1=1131306&r2=1131307&view=diff
==============================================================================
---
oodt/branches/protocol/protocol-ftp/src/main/java/org/apache/oodt/cas/protocol/ftp/CommonsNetFtpProtocol.java
(original)
+++
oodt/branches/protocol/protocol-ftp/src/main/java/org/apache/oodt/cas/protocol/ftp/CommonsNetFtpProtocol.java
Sat Jun 4 02:31:08 2011
@@ -43,7 +43,8 @@ import org.apache.oodt.cas.protocol.exce
public class CommonsNetFtpProtocol implements Protocol {
private FTPClient ftp;
-
+ private String homeDir;
+
/**
* Creates a new FtpClient
*/
@@ -78,6 +79,7 @@ public class CommonsNetFtpProtocol imple
// set file type to binary
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
+ homeDir = ftp.printWorkingDirectory();
} catch (Exception e) {
// login failed
throw new ProtocolException(
@@ -176,6 +178,14 @@ public class CommonsNetFtpProtocol imple
+ e.getMessage());
}
}
+
+ public void cdRoot() throws ProtocolException {
+ cd(new ProtocolFile(ProtocolFile.SEPARATOR, true));
+ }
+
+ public void cdHome() throws ProtocolException {
+ cd(new ProtocolFile(homeDir, true));
+ }
/**
* {@inheritDoc}
Added:
oodt/branches/protocol/protocol-ftp/src/test/org/apache/oodt/cas/protocol/ftp/TestCogJGlobusFtpProtocol.java
URL:
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-ftp/src/test/org/apache/oodt/cas/protocol/ftp/TestCogJGlobusFtpProtocol.java?rev=1131307&view=auto
==============================================================================
---
oodt/branches/protocol/protocol-ftp/src/test/org/apache/oodt/cas/protocol/ftp/TestCogJGlobusFtpProtocol.java
(added)
+++
oodt/branches/protocol/protocol-ftp/src/test/org/apache/oodt/cas/protocol/ftp/TestCogJGlobusFtpProtocol.java
Sat Jun 4 02:31:08 2011
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+package org.apache.oodt.cas.protocol.ftp;
+
+//JUnit imports
+import java.io.File;
+import java.util.List;
+
+//APACHE imports
+import org.apache.ftpserver.ConnectionConfigFactory;
+import org.apache.ftpserver.DataConnectionConfigurationFactory;
+import org.apache.ftpserver.FtpServer;
+import org.apache.ftpserver.FtpServerFactory;
+import org.apache.ftpserver.listener.ListenerFactory;
+import org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor;
+import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory;
+
+//OODT imports
+import org.apache.oodt.cas.protocol.ProtocolFile;
+import org.apache.oodt.cas.protocol.auth.BasicAuthentication;
+import org.apache.oodt.cas.protocol.exceptions.ProtocolException;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link CogJGlobusFtpProtocol}.
+ *
+ * @author bfoster
+ */
+public class TestCogJGlobusFtpProtocol extends TestCase {
+
+ private static final int PORT = 9000;
+ private FtpServer server;
+ private static final File USERS_FILE = new
File("src/testdata/users.properties");
+
+ @Override
+ public void setUp() throws Exception {
+ assertTrue(USERS_FILE.getAbsolutePath() + " must exist",
+ USERS_FILE.exists());
+
+ FtpServerFactory serverFactory = new FtpServerFactory();
+
+ serverFactory.setConnectionConfig(new ConnectionConfigFactory()
+ .createConnectionConfig());
+
+ ListenerFactory listenerFactory = new ListenerFactory();
+
+ listenerFactory.setPort(PORT);
+
+ listenerFactory
+ .setDataConnectionConfiguration(new
DataConnectionConfigurationFactory()
+
.createDataConnectionConfiguration());
+
+ serverFactory.addListener("default",
listenerFactory.createListener());
+
+ PropertiesUserManagerFactory umFactory = new
PropertiesUserManagerFactory();
+ umFactory.setPasswordEncryptor(new
ClearTextPasswordEncryptor());
+ umFactory.setFile(USERS_FILE);
+
+ serverFactory.setUserManager(umFactory.createUserManager());
+
+ server = serverFactory.createServer();
+ server.start();
+ }
+
+ @Override
+ public void tearDown() {
+ server.stop();
+ }
+
+ public void testLSandCDandPWD() throws ProtocolException {
+ CogJGlobusFtpProtocol ftpProtocol = new
CogJGlobusFtpProtocol(PORT);
+ ftpProtocol.connect("localhost", new
BasicAuthentication("anonymous", "password"));
+ ftpProtocol.cd(new ProtocolFile("testdata", true));
+ List<ProtocolFile> lsResults = ftpProtocol.ls();
+ assertTrue(lsResults.contains(new
ProtocolFile(ftpProtocol.pwd(), "users.properties", false)));
+ }
+
+}
Propchange:
oodt/branches/protocol/protocol-ftp/src/test/org/apache/oodt/cas/protocol/ftp/TestCogJGlobusFtpProtocol.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: oodt/branches/protocol/protocol-ftp/src/testdata/users.properties
URL:
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-ftp/src/testdata/users.properties?rev=1131307&view=auto
==============================================================================
--- oodt/branches/protocol/protocol-ftp/src/testdata/users.properties (added)
+++ oodt/branches/protocol/protocol-ftp/src/testdata/users.properties Sat Jun
4 02:31:08 2011
@@ -0,0 +1,26 @@
+# 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.
+
+ftpserver.user.anonymous.userpassword=
+ftpserver.user.anonymous.maxloginperip=2
+ftpserver.user.anonymous.uploadrate=4800
+ftpserver.user.anonymous.writepermission=false
+ftpserver.user.anonymous.maxloginnumber=20
+ftpserver.user.anonymous.enableflag=true
+ftpserver.user.anonymous.homedirectory=src
+ftpserver.user.anonymous.idletime=300
+ftpserver.user.anonymous.downloadrate=4800
Propchange: oodt/branches/protocol/protocol-ftp/src/testdata/users.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain