Author: tpalsulich
Date: Mon Dec 29 20:45:45 2014
New Revision: 1648423

URL: http://svn.apache.org/r1648423
Log:
OODT-762. Migrate protocol/ftp test resources.

Added:
    oodt/trunk/protocol/ftp/src/test/java/
    oodt/trunk/protocol/ftp/src/test/java/org/
    oodt/trunk/protocol/ftp/src/test/java/org/apache/
    oodt/trunk/protocol/ftp/src/test/java/org/apache/oodt/
    oodt/trunk/protocol/ftp/src/test/java/org/apache/oodt/cas/
    oodt/trunk/protocol/ftp/src/test/java/org/apache/oodt/cas/protocol/
    oodt/trunk/protocol/ftp/src/test/java/org/apache/oodt/cas/protocol/ftp/
    
oodt/trunk/protocol/ftp/src/test/java/org/apache/oodt/cas/protocol/ftp/TestCogJGlobusFtpProtocol.java
    oodt/trunk/protocol/ftp/src/test/resources/
    oodt/trunk/protocol/ftp/src/test/resources/users.properties
Removed:
    oodt/trunk/protocol/ftp/src/test/org/
    oodt/trunk/protocol/ftp/src/testdata/

Added: 
oodt/trunk/protocol/ftp/src/test/java/org/apache/oodt/cas/protocol/ftp/TestCogJGlobusFtpProtocol.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/protocol/ftp/src/test/java/org/apache/oodt/cas/protocol/ftp/TestCogJGlobusFtpProtocol.java?rev=1648423&view=auto
==============================================================================
--- 
oodt/trunk/protocol/ftp/src/test/java/org/apache/oodt/cas/protocol/ftp/TestCogJGlobusFtpProtocol.java
 (added)
+++ 
oodt/trunk/protocol/ftp/src/test/java/org/apache/oodt/cas/protocol/ftp/TestCogJGlobusFtpProtocol.java
 Mon Dec 29 20:45:45 2014
@@ -0,0 +1,138 @@
+/*
+ * 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.ArrayList;
+import java.util.List;
+import java.util.Vector;
+
+//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;
+import org.globus.ftp.FileInfo;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import static org.mockito.Mockito.spy;
+
+/**
+ * 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/test/resources/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 = spy(new 
CogJGlobusFtpProtocol(PORT));
+        BasicAuthentication auth = new BasicAuthentication("anonymous", 
"password");
+
+        /** Mocking server responses to prevent server failure **/
+
+        Mockito.doReturn("test/resources").when(ftpProtocol).getCurentDir();
+
+        Vector<FileInfo> vector = new Vector<FileInfo>();
+        FileInfo file = new FileInfo();
+        file.setName("users.properties");
+        byte b = 1;
+        file.setFileType(b);
+        vector.add(file);
+
+        Mockito.doAnswer(new Answer() {
+            public Object answer(InvocationOnMock invocation) {
+                return null;
+            }}).when(ftpProtocol).setActive();
+
+        Mockito.doReturn(vector).when(ftpProtocol).ftpList("*", null);
+
+        Mockito.doAnswer(new Answer() {
+            public Object answer(InvocationOnMock invocation) {
+                return null;
+            }}).when(ftpProtocol).connect("localhost", auth);
+
+        Mockito.doAnswer(new Answer() {
+            public Object answer(InvocationOnMock invocation) {
+                return null;
+            }}).when(ftpProtocol).cd(new ProtocolFile("test/resources", true));
+
+
+
+        ftpProtocol.connect("localhost", auth);
+
+
+               ftpProtocol.cd(new ProtocolFile("test/resources", true));
+
+               List<ProtocolFile> lsResults = ftpProtocol.ls();
+               assertTrue(lsResults.contains(new 
ProtocolFile(ftpProtocol.pwd(), "users.properties", false)));
+       }
+       
+}

Added: oodt/trunk/protocol/ftp/src/test/resources/users.properties
URL: 
http://svn.apache.org/viewvc/oodt/trunk/protocol/ftp/src/test/resources/users.properties?rev=1648423&view=auto
==============================================================================
--- oodt/trunk/protocol/ftp/src/test/resources/users.properties (added)
+++ oodt/trunk/protocol/ftp/src/test/resources/users.properties Mon Dec 29 
20:45:45 2014
@@ -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


Reply via email to