1 19 package org.netbeans.modules.turbo.keys; 20 21 import junit.framework.TestCase; 22 import org.openide.filesystems.FileObject; 23 import org.openide.filesystems.LocalFileSystem; 24 import org.openide.filesystems.FileUtil; 25 import org.openide.filesystems.FileSystem; 26 import org.netbeans.modules.turbo.Turbo; 27 28 import java.io.File ; 29 30 35 public class DiskFileKeyTest extends TestCase { 36 37 private FileSystem fs; 38 39 protected void setUp() throws Exception { 41 42 44 LocalFileSystem fs = new LocalFileSystem(); 45 File tmp = new File (System.getProperty("java.io.tmpdir") + File.separator + "turbo-test"); 46 tmp.mkdir(); 47 tmp.deleteOnExit(); 48 File theFile = new File (tmp, "theFile"); 49 theFile.createNewFile(); 50 theFile.deleteOnExit(); 51 fs.setRootDirectory(tmp); 52 53 this.fs = fs; 54 } 55 56 57 58 public void testMemoryKeys() throws Exception { 59 FileObject overlap = fs.getRoot().createFolder("nestedFS2"); 60 try { 61 LocalFileSystem ofs = new LocalFileSystem(); 62 ofs.setRootDirectory(FileUtil.toFile(overlap)); 63 64 ofs.getRoot().createData("data.txt"); 65 66 FileObject f1 = fs.findResource("nestedFS2/data.txt"); 67 FileObject f2 = ofs.findResource("data.txt"); 68 69 DiskFileKey k1 = DiskFileKey.createKey(f1); 70 DiskFileKey k2 = DiskFileKey.createKey(f2); 71 72 assertTrue(k1.equals(k2)); 73 74 } finally { 75 overlap.delete(overlap.lock()); 76 } 77 } 78 79 88 public void testDuplicatedFileObject() throws Exception { 89 FileObject overlap = fs.getRoot().createFolder("nestedFS"); 90 try { 91 LocalFileSystem ofs = new LocalFileSystem(); 92 ofs.setRootDirectory(FileUtil.toFile(overlap)); 93 94 ofs.getRoot().createData("data.txt"); 95 96 FileObject f1 = fs.findResource("nestedFS/data.txt"); 97 FileObject f2 = ofs.findResource("data.txt"); 98 assert f1 != f2; 99 assert f1.equals(f2) == false; 100 Object k1 = DiskFileKey.createKey(f1); 101 Object k2 = DiskFileKey.createKey(f2); 102 103 104 Turbo turbo = Turbo.getDefault(); 105 106 turbo.writeEntry(k1, "identity", "clash"); 107 Object v1 = turbo.readEntry(k1, "identity"); 108 Object v2 = turbo.readEntry(k2, "identity"); 109 110 assertTrue("clash".equals(v1)); 111 assertTrue("Unexpected value:" + v2, "clash".equals(v2)); 112 113 turbo.writeEntry(k2, "identity", "over!"); 114 115 v1 = turbo.readEntry(k1, "identity"); 116 v2 = turbo.readEntry(k2, "identity"); 117 118 assertTrue("over!".equals(v1)); 119 assertTrue("Unexpected value:" + v2, "over!".equals(v2)); 120 121 } finally { 122 overlap.delete(overlap.lock()); 123 } 124 } 125 126 } 127 | Popular Tags |