incubator-ftpserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r565040 - in /incubator/ftpserver/trunk: core/src/java/org/apache/ftpserver/filesystem/ core/src/java/org/apache/ftpserver/listing/ core/src/test/org/apache/ftpserver/filesystem/ ftplet-api/src/java/org/apache/ftpserver/ftplet/
Date Sun, 12 Aug 2007 12:11:33 GMT
Author: ngn
Date: Sun Aug 12 05:11:32 2007
New Revision: 565040

URL: http://svn.apache.org/viewvc?view=rev&rev=565040
Log:
Make sure files are returned in alphabetical order (FTPSERVER-103)
Refactor tests further to make the reusable for other file system implementations

Added:
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileSystemViewTemplate.java
  (with props)
Modified:
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/filesystem/NativeFileObject.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listing/DirectoryLister.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileObjectTestTemplate.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/NativeFileObjectTest.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/NativeFileSystemViewTest.java
    incubator/ftpserver/trunk/ftplet-api/src/java/org/apache/ftpserver/ftplet/FileObject.java

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/filesystem/NativeFileObject.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/filesystem/NativeFileObject.java?view=diff&rev=565040&r1=565039&r2=565040
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/filesystem/NativeFileObject.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/filesystem/NativeFileObject.java
Sun Aug 12 05:11:32 2007
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */  
+ */
 
 package org.apache.ftpserver.filesystem;
 
@@ -26,6 +26,8 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.RandomAccessFile;
+import java.util.Arrays;
+import java.util.Comparator;
 import java.util.StringTokenizer;
 
 import org.apache.ftpserver.ftplet.FileObject;
@@ -33,204 +35,201 @@
 import org.apache.ftpserver.usermanager.WriteRequest;
 
 /**
- * This class wraps native file object. 
+ * This class wraps native file object.
  */
