| 1 | |
package org.webslinger.commons.vfs.tests; |
| 2 | |
|
| 3 | |
import org.webslinger.httpunit.WebslingerTestCase; |
| 4 | |
|
| 5 | |
import java.io.File; |
| 6 | |
|
| 7 | |
import org.apache.commons.vfs.FileObject; |
| 8 | |
import org.apache.commons.vfs.FileSystemOptions; |
| 9 | |
import org.apache.commons.vfs.Selectors; |
| 10 | |
import org.apache.commons.vfs.impl.StandardFileSystemManager; |
| 11 | |
|
| 12 | |
import org.webslinger.containers.TestContainer; |
| 13 | |
import org.webslinger.commons.vfs.VFSUtil; |
| 14 | |
import org.webslinger.commons.vfs.operations.COWStateOperation; |
| 15 | |
import org.webslinger.io.IOUtil; |
| 16 | |
|
| 17 | |
public class TestChildren extends TestContainer.TestContainerTestCase { |
| 18 | |
protected StandardFileSystemManager sfsm; |
| 19 | |
protected FileObject root; |
| 20 | |
|
| 21 | |
public TestChildren(String name) { |
| 22 | 6 | super(name); |
| 23 | 6 | } |
| 24 | |
|
| 25 | |
protected void setUp() throws Exception { |
| 26 | 6 | super.setUp(); |
| 27 | 6 | sfsm = VFSUtil.createStandardFileSystemManager(); |
| 28 | 6 | root = sfsm.createVirtualFileSystem(VFSUtil.toFileObject(sfsm, getBase(), new FileSystemOptions())); |
| 29 | 6 | root.delete(Selectors.SELECT_ALL); |
| 30 | 6 | root.createFolder(); |
| 31 | 6 | } |
| 32 | |
|
| 33 | |
protected void tearDown() throws Exception { |
| 34 | |
try { |
| 35 | 6 | root.delete(Selectors.SELECT_ALL); |
| 36 | 0 | } catch (Exception e) { |
| 37 | 6 | } |
| 38 | 6 | super.tearDown(); |
| 39 | 6 | } |
| 40 | |
|
| 41 | |
protected void doTest(String label, FileObject root, FileObject top) throws Exception { |
| 42 | 4 | doTest(new File(getBase(), "one"), label, root, top); |
| 43 | 4 | } |
| 44 | |
|
| 45 | |
protected void doTest(File oneFile, String label, FileObject root, FileObject top) throws Exception { |
| 46 | 6 | assertEquals(label + "(root): children count", 0, root.getChildren().length); |
| 47 | 6 | assertEquals(label + "(top): children count", 0, top.getChildren().length); |
| 48 | 6 | IOUtil.touch(oneFile); |
| 49 | 6 | assertEquals(label + "(root): children count", 0, root.getChildren().length); |
| 50 | 6 | assertEquals(label + "(top): children count", 0, top.getChildren().length); |
| 51 | 6 | root.refresh(); |
| 52 | 6 | assertEquals(label + "(root): children count", 1, root.getChildren().length); |
| 53 | 6 | assertEquals(label + "(top): children count", 0, top.getChildren().length); |
| 54 | 6 | top.refresh(); |
| 55 | 6 | assertEquals(label + "(root): children count", 1, root.getChildren().length); |
| 56 | 6 | assertEquals(label + "(top): children count", 1, top.getChildren().length); |
| 57 | 6 | oneFile.delete(); |
| 58 | 6 | assertEquals(label + "(root): children count", 1, root.getChildren().length); |
| 59 | 6 | assertEquals(label + "(top): children count", 1, top.getChildren().length); |
| 60 | 6 | root.refresh(); |
| 61 | 6 | assertEquals(label + "(root): children count", 0, root.getChildren().length); |
| 62 | 6 | assertEquals(label + "(top): children count", 1, top.getChildren().length); |
| 63 | 6 | top.refresh(); |
| 64 | 6 | assertEquals(label + "(root): children count", 0, root.getChildren().length); |
| 65 | 6 | assertEquals(label + "(top): children count", 0, top.getChildren().length); |
| 66 | 6 | IOUtil.touch(oneFile); |
| 67 | 6 | assertEquals(label + "(root): children count", 0, root.getChildren().length); |
| 68 | 6 | assertEquals(label + "(top): children count", 0, top.getChildren().length); |
| 69 | 6 | top.refresh(); |
| 70 | 6 | assertEquals(label + "(top): children count", 1, top.getChildren().length); |
| 71 | 6 | assertEquals(label + "(root): children count", 1, root.getChildren().length); |
| 72 | 6 | oneFile.delete(); |
| 73 | 6 | assertEquals(label + "(top): children count", 1, top.getChildren().length); |
| 74 | 6 | assertEquals(label + "(root): children count", 1, root.getChildren().length); |
| 75 | 6 | top.refresh(); |
| 76 | 6 | assertEquals(label + "(top): children count", 0, top.getChildren().length); |
| 77 | 6 | assertEquals(label + "(root): children count", 0, root.getChildren().length); |
| 78 | 6 | } |
| 79 | |
|
| 80 | |
public void doCowTest(String name) throws Exception { |
| 81 | 2 | root.resolveFile("folder").createFolder(); |
| 82 | 2 | root.resolveFile("view").createFolder(); |
| 83 | 2 | FileObject fo = sfsm.createFileSystem(name, root).resolveFile("view"); |
| 84 | 2 | VFSUtil.getOperation(fo, COWStateOperation.class).addBase("../folder"); |
| 85 | 2 | doTest(new File(new File(getBase(), "folder"), "oneFile"), "cow", root.resolveFile("folder"), fo); |
| 86 | 2 | } |
| 87 | |
|
| 88 | |
public void testCowSimple() throws Exception { |
| 89 | 1 | doTest("cow", root, sfsm.createFileSystem("cow", root)); |
| 90 | 1 | } |
| 91 | |
|
| 92 | |
public void testCowComplex() throws Exception { |
| 93 | 1 | doCowTest("cow"); |
| 94 | 1 | } |
| 95 | |
|
| 96 | |
public void testFlat() throws Exception { |
| 97 | 1 | doTest("flat", root, sfsm.createFileSystem("flat", root)); |
| 98 | 1 | } |
| 99 | |
|
| 100 | |
public void testWsvfs() throws Exception { |
| 101 | 1 | doTest("wsvfs", root, sfsm.createFileSystem("wsvfs", root)); |
| 102 | 1 | } |
| 103 | |
|
| 104 | |
public void testWsvfsComplex() throws Exception { |
| 105 | 1 | doCowTest("wsvfs"); |
| 106 | 1 | } |
| 107 | |
|
| 108 | |
public void testVfs() throws Exception { |
| 109 | 1 | doTest("vfs", root, sfsm.createVirtualFileSystem(root)); |
| 110 | 1 | } |
| 111 | |
} |