1 19 20 package org.openide.filesystems; 21 22 import java.io.File ; 23 import java.io.InputStream ; 24 import java.io.SyncFailedException ; 25 26 public class LocalFileSystemTestHid extends TestBaseHid { 27 private static String [] resources = new String [] { 28 "A/B/C.java", 29 "A/C/A" 30 }; 31 32 public LocalFileSystemTestHid (String testName) { 33 super(testName); 34 } 35 36 37 protected String [] getResources (String testName) { 38 return resources; 39 } 40 41 42 public void testExternalRemoveChildrenEvents () throws Exception { 43 FileObject fo = testedFS.findResource ("A/B/C.java"); 44 45 assertNotNull(fo); 46 47 if (!fo.isData ()) { 48 fail ("Not data"); 49 } 50 51 java.util.Date date = fo.lastModified (); 52 53 registerDefaultListener (fo); 54 55 assertNotNull (fo.getParent()); 56 57 java.io.File f = (java.io.File )fo.getParent ().getAttribute ("java.io.File"); 58 59 assertNotNull (f); 60 61 Thread.sleep (100); 63 64 if (!removeRec (f)) { 65 fail ("Cannot delete " + f); 66 } 67 68 if (f.exists()) { 69 fail ("File still exits: " + f); 70 } 71 72 73 fo.refresh(); 75 76 80 81 java.util.Date now = fo.lastModified (); 83 if (date.equals (now)) { 84 fail ("Last modified date before delete (" + date + ") is same as after (" + now + ")"); 85 } 86 87 InputStream is = null; 89 try { 90 fo.getInputStream (); 91 fail ("Input stream was created"); 92 } catch (java.io.FileNotFoundException ex) { 93 } finally { 95 if (is != null) is.close(); 96 } 97 98 fileChangedAssert ("Change event", 0); 100 fileDeletedAssert ("Delete event", 1); 101 102 103 if (fo.isValid ()) { 105 fail ("File is still valid: " + fo); 106 } 107 108 FileObject[] arr = fo.getParent ().getChildren (); 111 112 if (arr.length > 0) { 113 fail ("Parent's children not updated yet: " + arr.length + " [0] = " + arr[0]); 114 } 115 } 116 117 119 public void testExternalInternal () throws Exception { 120 FileObject fo = testedFS.findResource ("A/C"); 121 122 FileObject[] arr = fo.getChildren (); 124 if (arr.length != 1) { 125 fail ("Strange children in subfolder: " + java.util.Arrays.asList (arr)); 126 } 127 128 assertNotNull (fo); 129 130 if (!fo.isFolder ()) { 131 fail ("Not folder"); 132 } 133 134 135 136 File f = (File )fo.getAttribute ("java.io.File"); 137 assertNotNull (f); 138 139 File c = new File (f, "A.child"); 140 c.createNewFile(); 141 142 if (fo.getFileObject ("A.child") != null) { 143 fail ("the file created by external modification should not be found until refresh if the value is in cache"); 144 } 145 146 try { 147 FileObject oc = fo.createData ("A.child"); 148 fail ("A child has been created event it should not"); 149 } catch (SyncFailedException ex) { 150 } 152 153 fo.refresh (); 155 156 if (fo.getFileObject ("A.child") == null) { 158 fail ("the file is still not noticed in local file system"); 159 } 160 161 162 165 c = new File (f, "B.child"); 166 c.createNewFile(); 167 168 if (fo.getFileObject ("B.child") != null) { 169 fail ("The cache should not be up-to-date"); 170 } 171 172 FileObject ok = FileUtil.createData (fo, "B.child"); 173 174 if (!c.equals (ok.getAttribute ("java.io.File"))) { 175 fail ("The created file is not the same"); 176 } 177 } 178 179 183 private static boolean removeRec (java.io.File f) { 184 185 if (f.isDirectory ()) { 186 java.io.File arr[] = f.listFiles(); 187 188 for (int i = 0; i < arr.length; i++) { 189 if (!removeRec (arr[i])) { 190 return false; 191 } 192 } 193 } 194 195 return f.delete (); 196 } 197 } 198 | Popular Tags |