Coverage Report - org.webslinger.commons.vfs.tests.TestWsvfs
 
Classes in this File Line Coverage Branch Coverage Complexity
TestWsvfs
98%
41/42
100%
4/4
0
 
 1  
 package org.webslinger.commons.vfs.tests;
 2  
 
 3  
 import org.webslinger.httpunit.WebslingerTestCase;
 4  
 
 5  
 import java.io.EOFException;
 6  
 import java.io.File;
 7  
 import java.io.IOException;
 8  
 import java.io.OutputStream;
 9  
 
 10  
 import org.apache.commons.vfs.FileObject;
 11  
 import org.apache.commons.vfs.RandomAccessContent;
 12  
 import org.apache.commons.vfs.Selectors;
 13  
 import org.apache.commons.vfs.impl.StandardFileSystemManager;
 14  
 import org.apache.commons.vfs.util.RandomAccessMode;
 15  
 
 16  
 import org.webslinger.containers.TestContainer;
 17  
 import org.webslinger.commons.vfs.VFSUtil;
 18  
 import org.webslinger.commons.vfs.virtual.VirtualFileSystem;
 19  
 import org.webslinger.io.IOUtil;
 20  
 import static org.webslinger.commons.vfs.tests.TestUtil.checkContent;
 21  
 
 22  
 public class TestWsvfs extends TestContainer.TestContainerTestCase {
 23  
     protected StandardFileSystemManager sfsm;
 24  
     protected FileObject root;
 25  
     public TestWsvfs(String name) {
 26  1
         super(name);
 27  1
     }
 28  
 
 29  
     protected void setUp() throws Exception {
 30  1
         super.setUp();
 31  1
         sfsm = VFSUtil.createStandardFileSystemManager();
 32  1
         sfsm.setBaseFile(new File(getTestLocation(), getName()));
 33  1
         root = sfsm.createVirtualFileSystem(sfsm.resolveFile("."));
 34  1
         root.delete(Selectors.SELECT_ALL);
 35  1
     }
 36  
 
 37  
     protected void tearDown() throws Exception {
 38  1
         root.delete(Selectors.SELECT_ALL);
 39  1
         super.tearDown();
 40  1
     }
 41  
 
 42  
     public void testJunctions() throws Exception {
 43  1
         VirtualFileSystem vfs = (VirtualFileSystem) sfsm.createFileSystem("wsvfs", root.resolveFile("virtual")).getFileSystem();
 44  1
         FileObject top = vfs.getRoot();
 45  1
         VFSUtil.setString(root, "real/dir1/file1", "abc");
 46  1
         VFSUtil.setString(root, "real/dir2/file2", "123");
 47  1
         VFSUtil.setString(root, "real/dir3/file3", "fiddleumdeedee");
 48  1
         VFSUtil.setString(root, "virtual/dir1/file4", "don'tever");
 49  1
         VFSUtil.setString(root, "virtual/dir2/file5", "sitona");
 50  1
         VFSUtil.setString(root, "virtual/dir3/file6", "woodpecker'sknee");
 51  1
         vfs.addJunction("dir1/file1", root.resolveFile("/real/dir1/file1"));
 52  1
         VFSUtil.tree(top, System.err);
 53  1
         checkContent("dir1/file1(resolve)", vfs.resolveFile("/dir1/file1"), null, "abc", true);
 54  1
         checkContent("dir1/file4(resolve)", vfs.resolveFile("/dir1/file4"), null, "don'tever", true);
 55  1
         assertTrue("dir1 has children", vfs.resolveFile("/dir1").getType().hasChildren());
 56  1
         FileObject[] children = vfs.resolveFile("/dir1").getChildren();
 57  1
         assertTrue("dir1 getChildren not null", children != null);
 58  1
         boolean foundFile1 = false, foundFile4 = false;
 59  3
         for (FileObject child: children) {
 60  2
             String name = child.getName().getBaseName();
 61  2
             if (name.equals("file1")) {
 62  1
                 foundFile1 = true;
 63  1
                 checkContent("dir1/file1(getChildren)", child, null, "abc", true);
 64  1
             } else if (name.equals("file4")) {
 65  1
                 foundFile4 = true;
 66  1
                 checkContent("dir1/file4(getChildren)", child, null, "don'tever", true);
 67  
             } else {
 68  0
                 fail("Found extra child in dir1(" + name + ")");
 69  
             }
 70  
         }
 71  1
         assertTrue("dir1 getChildren contains file1", foundFile1);
 72  1
         assertTrue("dir1 getChildren contains file4", foundFile4);
 73  1
         vfs.removeJunction("/dir1/file1");
 74  1
         checkContent("dir1/file4(resolve)", vfs.resolveFile("/dir1/file4"), null, "don'tever", true);
 75  1
         assertFalse("dir1/file1 does not exist after removeJunction", vfs.resolveFile("/dir1/file1").exists());
 76  1
     }
 77  
 }