incubator-ftpserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r565038 - in /incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem: FileObjectTestTemplate.java NativeFileObjectTest.java
Date Sun, 12 Aug 2007 11:57:58 GMT
Author: ngn
Date: Sun Aug 12 04:57:57 2007
New Revision: 565038

URL: http://svn.apache.org/viewvc?view=rev&rev=565038
Log:
Refactor file object test to a generic template

Added:
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileObjectTestTemplate.java
  (with props)
Modified:
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/NativeFileObjectTest.java

Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileObjectTestTemplate.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileObjectTestTemplate.java?view=auto&rev=565038
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileObjectTestTemplate.java
(added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileObjectTestTemplate.java
Sun Aug 12 04:57:57 2007
@@ -0,0 +1,93 @@
+package org.apache.ftpserver.filesystem;
+
+
+import junit.framework.TestCase;
+
+import org.apache.ftpserver.ftplet.AuthorizationRequest;
+import org.apache.ftpserver.ftplet.FileObject;
+import org.apache.ftpserver.ftplet.User;
+import org.apache.ftpserver.usermanager.BaseUser;
+
+public abstract class FileObjectTestTemplate extends TestCase {
+
+    protected static final String FILE2_PATH = "/dir1/file2";
+    protected static final String DIR1_PATH = "/dir1";
+    protected static final String DIR1_WITH_SLASH_PATH = "/dir1/";
+    protected static final String FILE1_PATH = "/file1";
+    
+    protected static final User USER = new BaseUser() {
+        public AuthorizationRequest authorize(AuthorizationRequest request) {
+            return request;
+        }
+    };
+
+    public FileObjectTestTemplate() {
+        super();
+    }
+
+    public FileObjectTestTemplate(String name) {
+        super(name);
+    }
+
+    protected abstract FileObject createFile(String fileName, User user);
+    
+    
+    public void testNullFileName() {
+        try{
+            createFile(null, USER);
+            fail("Must throw IllegalArgumentException");
+        } catch(IllegalArgumentException e) {
+            // OK
+        }
+    }
+
+    public void testWhiteSpaceFileName() {
+        try{
+            createFile(" \t", USER);
+           fail("Must throw IllegalArgumentException");
+        } catch(IllegalArgumentException e) {
+            // OK
+        } 
+    }
+    
+    public void testEmptyFileName() {
+        try{
+            createFile("", USER);
+            fail("Must throw IllegalArgumentException");
+        } catch(IllegalArgumentException e) {
+            // OK
+        }
+    }
+
+    public void testNonLeadingSlash() {
+        try{
+            createFile("foo", USER);
+            fail("Must throw IllegalArgumentException");
+        } catch(IllegalArgumentException e) {
+            // OK
+        }
+    }
+
+    public void testFullName() {
+        FileObject fileObject = createFile(FILE2_PATH, USER);
+        assertEquals("/dir1/file2", fileObject.getFullName());
+    
+        fileObject = createFile("/dir1/", USER);
+        assertEquals("/dir1", fileObject.getFullName());
+    
+        fileObject = createFile("/dir1", USER);
+        assertEquals("/dir1", fileObject.getFullName());
+    }
+
+    public void testShortName() {
+        FileObject fileObject = createFile("/dir1/file2", USER);
+        assertEquals("file2", fileObject.getShortName());
+    
+        fileObject = createFile("/dir1/", USER);
+        assertEquals("dir1", fileObject.getShortName());
+    
+        fileObject = createFile("/dir1", USER);
+        assertEquals("dir1", fileObject.getShortName());
+    }
+
+}
\ No newline at end of file

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

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/NativeFileObjectTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/NativeFileObjectTest.java?view=diff&rev=565038&r1=565037&r2=565038
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/NativeFileObjectTest.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/NativeFileObjectTest.java
Sun Aug 12 04:57:57 2007
@@ -21,14 +21,14 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
-import junit.framework.TestCase;
-
-import org.apache.ftpserver.ftplet.AuthorizationRequest;
-import org.apache.ftpserver.usermanager.BaseUser;
+import org.apache.ftpserver.ftplet.FileObject;
+import org.apache.ftpserver.ftplet.User;
 import org.apache.ftpserver.util.IoUtils;
 
-public class NativeFileObjectTest extends TestCase {
+public class NativeFileObjectTest extends FileObjectTestTemplate {
 
     private static final File TEST_TMP_DIR = new File("test-tmp");
     private static final File ROOT_DIR = new File(TEST_TMP_DIR, "ftproot");
@@ -36,6 +36,16 @@
     private static final File TEST_FILE1 = new File(ROOT_DIR, "file1");
     private static final File TEST_FILE2_IN_DIR1 = new File(TEST_DIR1, "file2");
 
+    private static final Map FILE_MAPPINGS = new HashMap();
+    
+    static {
+        FILE_MAPPINGS.put(FILE2_PATH, TEST_FILE2_IN_DIR1);
+        FILE_MAPPINGS.put(DIR1_PATH, TEST_DIR1);
+        FILE_MAPPINGS.put(FILE1_PATH, TEST_FILE1);
+        FILE_MAPPINGS.put(DIR1_WITH_SLASH_PATH, TEST_DIR1);
+        FILE_MAPPINGS.put(" \t", TEST_FILE2_IN_DIR1);
+    }
+    
     private static final String ROOT_DIR_PATH = ROOT_DIR.getAbsolutePath()
             .replace(File.separatorChar, '/');
 
@@ -45,19 +55,6 @@
     private static final String FULL_PATH_NO_CURRDIR = ROOT_DIR_PATH + "/"
             + TEST_FILE2_IN_DIR1.getName();
 
-    public static class AlwaysAuthorizedUser extends BaseUser {
-
-        public AuthorizationRequest authorize(AuthorizationRequest request) {
-            return request;
-        }
-        
-    }
-    
-    /*
-     * (non-Javadoc)
-     * 
-     * @see junit.framework.TestCase#setUp()
-     */
     protected void setUp() throws Exception {
         initDirs();
 
@@ -65,6 +62,11 @@
         TEST_FILE1.createNewFile();
         TEST_FILE2_IN_DIR1.createNewFile();
     }
+    
+
+    protected FileObject createFile(String fileName, User user) {
+        return new NativeFileObject(fileName, (File)FILE_MAPPINGS.get(fileName), user);
+    }
 
     public void testGetPhysicalName() {
 
@@ -135,82 +137,15 @@
         
     }
 
-    
-    public void testConstructorWithNullFileName() {
-        try{
-            new NativeFileObject(null, TEST_FILE2_IN_DIR1, new AlwaysAuthorizedUser());
-            fail("Must throw IllegalArgumentException");
-        } catch(IllegalArgumentException e) {
-            // OK
-        }
-    }
-
-    public void testEmptyFileName() {
-        try{
-            new NativeFileObject("", TEST_FILE2_IN_DIR1, new AlwaysAuthorizedUser());
-            fail("Must throw IllegalArgumentException");
-        } catch(IllegalArgumentException e) {
-            // OK
-        }
-    }
-
-    public void testNonLeadingSlash() {
-        try{
-            new NativeFileObject("foo", TEST_FILE2_IN_DIR1, new AlwaysAuthorizedUser());
-            fail("Must throw IllegalArgumentException");
-        } catch(IllegalArgumentException e) {
-            // OK
-        }
-    }
-
-    public void testWhiteSpaceFileName() {
-        try{
-            new NativeFileObject(" \t", TEST_FILE2_IN_DIR1, new AlwaysAuthorizedUser());
-            fail("Must throw IllegalArgumentException");
-        } catch(IllegalArgumentException e) {
-            // OK
-        } 
-    }
-
     public void testConstructorWithNullFile() {
         try{
-            new NativeFileObject("foo", null, new AlwaysAuthorizedUser());
+            new NativeFileObject("foo", null, USER);
             fail("Must throw IllegalArgumentException");
         } catch(IllegalArgumentException e) {
             // OK
         }
     }
 
-    
-    public void testFullName() {
-        NativeFileObject fileObject = new NativeFileObject("/dir1/file2",
-                TEST_FILE2_IN_DIR1, new AlwaysAuthorizedUser());
-        assertEquals("/dir1/file2", fileObject.getFullName());
-
-        fileObject = new NativeFileObject("/dir1/", TEST_DIR1, new AlwaysAuthorizedUser());
-        assertEquals("/dir1", fileObject.getFullName());
-
-        fileObject = new NativeFileObject("/dir1", TEST_DIR1, new AlwaysAuthorizedUser());
-        assertEquals("/dir1", fileObject.getFullName());
-    }
-
-    public void testShortName() {
-        NativeFileObject fileObject = new NativeFileObject("/dir1/file2",
-                TEST_FILE2_IN_DIR1, new AlwaysAuthorizedUser());
-        assertEquals("file2", fileObject.getShortName());
-
-        fileObject = new NativeFileObject("/dir1/", TEST_DIR1, new AlwaysAuthorizedUser());
-        assertEquals("dir1", fileObject.getShortName());
-
-        fileObject = new NativeFileObject("/dir1", TEST_DIR1, new AlwaysAuthorizedUser());
-        assertEquals("dir1", fileObject.getShortName());
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see junit.framework.TestCase#tearDown()
-     */
     protected void tearDown() throws Exception {
         cleanTmpDirs();
     }
@@ -230,5 +165,6 @@
             IoUtils.delete(TEST_TMP_DIR);
         }
     }
+
 
 }



Mime
View raw message