jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r585438 - in /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs: AbstractFileSystemTest.java mem/MemoryFileSystemTest.java
Date Wed, 17 Oct 2007 10:33:00 GMT
Author: jukka
Date: Wed Oct 17 03:32:46 2007
New Revision: 585438

URL: http://svn.apache.org/viewvc?rev=585438&view=rev
Log:
JCR-1175: Test cases for all FileSystem implementations
    - Extracted generic tests from MemoryFileSystemTest to AbstractFileSystemTest

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java
      - copied, changed from r585163, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystemTest.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystemTest.java

Copied: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java
(from r585163, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystemTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java?p2=jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java&p1=jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystemTest.java&r1=585163&r2=585438&rev=585438&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystemTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java
Wed Oct 17 03:32:46 2007
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.core.fs.mem;
+package org.apache.jackrabbit.core.fs;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -26,18 +26,22 @@
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemException;
 
-public class MemoryFileSystemTest extends TestCase {
+public abstract class AbstractFileSystemTest extends TestCase {
 
     private FileSystem fs;
-    private byte[] sampleBytes;
+    private byte[] sampleBytes = new byte[]{(byte)0x12, (byte)0x0F, (byte)0xF0};
+
+    protected abstract FileSystem getFileSystem() throws Exception;
 
     protected void setUp() throws Exception {
-        super.setUp();
-        sampleBytes = new byte[]{(byte)0x12, (byte)0x0F, (byte)0xF0};
-        fs = new MemoryFileSystem();
+        fs = getFileSystem();
         fs.init();
     }
 
+    protected void tearDown() throws FileSystemException {
+        fs.close();
+    }
+
     public void testIsFolder() throws Exception {
         assertTrue(fs.isFolder("/"));
     }
@@ -169,8 +173,6 @@
         entries = fs.listFiles("/folder");
         assertEquals(1, entries.length);
         assertEquals(entries[0], "/folder/file");
-
-
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystemTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystemTest.java?rev=585438&r1=585437&r2=585438&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystemTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystemTest.java
Wed Oct 17 03:32:46 2007
@@ -16,161 +16,13 @@
  */
 package org.apache.jackrabbit.core.fs.mem;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
+import org.apache.jackrabbit.core.fs.AbstractFileSystemTest;
 import org.apache.jackrabbit.core.fs.FileSystem;
-import org.apache.jackrabbit.core.fs.FileSystemException;
-
-public class MemoryFileSystemTest extends TestCase {
-
-    private FileSystem fs;
-    private byte[] sampleBytes;
-
-    protected void setUp() throws Exception {
-        super.setUp();
-        sampleBytes = new byte[]{(byte)0x12, (byte)0x0F, (byte)0xF0};
-        fs = new MemoryFileSystem();
-        fs.init();
-    }
-
-    public void testIsFolder() throws Exception {
-        assertTrue(fs.isFolder("/"));
-    }
-
-    public void testCreateFile() throws Exception {
-        fs.createFolder("/folder");
-        createFile("/folder/file", sampleBytes);
-        assertTrue(fs.isFile("/folder/file"));
-    }
-
-    public void testCreateFileInNonExistentFolder() throws IOException {
-        try {
-            createFile("/folder/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);
-    }
-
-    private void verifyStreamInput(InputStream inputStream, byte[] expectedBytes) throws
IOException {
-        byte[] resultBytes = new byte[3];
-        inputStream.read(resultBytes);
-        inputStream.close();
-
-        assertEquals(expectedBytes[0], resultBytes[0]);
-        assertEquals(expectedBytes[1], resultBytes[1]);
-        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
{
-        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");
-            fail("FileSystemException expected");
-        } catch (FileSystemException e) {
-            // ok
-        }
-    }
-
-    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);
-        assertEquals(entries[0], "/file");
-        assertEquals(entries[1], "/folder");
-
-        entries = fs.list("/folder");
-        assertEquals(2, entries.length);
-        Arrays.sort(entries);
-        assertEquals(entries[0], "/folder/file");
-        assertEquals(entries[1], "/folder/subfolder");
-
-        entries = fs.listFiles("/folder");
-        assertEquals(1, entries.length);
-        assertEquals(entries[0], "/folder/file");
 
+public class MemoryFileSystemTest extends AbstractFileSystemTest {
 
+    protected FileSystem getFileSystem() {
+        return new MemoryFileSystem();
     }
 
 }



Mime
View raw message