Author: bfoster
Date: Thu Jun  9 21:18:53 2011
New Revision: 1134087

URL: http://svn.apache.org/viewvc?rev=1134087&view=rev
Log:
- updated to add new Protocol method: ls(ProtocolFileFilter)
- updated unit tests and add unit test for HostKeyAuthentication

----------------
OODT-194

Added:
    
oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/auth/
    
oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/auth/TestHostKeyAuthentication.java
   (with props)
Modified:
    
oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java
    
oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocolFactory.java
    
oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java

Modified: 
oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java
URL: 
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java?rev=1134087&r1=1134086&r2=1134087&view=diff
==============================================================================
--- 
oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java
 (original)
+++ 
oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java
 Thu Jun  9 21:18:53 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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.
@@ -20,6 +20,7 @@ package org.apache.oodt.cas.protocol.sft
 import org.apache.oodt.cas.protocol.auth.Authentication;
 import org.apache.oodt.cas.protocol.exceptions.ProtocolException;
 import org.apache.oodt.cas.protocol.sftp.auth.HostKeyAuthentication;
+import org.apache.oodt.cas.protocol.util.ProtocolFileFilter;
 import org.apache.oodt.cas.protocol.Protocol;
 import org.apache.oodt.cas.protocol.ProtocolFile;
 
@@ -157,6 +158,26 @@ public class JschSftpProtocol implements
     }
   }
 
+       public List<ProtocolFile> ls(ProtocolFileFilter filter)
+                       throws ProtocolException {
+    try {
+      Vector<ChannelSftp.LsEntry> sftpFiles = (Vector<ChannelSftp.LsEntry>) 
sftpChannel
+          .ls(sftpChannel.pwd());
+      Vector<ProtocolFile> returnFiles = new Vector<ProtocolFile>();
+      for (ChannelSftp.LsEntry sftpFile : sftpFiles) {
+        String path = this.pwd().getPath();
+        ProtocolFile pFile = new ProtocolFile(path + "/" + 
sftpFile.getFilename(), sftpFile
+            .getAttrs().isDir());
+        if (filter.accept(pFile)) {
+               returnFiles.add(pFile);
+        }
+      }
+      return returnFiles;
+    } catch (Exception e) {
+      throw new ProtocolException("Failed to get file list : " + 
e.getMessage());
+    }
+       }
+       
   public ProtocolFile pwd() throws ProtocolException {
     try {
       return new ProtocolFile(sftpChannel.pwd(), true);

Modified: 
oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocolFactory.java
URL: 
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocolFactory.java?rev=1134087&r1=1134086&r2=1134087&view=diff
==============================================================================
--- 
oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocolFactory.java
 (original)
+++ 
oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocolFactory.java
 Thu Jun  9 21:18:53 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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.
@@ -20,22 +20,29 @@ package org.apache.oodt.cas.protocol.sft
 import org.apache.oodt.cas.protocol.ProtocolFactory;
 
 /**
- * 
  * Creates new {@link JschSftpProtocol}s.
- * 
+ *
  * @author bfoster
  * @author mattmann
  * @version $Revision$
- * 
  */
 public class JschSftpProtocolFactory implements ProtocolFactory {
 
+       private int port = -1;
+       
   public JschSftpProtocol newInstance() {
-    return new JschSftpProtocol();
+       if (port > 0) {
+               return new JschSftpProtocol(port);
+       } else {
+               return new JschSftpProtocol();
+       }
   }
 
   public String getSchema() {
-       return "sftp";
+       return "sftp";
   }
 
+  public void setPort(int port) {
+       this.port = port;
+  }
 }

Modified: 
oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java
URL: 
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java?rev=1134087&r1=1134086&r2=1134087&view=diff
==============================================================================
--- 
oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java
 (original)
+++ 
oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java
 Thu Jun  9 21:18:53 2011
@@ -27,6 +27,7 @@ import java.util.concurrent.Executors;
 import org.apache.oodt.cas.protocol.ProtocolFile;
 import org.apache.oodt.cas.protocol.exceptions.ProtocolException;
 import org.apache.oodt.cas.protocol.sftp.auth.HostKeyAuthentication;
+import org.apache.oodt.cas.protocol.util.ProtocolFileFilter;
 
 //SshTools imports
 import com.sshtools.daemon.SshDaemon;
@@ -86,7 +87,11 @@ public class TestJschSftpProtocol extend
                ProtocolFile testDir = new ProtocolFile(homeDir, "sshTestDir", 
true);
                sftpProtocol.cd(testDir);
                assertEquals(testDir, sftpProtocol.pwd());
-               List<ProtocolFile> lsResults = new 
ArrayList<ProtocolFile>(sftpProtocol.ls());
+               List<ProtocolFile> lsResults = new 
ArrayList<ProtocolFile>(sftpProtocol.ls(new ProtocolFileFilter() {
+                       public boolean accept(ProtocolFile file) {
+                               return file.getName().equals("sshTestFile");
+                       }
+               }));
                assertEquals(1, lsResults.size());
                ProtocolFile testFile = lsResults.get(0);
                assertEquals(new ProtocolFile(testDir, "sshTestFile", false), 
testFile);

Added: 
oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/auth/TestHostKeyAuthentication.java
URL: 
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/auth/TestHostKeyAuthentication.java?rev=1134087&view=auto
==============================================================================
--- 
oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/auth/TestHostKeyAuthentication.java
 (added)
+++ 
oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/auth/TestHostKeyAuthentication.java
 Thu Jun  9 21:18:53 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.
+ */
+package org.apache.oodt.cas.protocol.sftp.auth;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link HostKeyAuthentication}.
+ * 
+ * @author bfoster
+ */
+public class TestHostKeyAuthentication extends TestCase {
+
+       public void testInitialState() {
+               HostKeyAuthentication auth = new HostKeyAuthentication("user", 
"pass", "file");
+               assertEquals("user", auth.getUser());
+               assertEquals("pass", auth.getPass());
+               assertEquals("file", auth.getHostKeyFile());
+       }
+       
+}

Propchange: 
oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/auth/TestHostKeyAuthentication.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to