You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-commits@incubator.apache.org by ng...@apache.org on 2006/11/15 22:06:18 UTC

svn commit: r475454 - in /incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests: DeleteTest.java HelpTest.java LangTest.java LoginTest.java MDTMTest.java StoreTest.java

Author: ngn
Date: Wed Nov 15 14:06:17 2006
New Revision: 475454

URL: http://svn.apache.org/viewvc?view=rev&rev=475454
Log:
Adding additional unit tests based on a coverage analysis

Added:
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/HelpTest.java   (with props)
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LangTest.java   (with props)
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/MDTMTest.java   (with props)
Modified:
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/StoreTest.java

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java?view=diff&rev=475454&r1=475453&r2=475454
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java (original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java Wed Nov 15 14:06:17 2006
@@ -47,6 +47,10 @@
         assertFalse(TEST_FILE1.exists());
     }
 
+    public void testDeleteNoFileName() throws Exception {
+        assertEquals(501, client.sendCommand("DELE"));
+    }
+    
     public void testDeleteWithSpaceInFileName() throws Exception {
         TEST_FILE_WITH_SPACE.createNewFile();
         

Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/HelpTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/HelpTest.java?view=auto&rev=475454
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/HelpTest.java (added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/HelpTest.java Wed Nov 15 14:06:17 2006
@@ -0,0 +1,55 @@
+/*
+ * 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.ftpserver.clienttests;
+
+
+
+public class HelpTest extends ClientTestTemplate {
+
+
+    /* (non-Javadoc)
+     * @see org.apache.ftpserver.clienttests.ClientTestTemplate#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+    }
+
+    public void testHelp() throws Exception {
+        assertEquals(214, client.help());
+        assertTrue(client.getReplyString().indexOf("The following commands are implemented") > -1);
+    }
+    
+    public void testHelpForCWD() throws Exception {
+        assertEquals(214, client.help("CWD"));
+        assertTrue(client.getReplyString().indexOf("Syntax: CWD") > -1);
+    }
+
+    public void testHelpForCWDLowerCase() throws Exception {
+        assertEquals(214, client.help("cwd"));
+        assertTrue(client.getReplyString().indexOf("Syntax: CWD") > -1);
+    }
+
+    public void testHelpForUnknownCommand() throws Exception {
+        assertEquals(214, client.help("foo"));
+        assertTrue(client.getReplyString().indexOf("The following commands are implemented") > -1);
+    }
+}

Propchange: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/HelpTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LangTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LangTest.java?view=auto&rev=475454
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LangTest.java (added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LangTest.java Wed Nov 15 14:06:17 2006
@@ -0,0 +1,67 @@
+/*
+ * 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.ftpserver.clienttests;
+
+import java.util.Properties;
+
+
+
+public class LangTest extends ClientTestTemplate {
+
+
+    /* (non-Javadoc)
+     * @see org.apache.ftpserver.clienttests.ClientTestTemplate#createConfig()
+     */
+    protected Properties createConfig() {
+        Properties config = super.createConfig();
+        config.setProperty("config.message.languages", "en,zh-tw");
+        return config;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ftpserver.clienttests.ClientTestTemplate#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+    }
+
+    public void testLangDefault() throws Exception {
+        assertEquals(200, client.sendCommand("LANG"));
+    }
+
+    public void testLangEn() throws Exception {
+        assertEquals(200, client.sendCommand("LANG EN"));
+    }
+
+    public void testLangZHTW() throws Exception {
+        assertEquals(200, client.sendCommand("LANG ZH-TW"));
+    }
+
+    public void testLangZHTWLowerCase() throws Exception {
+        assertEquals(200, client.sendCommand("LANG zh-tw"));
+    }
+    
+    public void testLangUnknownLang() throws Exception {
+        assertEquals(504, client.sendCommand("LANG FOO"));
+    }
+
+}

Propchange: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LangTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java?view=diff&rev=475454&r1=475453&r2=475454
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java (original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java Wed Nov 15 14:06:17 2006
@@ -42,7 +42,9 @@
     }
 
     public void testLoginWithAccount() throws Exception {
-        assertTrue(client.login(ADMIN_USERNAME, ADMIN_PASSWORD, UNKNOWN_PASSWORD));
+        assertTrue(client.login(ADMIN_USERNAME, ADMIN_PASSWORD));
+        
+        assertTrue(FTPReply.isPositiveCompletion(client.acct("FOO")));
     }
 
     public void testLoginWithEmptyPassword() throws Exception {

Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/MDTMTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/MDTMTest.java?view=auto&rev=475454
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/MDTMTest.java (added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/MDTMTest.java Wed Nov 15 14:06:17 2006
@@ -0,0 +1,67 @@
+/*
+ * 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.ftpserver.clienttests;
+
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+
+
+public class MDTMTest extends ClientTestTemplate {
+    private static final SimpleDateFormat FTP_DATE_FORMAT = new SimpleDateFormat("yyyyMMddhhmmss.SSS");
+    private static final File TEST_FILE1 = new File(ROOT_DIR, "test1.txt");
+    private static final File TEST_DIR1 = new File(ROOT_DIR, "dir1");
+    
+    /* (non-Javadoc)
+     * @see org.apache.ftpserver.clienttests.ClientTestTemplate#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+    }
+
+    public void testMDTMForFile() throws Exception {
+        TEST_FILE1.createNewFile();
+        Date expected = new Date(TEST_FILE1.lastModified());
+        assertEquals(213, client.sendCommand("MDTM " + TEST_FILE1.getName()));
+
+        Date actual = FTP_DATE_FORMAT.parse(client.getReplyString().substring(4).trim());
+        assertEquals(expected, actual);
+    }
+
+    public void testMDTMForDir() throws Exception {
+        TEST_DIR1.mkdirs();
+        Date expected = new Date(TEST_DIR1.lastModified());
+        assertEquals(213, client.sendCommand("MDTM " + TEST_DIR1.getName()));
+        
+        Date actual = FTP_DATE_FORMAT.parse(client.getReplyString().substring(4).trim());
+        assertEquals(expected, actual);
+    }
+    
+    public void testMDTMForNonExistingFile() throws Exception {
+        assertEquals(550, client.sendCommand("MDTM " + TEST_FILE1.getName()));
+    }
+
+    public void testMDTMWithNoFileName() throws Exception {
+        assertEquals(501, client.sendCommand("MDTM"));
+    }
+}

Propchange: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/MDTMTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/StoreTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/StoreTest.java?view=diff&rev=475454&r1=475453&r2=475454
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/StoreTest.java (original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/StoreTest.java Wed Nov 15 14:06:17 2006
@@ -67,6 +67,7 @@
     public void testStoreNoFileName() throws Exception {
         assertEquals(501, client.sendCommand("STOR"));
     }
+    
     /* TODO: this test now fails as we don't detect the invalid file name
      * A future improvment would be to detect this and report an error
     public void testStoreInValidFileName() throws Exception {
@@ -160,6 +161,10 @@
         
         doAssertOfUniqueFile(client, ROOT_DIR);
     }
+    
+    public void testStoreUniqueNoFileName() throws Exception {
+        assertEquals(501, client.sendCommand("STOU"));
+    }
 
     public void testStoreUniqueWithDirectoryWithTrailingSlash() throws Exception {
         TEST_DIR.mkdirs();
@@ -196,6 +201,10 @@
         TestUtil.assertFileEqual(doubleTestData, testFile);
     }
 
+    public void testAppendNoFileName() throws Exception {
+        assertEquals(501, client.sendCommand("APPE"));
+    }
+    
     public void testAppendWithDirectoryInPlace() throws Exception {
         File testFile = new File(ROOT_DIR, TEST_FILENAME);
         testFile.mkdirs();