1 19 20 package org.netbeans.modules.masterfs; 21 22 import java.beans.PropertyVetoException ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import junit.framework.Test; 26 import org.netbeans.junit.NbTestSuite; 27 import org.openide.filesystems.FileObjectTestHid; 28 import org.openide.filesystems.FileSystem; 29 import org.openide.filesystems.FileSystemTestHid; 30 import org.openide.filesystems.FileUtil; 31 import org.openide.filesystems.FileUtilTestHidden; 32 import org.openide.filesystems.LocalFileSystem; 33 import org.openide.filesystems.URLMapperTestHidden; 34 35 38 public class MasterFileSystemOnTopOfLocalFSTest extends MasterFileSystemTest { 39 private static LocalFileSystem rootFs; 40 41 public MasterFileSystemOnTopOfLocalFSTest(Test test) { 42 super(test); 43 } 44 45 public static void main(String args[]) { 46 junit.textui.TestRunner.run(suite()); 47 } 48 49 public static Test suite() { 50 NbTestSuite suite = new NbTestSuite(); 51 suite.addTestSuite(FileSystemTestHid.class); 52 suite.addTestSuite(FileObjectTestHid.class); 53 suite.addTestSuite(URLMapperTestHidden.class); 54 suite.addTestSuite(FileUtilTestHidden.class); 55 56 57 return new MasterFileSystemOnTopOfLocalFSTest(suite); 58 } 59 60 protected FileSystem[] createFileSystem(String testName, String [] resources) throws IOException { 61 FileSystem[] fss = super.createFileSystem(testName, resources); 62 if (rootFs == null) { 63 for (int i = 0; i < fss.length && fss[i] != null; i++) { 64 if (fss[i] instanceof MasterFileSystem) { 65 File rootFile = getRoot(new File (getResourcePrefix(testName, resources))); 66 rootFs = new LocalFileSystem(); 67 try { 68 rootFs.setRootDirectory(rootFile); 69 } catch (PropertyVetoException ex) { 70 IOException iex = new IOException (ex.getLocalizedMessage()); 71 iex.initCause(ex); 72 throw iex; 73 } 74 MountTable.getDefault().unmount(rootFile.getAbsolutePath()); 75 MountTable.getDefault().mount(rootFile.getAbsolutePath(), rootFs); 76 break; 77 } 78 } 79 80 } 81 return fss; 82 } 83 84 private static File getRoot(final File dir) { 85 File retval = dir; 86 for (; retval.getParentFile() != null; retval = retval.getParentFile()); 87 assert retval != null; 88 return retval; 89 } 90 } 91 | Popular Tags |