| 1 | |
package org.webslinger.commons.vfs.tests; |
| 2 | |
|
| 3 | |
import org.apache.commons.vfs.FileObject; |
| 4 | |
import org.apache.commons.vfs.FileSystem; |
| 5 | |
|
| 6 | |
import org.webslinger.commons.vfs.operations.SymlinkOperation; |
| 7 | |
|
| 8 | |
public class SymlinkTester extends OperationTester<SymlinkOperation> { |
| 9 | |
public SymlinkTester(FileObject root) { |
| 10 | 1 | super(root, SymlinkOperation.class); |
| 11 | 1 | } |
| 12 | |
|
| 13 | |
public void doTest() throws Exception { |
| 14 | 1 | FileSystem fs = root.getFileSystem(); |
| 15 | 1 | getOperation(fs, "symlinks/filelink1").setSymlink("../files/sourcefile1"); |
| 16 | 1 | getOperation(fs, "symlinks/filelink2").setSymlink("filelink1"); |
| 17 | 1 | FileObject[] children = root.resolveFile("symlinks").getChildren(); |
| 18 | 1 | assertNotNull("getChildren is not null", children); |
| 19 | 1 | assertEquals("child count in symlinks", 2, children.length); |
| 20 | 3 | for (FileObject child: children) { |
| 21 | 2 | String baseName = child.getName().getBaseName(); |
| 22 | 2 | if (baseName.equals("filelink1")) { |
| 23 | 1 | } else if (baseName.equals("filelink2")) { |
| 24 | |
} else { |
| 25 | 0 | fail("Unknown child in list(" + baseName + ")"); |
| 26 | |
} |
| 27 | |
} |
| 28 | 1 | assertFalse("filelink1 does not exist", root.resolveFile("symlinks/filelink1").exists()); |
| 29 | 1 | assertFalse("filelink2 does not exist", root.resolveFile("symlinks/filelink2").exists()); |
| 30 | 1 | TestUtil.writeString(root.resolveFile("files/sourcefile1"), "sourcefile1 content"); |
| 31 | 1 | TestUtil.writeString(root.resolveFile("files/sourcefile2"), "sourcefile2 content"); |
| 32 | 1 | root.resolveFile("symlinks/filelink1").refresh(); |
| 33 | 1 | assertTrue("filelink1 exists", root.resolveFile("symlinks/filelink1").exists()); |
| 34 | 1 | root.resolveFile("symlinks/filelink2").refresh(); |
| 35 | 1 | assertTrue("filelink1 exists", root.resolveFile("symlinks/filelink2").exists()); |
| 36 | 1 | assertEquals("filelink1 content", "sourcefile1 content", TestUtil.readString(root.resolveFile("symlinks/filelink1"))); |
| 37 | 1 | assertEquals("filelink2 content", "sourcefile1 content", TestUtil.readString(root.resolveFile("symlinks/filelink2"))); |
| 38 | 1 | getOperation(fs, "symlinks/filelink2").setSymlink("../files/sourcefile2"); |
| 39 | 1 | assertEquals("filelink1 content", "sourcefile1 content", TestUtil.readString(root.resolveFile("symlinks/filelink1"))); |
| 40 | 1 | assertEquals("filelink2 content", "sourcefile2 content", TestUtil.readString(root.resolveFile("symlinks/filelink2"))); |
| 41 | 1 | getOperation(fs, "symlinks/filelink1").setSymlink(null); |
| 42 | 1 | assertFalse("filelink1 does not exist", root.resolveFile("symlinks/filelink1").exists()); |
| 43 | 1 | children = root.resolveFile("symlinks").getChildren(); |
| 44 | 1 | assertNotNull("getChildren is not null", children); |
| 45 | 1 | assertEquals("child count in symlinks", 1, children.length); |
| 46 | 1 | assertEquals("only child is filelink2", "filelink2", children[0].getName().getBaseName()); |
| 47 | 1 | } |
| 48 | |
} |