1 19 20 package org.openide.loaders; 21 22 import junit.framework.AssertionFailedError; 23 import org.netbeans.junit.NbTestCase; 24 import org.openide.filesystems.FileAttributeEvent; 25 import org.openide.filesystems.FileChangeListener; 26 import org.openide.filesystems.FileEvent; 27 import org.openide.filesystems.FileObject; 28 import org.openide.filesystems.FileRenameEvent; 29 import org.openide.filesystems.FileSystem; 30 import org.openide.filesystems.FileUtil; 31 import org.openide.filesystems.Repository; 32 import org.openide.nodes.Node; 33 import org.openide.util.RequestProcessor; 34 35 40 public class Deadlock51637Test extends NbTestCase implements FileChangeListener { 41 FileObject toolbars; 42 FileSystem fs; 43 DataFolder toolbarsFolder; 44 DataFolder anotherFolder; 45 DataObject obj; 46 47 Node node; 48 Exception assigned; 49 boolean called; 50 boolean enough; 51 52 public Deadlock51637Test(String testName) { 53 super (testName); 54 } 55 56 protected void setUp() throws Exception { 57 fs = Repository.getDefault ().getDefaultFileSystem (); 58 FileObject root = fs.getRoot (); 59 toolbars = FileUtil.createFolder (root, "Toolbars"); 60 toolbarsFolder = DataFolder.findFolder (toolbars); 61 FileObject[] arr = toolbars.getChildren (); 62 for (int i = 0; i < arr.length; i++) { 63 arr[i].delete (); 64 } 65 FileObject fo = FileUtil.createData (root, "Ahoj.txt"); 66 obj = DataObject.find (fo); 67 fo = FileUtil.createFolder (root, "Another"); 68 anotherFolder = DataFolder.findFolder (fo); 69 70 fs.addFileChangeListener (this); 71 } 72 73 protected void tearDown() throws Exception { 74 fs.removeFileChangeListener (this); 75 76 assertTrue ("The doCreateNode must be called", called); 77 78 FileObject[] arr = toolbars.getChildren (); 79 for (int i = 0; i < arr.length; i++) { 80 arr[i].delete (); 81 } 82 83 } 84 85 private void doCreateNode () { 86 if (enough) { 87 return; 88 } 89 if (node != null) { 90 assertNotNull ("Node is not null, but it was not assigned", assigned); 91 92 AssertionFailedError a = new AssertionFailedError ("Node cannot be null"); 93 a.initCause (assigned); 94 throw a; 95 } 96 enough = true; 98 fs.removeFileChangeListener (this); 99 100 called = true; 101 102 boolean ok; 103 try { 104 final Exception now = new Exception ("Calling to rp"); 105 ok = RequestProcessor.getDefault ().post (new Runnable () { 106 public void run () { 107 node = obj.getNodeDelegate (); 108 109 assigned = new Exception ("Created in RP"); 110 assigned.initCause (now); 111 } 112 }).waitFinished (100000); 113 } catch (InterruptedException ex) { 114 AssertionFailedError a = new AssertionFailedError (ex.getMessage ()); 115 a.initCause (ex); 116 throw a; 117 } 118 119 if (node == null) { 120 fail ("Node is still null and the waitFinished was " + ok); 121 } 122 } 123 124 125 public void testMove () throws Exception { 126 obj.move (anotherFolder); 127 } 128 129 public void testCopy () throws Exception { 130 obj.copy (anotherFolder); 131 } 132 133 public void testRename () throws Exception { 134 obj.rename ("NewName.txt"); 135 } 136 137 public void testCreateShadow () throws Exception { 138 obj.createShadow (anotherFolder); 139 } 140 141 public void testTemplate () throws Exception { 142 obj.createFromTemplate (anotherFolder); 143 } 144 145 public void testTemplate2 () throws Exception { 146 obj.createFromTemplate (anotherFolder, "AhojVole.txt"); 147 } 148 149 153 public void fileRenamed (FileRenameEvent fe) { 154 doCreateNode (); 155 } 156 157 public void fileAttributeChanged (FileAttributeEvent fe) { 158 } 159 160 public void fileFolderCreated (FileEvent fe) { 161 doCreateNode (); 162 } 163 164 public void fileDeleted (FileEvent fe) { 165 doCreateNode (); 166 } 167 168 public void fileDataCreated (FileEvent fe) { 169 doCreateNode (); 170 } 171 172 public void fileChanged (FileEvent fe) { 173 doCreateNode (); 174 } 175 176 } 177 | Popular Tags |