1 19 20 package org.openide.filesystems; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyVetoException ; 24 import java.beans.VetoableChangeListener ; 25 import java.io.IOException ; 26 27 public class FileSystemTestHid extends TestBaseHid { 28 private FileObject root; 29 private static String [] resources = new String [] { 30 "atleastone" 31 }; 32 33 public FileSystemTestHid(String testName) { 34 super(testName); 35 } 36 private static int abacus = 0; 37 38 39 protected String [] getResources (String testName) { 40 return resources; 41 } 42 public void testAddFileStatusListener () { 43 if (!(this.testedFS instanceof TestUtilHid.StatusFileSystem)) 44 return; 45 FileStatusListener[] fsListeners = new FileStatusListener [10]; 46 abacus = 0; 47 48 for (int i = 0; i < fsListeners.length; i++) { 49 fsListeners[i] = createFileStatusListener (); 50 this.testedFS.addFileStatusListener(fsListeners[i]); 51 } 52 this.testedFS.fireFileStatusChanged(new FileStatusEvent (this.testedFS, true, true) ); 53 fsAssert("failure: not all FileStstausListeners invoked: " + abacus, abacus == fsListeners.length); 54 55 abacus = 0; 56 this.testedFS.removeFileStatusListener(fsListeners[0]); 57 this.testedFS.fireFileStatusChanged(new FileStatusEvent (this.testedFS, true, true) ); 58 fsAssert("failure: not all FileStstausListeners invoked", abacus == (fsListeners.length -1)); 59 } 60 61 62 public void testAddVetoableChangeListener () { 63 VetoableChangeListener [] vListeners = new VetoableChangeListener [10]; 64 abacus = 0; 65 66 for (int i = 0; i < vListeners.length; i++) { 67 vListeners[i] = createVetoableChangeListener (); 68 this.testedFS.addVetoableChangeListener(vListeners[i]); 69 } 70 try { 71 this.testedFS.fireVetoableChange("test", "old", "new"); 72 } catch (PropertyVetoException pex) { 73 fsFail("unexpected veto exception"); 74 } 75 fsAssert("failure: not all VetoableChangeListeners invoked", abacus == vListeners.length); 76 77 abacus = 0; 78 this.testedFS.removeVetoableChangeListener(vListeners[0]); 79 try { 80 this.testedFS.fireVetoableChange("test", "old", "new"); 81 } catch (PropertyVetoException pex) { 82 fsFail("unexpected veto exception"); 83 } 84 fsAssert("failure: not all VetoableChangeListeners invoked", abacus == (vListeners.length -1)); 85 } 86 87 private FileStatusListener createFileStatusListener () { 88 return new FileStatusListener () { 89 public void annotationChanged (FileStatusEvent ev) { 90 abacus++; 91 } 92 }; 93 94 } 95 96 private VetoableChangeListener createVetoableChangeListener () { 97 return new VetoableChangeListener () { 98 public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException { 99 abacus++; 100 } 101 }; 102 103 } 104 105 public void testFsfileFolderCreated() throws IOException { 106 FileSystem fs = this.testedFS; 107 if (!fs.isReadOnly () && !root.isReadOnly()) { 108 root.getChildren(); 109 registerDefaultListener (fs); 110 root.createFolder("testtset"); 111 fileFolderCreatedAssert ("unexpecetd event count",1); 112 } 113 } 114 115 public void testFsfileDataCreated() throws IOException { 116 FileSystem fs = this.testedFS; 117 if (!fs.isReadOnly () && !root.isReadOnly()) { 118 root.getChildren(); 119 registerDefaultListener (fs); 120 FileObject newF = root.createData("testfile","txe"); 121 fileDataCreatedAssert ("unexpecetd event count",1); 122 } 123 124 } 125 126 public void testFsfileRenamed() throws IOException { 127 FileSystem fs = this.testedFS; 128 if (!fs.isReadOnly () && !root.isReadOnly()) { 129 root.getChildren(); 130 registerDefaultListener (fs); 131 FileObject newF = root.createData("testfile","txe"); 132 FileLock fLock = newF.lock(); 133 try { 134 newF.rename(fLock,"obscure","uni"); 135 } finally { 136 fLock.releaseLock(); 137 } 138 139 fileRenamedAssert("unexpecetd event count",1); 140 } 141 142 } 143 144 public void testFsfileDeleted() throws IOException { 145 FileSystem fs = this.testedFS; 146 if (!fs.isReadOnly () && !root.isReadOnly()) { 147 root.getChildren(); 148 registerDefaultListener (fs); 149 FileObject newF = root.createData("testfile","txe"); 150 FileLock fLock = newF.lock(); 151 try { 152 newF.delete(fLock); 153 } finally { 154 fLock.releaseLock(); 155 } 156 157 fileDeletedAssert("unexpecetd event count",1); 158 } 159 160 } 161 162 163 public void testIsValid() { 164 Repository r = new Repository(new LocalFileSystem ()); 165 fsAssert("file system, which is not assigned to the repository, should be invalid", 167 !testedFS.isValid()); 168 169 r.addFileSystem(testedFS); 171 if (!testedFS.getSystemName().equals("")) 172 fsAssert("assign to empty repository -> become valid" , testedFS.isValid()); 173 174 r.removeFileSystem(testedFS); 176 fsAssert("remove from repo -> become invalid", !testedFS.isValid()); 177 } 178 179 protected void setUp() throws Exception { 180 super.setUp(); 181 root = testedFS.findResource(getResourcePrefix()); 182 } 183 184 } 185 | Popular Tags |