jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r585513 - /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java
Date Wed, 17 Oct 2007 14:09:19 GMT
Author: jukka
Date: Wed Oct 17 07:09:18 2007
New Revision: 585513

URL: http://svn.apache.org/viewvc?rev=585513&view=rev
Log:
JCR-1175: Test cases for all FileSystem implementations
    - Merged and extended all individual test methods into a single
      testEverything() method to avoid invoking the expensive setUp()
      and tearDown() calls too many times

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java?rev=585513&r1=585512&r2=585513&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java
Wed Oct 17 07:09:18 2007
@@ -42,34 +42,174 @@
         fs.close();
     }
 
-    public void testIsFolder() throws Exception {
+    public void testEverything() throws Exception {
+        String[] list;
+
+        // At beginning the file system should contain only the root folder
+        assertTrue(fs.exists("/"));
         assertTrue(fs.isFolder("/"));
-    }
+        assertFalse(fs.isFile("/"));
+        assertEquals(0, fs.list("/").length);
 
-    public void testCreateFile() throws Exception {
+        // Create a folder
         fs.createFolder("/folder");
+        assertTrue(fs.exists("/folder"));
+        assertTrue(fs.isFolder("/folder"));
+        assertFalse(fs.isFile("/folder"));
+        assertEquals(0, fs.list("/folder").length);
+        list = fs.list("/");
+        assertEquals(1, list.length);
+        assertEquals("folder", list[0]);
+
+        // Create a file inside the folder
         createFile("/folder/file", sampleBytes);
+        assertTrue(fs.exists("/folder/file"));
+        assertFalse(fs.isFolder("/folder/file"));
         assertTrue(fs.isFile("/folder/file"));
-    }
+        list = fs.list("/folder");
+        assertEquals(1, list.length);
+        assertEquals("file", list[0]);
+        assertEquals(3, fs.length("/folder/file"));
+        verifyStreamInput(fs.getInputStream("/folder/file"), sampleBytes);
+
+        // Copy the file
+        fs.copy("/folder/file", "/folder/file2");
+        assertTrue(fs.exists("/folder/file"));
+        assertFalse(fs.isFolder("/folder/file"));
+        assertTrue(fs.isFile("/folder/file"));
+        assertTrue(fs.exists("/folder/file2"));
+        assertFalse(fs.isFolder("/folder/file2"));
+        assertTrue(fs.isFile("/folder/file2"));
+        list = fs.list("/folder");
+        Arrays.sort(list);
+        assertEquals(2, list.length);
+        assertEquals("file", list[0]);
+        assertEquals("file2", list[1]);
+        assertEquals(3, fs.length("/folder/file2"));
+        verifyStreamInput(fs.getInputStream("/folder/file2"), sampleBytes);
+
+        // Delete the copy
+        fs.deleteFile("/folder/file2");
+        assertFalse(fs.exists("/folder/file2"));
+        assertFalse(fs.isFolder("/folder/file2"));
+        assertFalse(fs.isFile("/folder/file2"));
+        list = fs.list("/folder");
+        assertEquals(1, list.length);
+        assertEquals("file", list[0]);
+
+        // Move the file
+        fs.move("/folder/file", "/folder/file2");
+        assertFalse(fs.exists("/folder/file"));
+        assertFalse(fs.isFolder("/folder/file"));
+        assertFalse(fs.isFile("/folder/file"));
+        assertTrue(fs.exists("/folder/file2"));
+        assertFalse(fs.isFolder("/folder/file2"));
+        assertTrue(fs.isFile("/folder/file2"));
+        list = fs.list("/folder");
+        assertEquals(1, list.length);
+        assertEquals("file2", list[0]);
+        assertEquals(3, fs.length("/folder/file2"));
+        verifyStreamInput(fs.getInputStream("/folder/file2"), sampleBytes);
+
+        // Move the folder
+        fs.move("/folder", "/folder2");
+        assertFalse(fs.exists("/folder"));
+        assertFalse(fs.isFolder("/folder"));
+        assertFalse(fs.isFile("/folder"));
+        assertTrue(fs.exists("/folder2"));
+        assertTrue(fs.isFolder("/folder2"));
+        assertFalse(fs.isFile("/folder2"));
+        assertFalse(fs.exists("/folder/file2"));
+        assertFalse(fs.isFolder("/folder/file2"));
+        assertFalse(fs.isFile("/folder/file2"));
+        assertTrue(fs.exists("/folder2/file2"));
+        assertFalse(fs.isFolder("/folder2/file2"));
+        assertTrue(fs.isFile("/folder2/file2"));
+        list = fs.list("/");
+        assertEquals(1, list.length);
+        assertEquals("folder2", list[0]);
+        list = fs.list("/folder2");
+        assertEquals(1, list.length);
+        assertEquals("file2", list[0]);
+        assertEquals(3, fs.length("/folder2/file2"));
+        verifyStreamInput(fs.getInputStream("/folder2/file2"), sampleBytes);
+
+        // Create a subfolder
+        fs.createFolder("/folder2/subfolder");
+        assertTrue(fs.exists("/folder2/subfolder"));
+        assertTrue(fs.isFolder("/folder2/subfolder"));
+        assertFalse(fs.isFile("/folder2/subfolder"));
+        assertEquals(0, fs.list("/folder2/subfolder").length);
+        list = fs.list("/folder2");
+        Arrays.sort(list);
+        assertEquals(2, list.length);
+        assertEquals("file2", list[0]);
+        assertEquals("subfolder", list[1]);
+        list = fs.listFiles("/folder2");
+        assertEquals(1, list.length);
+        assertEquals("file2", list[0]);
+        list = fs.listFolders("/folder2");
+        assertEquals(1, list.length);
+        assertEquals("subfolder", list[0]);
+
+        // Delete the subfolder
+        fs.deleteFolder("/folder2/subfolder");
+        assertFalse(fs.exists("/folder2/subfolder"));
+        assertFalse(fs.isFolder("/folder2/subfolder"));
+        assertFalse(fs.isFile("/folder2/subfolder"));
+        list = fs.list("/folder2");
+        assertEquals(1, list.length);
+        assertEquals("file2", list[0]);
+        list = fs.listFiles("/folder2");
+        assertEquals(1, list.length);
+        assertEquals("file2", list[0]);
+        assertEquals(0, fs.listFolders("/folder2").length);
+
+        // Delete the folder
+        fs.deleteFolder("/folder2");
+        assertFalse(fs.exists("/folder2"));
+        assertFalse(fs.isFolder("/folder2"));
+        assertFalse(fs.isFile("/folder2"));
+        assertFalse(fs.exists("/folder2/file2"));
+        assertFalse(fs.isFolder("/folder2/file2"));
+        assertFalse(fs.isFile("/folder2/file2"));
+        assertEquals(0, fs.list("/").length);
+
+        // Test last modified time stamps
+        createFile("/file1", sampleBytes);
+        Thread.sleep(100);
+        createFile("/file2", sampleBytes);
+        assertTrue(fs.lastModified("/file1") <= fs.lastModified("/file2"));
+        Thread.sleep(100);
+        fs.touch("/file1");
+        assertTrue(fs.lastModified("/file1") >= fs.lastModified("/file2"));
 
-    public void testCreateFileInNonExistentFolder() throws IOException {
+        // Try to create a file inside a nonexistent folder
         try {
-            createFile("/folder/file", sampleBytes);
+            createFile("/missing/file", sampleBytes);
             fail("FileSystemException expected");
         } catch (FileSystemException e) {
             // ok
         }
-    }
 
-    public void testGetInputStream() throws Exception {
-        createFile("/test", sampleBytes);
-        InputStream inputStream = fs.getInputStream("/test");
-        verifyStreamInput(inputStream, sampleBytes);
+        // Try to create a folder inside a nonexistent folder
+        fs.createFolder("/missing/subfolder");
+        assertTrue(fs.exists("/missing"));
+        assertTrue(fs.isFolder("/missing"));
+        assertFalse(fs.isFile("/missing"));
+        assertTrue(fs.exists("/missing/subfolder"));
+        assertTrue(fs.isFolder("/missing/subfolder"));
+        assertFalse(fs.isFile("/missing/subfolder"));
+        assertEquals(0, fs.list("/missing/subfolder").length);
+        list = fs.list("/missing");
+        assertEquals(1, list.length);
+        assertEquals("subfolder", list[0]);
     }
 
-    private void verifyStreamInput(InputStream inputStream, byte[] expectedBytes) throws
IOException {
+    private void verifyStreamInput(
+            InputStream inputStream, byte[] expectedBytes) throws IOException {
         byte[] resultBytes = new byte[3];
-        inputStream.read(resultBytes);
+        assertEquals(3, inputStream.read(resultBytes));
         inputStream.close();
 
         assertEquals(expectedBytes[0], resultBytes[0]);
@@ -77,105 +217,11 @@
         assertEquals(expectedBytes[2], resultBytes[2]);
     }
 
-    public void testCopy() throws Exception {
-        createFile("/test", sampleBytes);
-        fs.copy("/test", "/test2");
-        assertTrue(fs.exists("/test2"));
-        verifyStreamInput(fs.getInputStream("/test2"), sampleBytes);
-    }
-
-    private void createFile(String fileName, byte[] bytes) throws IOException, FileSystemException
{
+    private void createFile(String fileName, byte[] bytes)
+            throws IOException, FileSystemException {
         OutputStream outputStream = fs.getOutputStream(fileName);
         outputStream.write(bytes);
         outputStream.close();
-    }
-
-    public void testDeleteFile() throws Exception {
-        createFile("/test", sampleBytes);
-        assertTrue(fs.exists("/test"));
-        fs.deleteFile("/test");
-        assertFalse(fs.exists("/test"));
-    }
-
-    public void testLength() throws Exception {
-        createFile("/test", sampleBytes);
-        assertEquals(3, fs.length("/test"));
-    }
-
-    public void testMove() throws Exception {
-        createFile("/test", sampleBytes);
-        fs.move("/test", "/test2");
-        assertFalse(fs.exists("/test"));
-        assertTrue(fs.exists("/test2"));
-        verifyStreamInput(fs.getInputStream("/test2"), sampleBytes);
-    }
-
-    public void testLastModified() throws Exception {
-        createFile("/test", sampleBytes);
-        long millis1 = fs.lastModified("/test");
-        // ensure time gap
-        Thread.sleep(100);
-        createFile("/test", sampleBytes);
-        long millis2 = fs.lastModified("/test");
-        assertTrue(millis1 < millis2);
-    }
-
-    public void testTouch() throws Exception {
-        createFile("/test", sampleBytes);
-        long millis1 = fs.lastModified("/test");
-        // ensure time gap
-        Thread.sleep(100);
-        fs.touch("/test");
-        long millis2 = fs.lastModified("/test");
-        assertTrue(millis1 < millis2);
-    }
-
-    public void testCreateAndDeleteFolder() throws Exception {
-        fs.createFolder("/folder");
-        assertTrue(fs.isFolder("/folder"));
-        fs.deleteFolder("/folder");
-        assertFalse(fs.exists("/folder"));
-    }
-
-    public void testDeleteNonEmptyFolder() throws Exception {
-        fs.createFolder("/folder/subfolder");
-        try {
-            fs.deleteFolder("/folder");
-            assertFalse(fs.exists("/folder"));
-            assertFalse(fs.exists("/folder/subfolder"));
-        } catch (FileSystemException e) {
-            fail("unexpected FileSystemException");
-        }
-    }
-
-    public void testCreateSubFolderWithInNonExistentFolder() throws Exception {
-        fs.createFolder("/folder/subfolder");
-        assertTrue(fs.isFolder("/folder"));
-        assertTrue(fs.isFolder("/folder/subfolder"));
-    }
-
-    public void testList() throws Exception {
-        fs.createFolder("/folder/subfolder");
-        fs.getOutputStream("/folder/file").close();
-        fs.getOutputStream("/file").close();
-
-        String[] entries = fs.list("/");
-        assertEquals(2, entries.length);
-        Arrays.sort(entries);
-        System.out.println(entries[0]);
-        System.out.println(entries[1]);
-        assertEquals(entries[0], "file");
-        assertEquals(entries[1], "folder");
-
-        entries = fs.list("/folder");
-        assertEquals(2, entries.length);
-        Arrays.sort(entries);
-        assertEquals(entries[0], "file");
-        assertEquals(entries[1], "subfolder");
-
-        entries = fs.listFiles("/folder");
-        assertEquals(1, entries.length);
-        assertEquals(entries[0], "file");
     }
 
 }



Mime
View raw message