-public 
-class NativeFileObject implements FileObject {
+public class NativeFileObject implements FileObject {
 
     // the file name with respect to the user root.
     // The path separator character will be '/' and
     // it will always begin with '/'.
     private String fileName;
-    
+
     private File file;
-    
+
     private User user;
-    
-    
+
     /**
      * Constructor.
      */
     protected NativeFileObject(String fileName, File file, User user) {
-        if(fileName == null) {
+        if (fileName == null) {
             throw new IllegalArgumentException("fileName can not be null");
-        } 
-        if(file == null) {
+        }
+        if (file == null) {
             throw new IllegalArgumentException("file can not be null");
-        } 
+        }
         fileName = fileName.trim();
-        if(fileName.length() == 0) {
+        if (fileName.length() == 0) {
             throw new IllegalArgumentException("fileName can not be empty");
-        } else if(fileName.charAt(0) != '/') {
-            throw new IllegalArgumentException("fileName must be an absolut path");
+        } else if (fileName.charAt(0) != '/') {
+            throw new IllegalArgumentException(
+                    "fileName must be an absolut path");
         }
-        
-        
-        
+
         this.fileName = fileName;
         this.file = file;
         this.user = user;
     }
-    
+
     /**
      * Get full name.
      */
     public String getFullName() {
-        
+
         // strip the last '/' if necessary
         String fullName = fileName;
         int filelen = fullName.length();
-        if( (filelen != 1)&& (fullName.charAt(filelen - 1) == '/') ) {
+        if ((filelen != 1) && (fullName.charAt(filelen - 1) == '/')) {
             fullName = fullName.substring(0, filelen - 1);
         }
-        
+
         return fullName;
     }
-    
+
     /**
      * Get short name.
      */
     public String getShortName() {
-        
+
         // root - the short name will be '/'
-        if(fileName.equals("/")) {
+        if (fileName.equals("/")) {
             return "/";
         }
-        
+
         // strip the last '/'
         String shortName = fileName;
         int filelen = fileName.length();
-        if(shortName.charAt(filelen - 1) == '/') {
+        if (shortName.charAt(filelen - 1) == '/') {
             shortName = shortName.substring(0, filelen - 1);
         }
-        
+
         // return from the last '/'
         int slashIndex = shortName.lastIndexOf('/');
-        if(slashIndex != -1) {
+        if (slashIndex != -1) {
             shortName = shortName.substring(slashIndex + 1);
         }
         return shortName;
     }
-    
+
     /**
      * Is a hidden file?
      */
     public boolean isHidden() {
         return file.isHidden();
     }
-     
+
     /**
      * Is it a directory?
      */
     public boolean isDirectory() {
         return file.isDirectory();
     }
-    
+
     /**
      * Is it a file?
      */
     public boolean isFile() {
         return file.isFile();
     }
-    
+
     /**
      * Does this file exists?
      */
     public boolean doesExist() {
         return file.exists();
     }
-    
+
     /**
      * Get file size.
      */
     public long getSize() {
         return file.length();
     }
-    
+
     /**
      * Get file owner.
      */
     public String getOwnerName() {
         return "user";
     }
-    
+
     /**
      * Get group name
      */
     public String getGroupName() {
         return "group";
     }
-    
+
     /**
      * Get link count
      */
     public int getLinkCount() {
         return file.isDirectory() ? 3 : 1;
     }
-    
+
     /**
      * Get last modified time.
-     */ 
+     */
     public long getLastModified() {
         return file.lastModified();
     }
-    
+
     /**
      * Check read permission.
      */
     public boolean hasReadPermission() {
         return file.canRead();
     }
-    
+
     /**
      * Check file write permission.
      */
     public boolean hasWritePermission() {
-        if(user.authorize(new WriteRequest(getFullName())) == null) {
+        if (user.authorize(new WriteRequest(getFullName())) == null) {
             return false;
         }
-        
-        if(file.exists()) {
+
+        if (file.exists()) {
             return file.canWrite();
         }
         return true;
     }
-    
+
     /**
      * Has delete permission.
      */
     public boolean hasDeletePermission() {
-        
+
         // root cannot be deleted
-        if( "/".equals(fileName) ) {
+        if ("/".equals(fileName)) {
             return false;
         }
-        
+
         return hasWritePermission();
     }
-    
+
     /**
      * Delete file.
      */
     public boolean delete() {
         boolean retVal = false;
-        if( hasDeletePermission() ) {
+        if (hasDeletePermission()) {
             retVal = file.delete();
         }
         return retVal;
     }
-    
+
     /**
      * Move file object.
      */
     public boolean move(FileObject dest) {
         boolean retVal = false;
-        if(dest.hasWritePermission() && hasReadPermission()) {
-            File destFile = ((NativeFileObject)dest).file;
-            
-            if(destFile.exists()) {
+        if (dest.hasWritePermission() && hasReadPermission()) {
+            File destFile = ((NativeFileObject) dest).file;
+
+            if (destFile.exists()) {
                 // renameTo behaves differently on different platforms
-                // this check verifies that if the destination already exists, 
+                // this check verifies that if the destination already exists,
                 // we fail
                 retVal = false;
             } else {
@@ -239,214 +238,221 @@
         }
         return retVal;
     }
-    
+
     /**
      * Create directory.
      */
     public boolean mkdir() {
         boolean retVal = false;
-        if(hasWritePermission()) {
+        if (hasWritePermission()) {
             retVal = file.mkdirs();
         }
         return retVal;
     }
-    
+
     /**
      * Get the physical file object.
      */
     public File getPhysicalFile() {
         return file;
     }
-    
+
     /**
-     * List files. If not a directory or does not exist, null
-     * will be returned. 
+     * List files. If not a directory or does not exist, null will be returned.
      */
     public FileObject[] listFiles() {
-    	
-    	// is a directory
-    	if(!file.isDirectory()) {
-    		return null;
-    	}
-    	
+
+        // is a directory
+        if (!file.isDirectory()) {
+            return null;
+        }
+
         // directory - return all the files
         File[] files = file.listFiles();
-        if(files == null) {
+        if (files == null) {
             return null;
         }
-        
+
+        // make sure the files are returned in order
+        Arrays.sort(files, new Comparator() {
+            public int compare(Object o1, Object o2) {
+                File f1 = (File) o1;
+                File f2 = (File) o2;
+
+                return f1.getName().compareTo(f2.getName());
+            }
+        });
+
         // get the virtual name of the base directory
         String virtualFileStr = getFullName();
-        if(virtualFileStr.charAt(virtualFileStr.length() - 1) != '/') {
+        if (virtualFileStr.charAt(virtualFileStr.length() - 1) != '/') {
             virtualFileStr += '/';
         }
-        
+
         // now return all the files under the directory
         FileObject[] virtualFiles = new FileObject[files.length];
-        for(int i=0; i<files.length; ++i) {
+        for (int i = 0; i < files.length; ++i) {
             File fileObj = files[i];
             String fileName = virtualFileStr + fileObj.getName();
             virtualFiles[i] = new NativeFileObject(fileName, fileObj, user);
         }
+
         return virtualFiles;
     }
-    
+
     /**
      * Create output stream for writing.
      */
     public OutputStream createOutputStream(long offset) throws IOException {
-        
+
         // permission check
-        if(!hasWritePermission()) {
+        if (!hasWritePermission()) {
             throw new IOException("No write permission : " + file.getName());
         }
-        
+
         // create output stream
         RandomAccessFile raf = new RandomAccessFile(file, "rw");
         raf.setLength(offset);
         raf.seek(offset);
         return new FileOutputStream(raf.getFD());
     }
-    
+
     /**
      * Create input stream for reading.
      */
     public InputStream createInputStream(long offset) throws IOException {
-        
+
         // permission check
-        if(!hasReadPermission()) {
+        if (!hasReadPermission()) {
             throw new IOException("No read permission : " + file.getName());
         }
-        
+
         // move to the appropriate offset and create input stream
         RandomAccessFile raf = new RandomAccessFile(file, "r");
         raf.seek(offset);
         return new FileInputStream(raf.getFD());
     }
-    
+
     /**
      * Normalize separate characher. Separate character should be '/' always.
      */
     public final static String normalizeSeparateChar(String pathName) {
-       pathName = pathName.replace(File.separatorChar, '/');
-       pathName = pathName.replace('\\', '/');
-       return pathName;
+        pathName = pathName.replace(File.separatorChar, '/');
+        pathName = pathName.replace('\\', '/');
+        return pathName;
     }
-    
+
     /**
-     * Get the physical canonical file name. It works like 
+     * Get the physical canonical file name. It works like
      * File.getCanonicalPath().
      * 
-     * @param rootDir The root directory. 
-     * 
-     * @param currDir The current directory. It will always be with
-     * respect to the root directory. 
-     * 
-     * @param fileName The input file name.
-     * 
-     * @return The return string will always begin with the root directory.
-     * It will never be null.
-     */
-    public final static String getPhysicalName(String rootDir, 
-    		String currDir, 
-    		String fileName) {
-    	return getPhysicalName(rootDir, currDir, fileName, false);
-    }
-    
-    public final static String getPhysicalName(String rootDir, 
-                                               String currDir, 
-                                               String fileName, boolean caseInsensitive)
{
-        
+     * @param rootDir
+     *            The root directory.
+     * @param currDir
+     *            The current directory. It will always be with respect to the
+     *            root directory.
+     * @param fileName
+     *            The input file name.
+     * @return The return string will always begin with the root directory. It
+     *         will never be null.
+     */
+    public final static String getPhysicalName(String rootDir, String currDir,
+            String fileName) {
+        return getPhysicalName(rootDir, currDir, fileName, false);
+    }
+
+    public final static String getPhysicalName(String rootDir, String currDir,
+            String fileName, boolean caseInsensitive) {
+
         // get the starting directory
         rootDir = rootDir.trim();
         fileName = fileName.trim();
-        
+
         rootDir = normalizeSeparateChar(rootDir);
-        if(rootDir.charAt(rootDir.length() - 1) != '/') {
+        if (rootDir.charAt(rootDir.length() - 1) != '/') {
             rootDir += '/';
         }
-        
+
         fileName = normalizeSeparateChar(fileName);
         String resArg;
-        if(fileName.charAt(0) != '/') {
-            if(currDir == null) {
+        if (fileName.charAt(0) != '/') {
+            if (currDir == null) {
                 currDir = "/";
             }
             currDir = currDir.trim();
-            if(currDir.length() == 0) {
+            if (currDir.length() == 0) {
                 currDir = "/";
             }
-            
+
             currDir = normalizeSeparateChar(currDir);
-            
-            if(currDir.charAt(0) != '/') {
+
+            if (currDir.charAt(0) != '/') {
                 currDir = '/' + currDir;
             }
-            if(currDir.charAt(currDir.length() - 1) != '/') {
+            if (currDir.charAt(currDir.length() - 1) != '/') {
                 currDir += '/';
             }
 
-            
             resArg = rootDir + currDir.substring(1);
-        }
-        else {
+        } else {
             resArg = rootDir;
         }
-        
+
         // strip last '/'
-        if(resArg.charAt(resArg.length() -1) == '/') {
-            resArg = resArg.substring(0, resArg.length()-1);
+        if (resArg.charAt(resArg.length() - 1) == '/') {
+            resArg = resArg.substring(0, resArg.length() - 1);
         }
-        
+
         // replace ., ~ and ..
         // in this loop resArg will never end with '/'
         StringTokenizer st = new StringTokenizer(fileName, "/");
-        while(st.hasMoreTokens()) {
+        while (st.hasMoreTokens()) {
             String tok = st.nextToken().trim();
-                        
+
             // . => current directory
-            if(tok.equals(".")) {
+            if (tok.equals(".")) {
                 continue;
             }
-            
+
             // .. => parent directory (if not root)
-            if(tok.equals("..")) {
-                if(resArg.startsWith(rootDir)) {
+            if (tok.equals("..")) {
+                if (resArg.startsWith(rootDir)) {
                     int slashIndex = resArg.lastIndexOf('/');
-                    if(slashIndex != -1) {
+                    if (slashIndex != -1) {
                         resArg = resArg.substring(0, slashIndex);
                     }
                 }
                 continue;
             }
-            
+
             // ~ => home directory (in this case the root directory)
             if (tok.equals("~")) {
-                resArg = rootDir.substring(0, rootDir.length()-1);
+                resArg = rootDir.substring(0, rootDir.length() - 1);
                 continue;
             }
-            
-            if(caseInsensitive) {
-            	File[] matches = new File(resArg).listFiles(new NameEqualsFileFilter(tok, true));
           	
-            	
-            	if(matches.length > 0) {
-            		tok = matches[0].getName();
-            	}
+
+            if (caseInsensitive) {
+                File[] matches = new File(resArg)
+                        .listFiles(new NameEqualsFileFilter(tok, true));
+
+                if (matches.length > 0) {
+                    tok = matches[0].getName();
+                }
             }
-            
+
             resArg = resArg + '/' + tok;
         }
-        
+
         // add last slash if necessary
-        if( (resArg.length()) + 1 == rootDir.length() ) {
+        if ((resArg.length()) + 1 == rootDir.length()) {
             resArg += '/';
         }
-        
+
         // final check
-        if ( !resArg.regionMatches(0, rootDir, 0, rootDir.length()) ) {
+        if (!resArg.regionMatches(0, rootDir, 0, rootDir.length())) {
             resArg = rootDir;
         }
-        
+
         return resArg;
     }
 }

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listing/DirectoryLister.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listing/DirectoryLister.java?view=diff&rev=565040&r1=565039&r2=565040
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listing/DirectoryLister.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listing/DirectoryLister.java
Sun Aug 12 05:11:32 2007
@@ -79,7 +79,7 @@
     }
     
     /**
-     * Get the file list.
+     * Get the file list. Files will be listed in alphabetlical order.
      */
     private FileObject[] listFiles(FileSystemView fileSystemView, String file) {
     	FileObject[] files = null;

Modified: 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=diff&rev=565040&r1=565039&r2=565040
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileObjectTestTemplate.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileObjectTestTemplate.java
Sun Aug 12 05:11:32 2007
@@ -14,6 +14,7 @@
     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 String FILE3_PATH = "/file3";
     
     protected static final User USER = new BaseUser() {
         public AuthorizationRequest authorize(AuthorizationRequest request) {
@@ -21,20 +22,12 @@
         }
     };
 
-    public FileObjectTestTemplate() {
-        super();
-    }
-
-    public FileObjectTestTemplate(String name) {
-        super(name);
-    }
-
-    protected abstract FileObject createFile(String fileName, User user);
+    protected abstract FileObject createFileObject(String fileName, User user);
     
     
     public void testNullFileName() {
         try{
-            createFile(null, USER);
+            createFileObject(null, USER);
             fail("Must throw IllegalArgumentException");
         } catch(IllegalArgumentException e) {
             // OK
@@ -43,7 +36,7 @@
 
     public void testWhiteSpaceFileName() {
         try{
-            createFile(" \t", USER);
+            createFileObject(" \t", USER);
            fail("Must throw IllegalArgumentException");
         } catch(IllegalArgumentException e) {
             // OK
@@ -52,7 +45,7 @@
     
     public void testEmptyFileName() {
         try{
-            createFile("", USER);
+            createFileObject("", USER);
             fail("Must throw IllegalArgumentException");
         } catch(IllegalArgumentException e) {
             // OK
@@ -61,7 +54,7 @@
 
     public void testNonLeadingSlash() {
         try{
-            createFile("foo", USER);
+            createFileObject("foo", USER);
             fail("Must throw IllegalArgumentException");
         } catch(IllegalArgumentException e) {
             // OK
@@ -69,25 +62,35 @@
     }
 
     public void testFullName() {
-        FileObject fileObject = createFile(FILE2_PATH, USER);
+        FileObject fileObject = createFileObject(FILE2_PATH, USER);
         assertEquals("/dir1/file2", fileObject.getFullName());
     
-        fileObject = createFile("/dir1/", USER);
+        fileObject = createFileObject("/dir1/", USER);
         assertEquals("/dir1", fileObject.getFullName());
     
-        fileObject = createFile("/dir1", USER);
+        fileObject = createFileObject("/dir1", USER);
         assertEquals("/dir1", fileObject.getFullName());
     }
 
     public void testShortName() {
-        FileObject fileObject = createFile("/dir1/file2", USER);
+        FileObject fileObject = createFileObject("/dir1/file2", USER);
         assertEquals("file2", fileObject.getShortName());
     
-        fileObject = createFile("/dir1/", USER);
+        fileObject = createFileObject("/dir1/", USER);
         assertEquals("dir1", fileObject.getShortName());
     
-        fileObject = createFile("/dir1", USER);
+        fileObject = createFileObject("/dir1", USER);
         assertEquals("dir1", fileObject.getShortName());
+    }
+    
+    public void testListFilesInOrder() {
+        FileObject root = createFileObject("/", USER);
+        
+        FileObject[] files = root.listFiles();
+        assertEquals(3, files.length);
+        assertEquals("dir1", files[0].getShortName());
+        assertEquals("file1", files[1].getShortName());
+        assertEquals("file3", files[2].getShortName());
     }
 
 }

Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileSystemViewTemplate.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileSystemViewTemplate.java?view=auto&rev=565040
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileSystemViewTemplate.java
(added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileSystemViewTemplate.java
Sun Aug 12 05:11:32 2007
@@ -0,0 +1,51 @@
+package org.apache.ftpserver.filesystem;
+
+import org.apache.ftpserver.usermanager.BaseUser;
+
+import junit.framework.TestCase;
+
+public abstract class FileSystemViewTemplate extends TestCase {
+
+    protected static final String DIR1_NAME = "dir1";
+   
+    protected BaseUser user = new BaseUser();
+
+    
+    public void testChangeDirectory() throws Exception {
+        NativeFileSystemView view = new NativeFileSystemView(user);
+        assertEquals("/", view.getCurrentDirectory().getFullName());
+
+        assertTrue(view.changeDirectory(DIR1_NAME));
+        assertEquals("/" + DIR1_NAME, view.getCurrentDirectory().getFullName());
+        
+        assertTrue(view.changeDirectory("."));
+        assertEquals("/" + DIR1_NAME, view.getCurrentDirectory().getFullName());
+
+        assertTrue(view.changeDirectory(".."));
+        assertEquals("/", view.getCurrentDirectory().getFullName());
+
+        assertTrue(view.changeDirectory("./" + DIR1_NAME));
+        assertEquals("/" + DIR1_NAME, view.getCurrentDirectory().getFullName());
+
+        assertTrue(view.changeDirectory("~"));
+        assertEquals("/", view.getCurrentDirectory().getFullName());
+    }
+
+    public void testChangeDirectoryCaseInsensitive() throws Exception {
+        NativeFileSystemView view = new NativeFileSystemView(user, true);
+        assertEquals("/", view.getCurrentDirectory().getFullName());
+        
+        assertTrue(view.changeDirectory("/DIR1"));
+        assertEquals("/dir1", view.getCurrentDirectory().getFullName());
+        assertTrue(view.getCurrentDirectory().doesExist());
+        
+        assertTrue(view.changeDirectory("/dir1"));
+        assertEquals("/dir1", view.getCurrentDirectory().getFullName());
+        assertTrue(view.getCurrentDirectory().doesExist());
+
+        assertTrue(view.changeDirectory("/DiR1"));
+        assertEquals("/dir1", view.getCurrentDirectory().getFullName());
+        assertTrue(view.getCurrentDirectory().doesExist());
+    }
+
+}
\ No newline at end of file

Propchange: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/FileSystemViewTemplate.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=565040&r1=565039&r2=565040
==============================================================================
--- 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 05:11:32 2007
@@ -35,13 +35,16 @@
     private static final File TEST_DIR1 = new File(ROOT_DIR, "dir1");
     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 File TEST_FILE3 = new File(ROOT_DIR, "file3");
 
     private static final Map FILE_MAPPINGS = new HashMap();
     
     static {
+        FILE_MAPPINGS.put("/", ROOT_DIR);
         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(FILE2_PATH, TEST_FILE3);
         FILE_MAPPINGS.put(DIR1_WITH_SLASH_PATH, TEST_DIR1);
         FILE_MAPPINGS.put(" \t", TEST_FILE2_IN_DIR1);
     }
@@ -61,10 +64,11 @@
         TEST_DIR1.mkdirs();
         TEST_FILE1.createNewFile();
         TEST_FILE2_IN_DIR1.createNewFile();
+        TEST_FILE3.createNewFile();
     }
     
 
-    protected FileObject createFile(String fileName, User user) {
+    protected FileObject createFileObject(String fileName, User user) {
         return new NativeFileObject(fileName, (File)FILE_MAPPINGS.get(fileName), user);
     }
 

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/NativeFileSystemViewTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/NativeFileSystemViewTest.java?view=diff&rev=565040&r1=565039&r2=565040
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/NativeFileSystemViewTest.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/filesystem/NativeFileSystemViewTest.java
Sun Aug 12 05:11:32 2007
@@ -22,48 +22,22 @@
 import java.io.File;
 import java.io.IOException;
 
-import junit.framework.TestCase;
-
 import org.apache.ftpserver.ftplet.FtpException;
-import org.apache.ftpserver.usermanager.BaseUser;
 import org.apache.ftpserver.util.IoUtils;
 
-public class NativeFileSystemViewTest extends TestCase {
+public class NativeFileSystemViewTest extends FileSystemViewTemplate {
 
     private static final File TEST_TMP_DIR = new File("test-tmp");
 
-    protected static final File ROOT_DIR = new File(TEST_TMP_DIR, "ftproot");
-
-    private static final File TEST_DIR1 = new File(ROOT_DIR, "dir1");
-
-    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 String ROOT_DIR_PATH = ROOT_DIR.getAbsolutePath()
-            .replace('\\', '/');
+    private static final File ROOT_DIR = new File(TEST_TMP_DIR, "ftproot");
 
-    private static final String FULL_PATH = ROOT_DIR_PATH + "/"
-            + TEST_DIR1.getName() + "/" + TEST_FILE2_IN_DIR1.getName();
+    private static final File TEST_DIR1 = new File(ROOT_DIR, DIR1_NAME);
 
-    private static final String FULL_PATH_NO_CURRDIR = ROOT_DIR_PATH + "/"
-            + TEST_FILE2_IN_DIR1.getName();
-
-    private BaseUser user;
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see junit.framework.TestCase#setUp()
-     */
     protected void setUp() throws Exception {
         initDirs();
 
         TEST_DIR1.mkdirs();
-        TEST_FILE1.createNewFile();
-        TEST_FILE2_IN_DIR1.createNewFile();
 
-        user = new BaseUser();
         user.setHomeDirectory(ROOT_DIR.getAbsolutePath());
     }
 
@@ -72,42 +46,7 @@
         assertEquals("/", view.getCurrentDirectory().getFullName());
     }
     
-    public void testChangeDirectory() throws Exception {
-        NativeFileSystemView view = new NativeFileSystemView(user);
-        assertEquals("/", view.getCurrentDirectory().getFullName());
 
-        assertTrue(view.changeDirectory(TEST_DIR1.getName()));
-        assertEquals("/" + TEST_DIR1.getName(), view.getCurrentDirectory().getFullName());
-        
-        assertTrue(view.changeDirectory("."));
-        assertEquals("/" + TEST_DIR1.getName(), view.getCurrentDirectory().getFullName());
-
-        assertTrue(view.changeDirectory(".."));
-        assertEquals("/", view.getCurrentDirectory().getFullName());
-
-        assertTrue(view.changeDirectory("./" + TEST_DIR1.getName()));
-        assertEquals("/" + TEST_DIR1.getName(), view.getCurrentDirectory().getFullName());
-
-        assertTrue(view.changeDirectory("~"));
-        assertEquals("/", view.getCurrentDirectory().getFullName());
-    }
-
-    public void testChangeDirectoryCaseInsensitive() throws Exception {
-        NativeFileSystemView view = new NativeFileSystemView(user, true);
-        assertEquals("/", view.getCurrentDirectory().getFullName());
-        
-        assertTrue(view.changeDirectory("/DIR1"));
-        assertEquals("/dir1", view.getCurrentDirectory().getFullName());
-        assertTrue(view.getCurrentDirectory().doesExist());
-        
-        assertTrue(view.changeDirectory("/dir1"));
-        assertEquals("/dir1", view.getCurrentDirectory().getFullName());
-        assertTrue(view.getCurrentDirectory().doesExist());
-
-        assertTrue(view.changeDirectory("/DiR1"));
-        assertEquals("/dir1", view.getCurrentDirectory().getFullName());
-        assertTrue(view.getCurrentDirectory().doesExist());
-    }
 
     public void testConstructorWithNullUser() throws FtpException {
         try{

Modified: incubator/ftpserver/trunk/ftplet-api/src/java/org/apache/ftpserver/ftplet/FileObject.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/ftplet-api/src/java/org/apache/ftpserver/ftplet/FileObject.java?view=diff&rev=565040&r1=565039&r2=565040
==============================================================================
--- incubator/ftpserver/trunk/ftplet-api/src/java/org/apache/ftpserver/ftplet/FileObject.java
(original)
+++ incubator/ftpserver/trunk/ftplet-api/src/java/org/apache/ftpserver/ftplet/FileObject.java
Sun Aug 12 05:11:32 2007
@@ -117,6 +117,7 @@
     /**
      * List file objects. If not a directory or does not exist,
      * null will be returned.
+     * Files must be returned in alphabetical order.
      */
     FileObject[] listFiles();
     



Mime
View raw message