1 19 20 package org.netbeans.core.validation; 21 22 import java.io.InputStream ; 23 import junit.framework.*; 24 import org.netbeans.junit.*; 25 import org.openide.cookies.InstanceCookie; 26 27 import org.openide.filesystems.*; 28 import org.openide.loaders.*; 29 30 34 public class ValidateLayerAutomountTest extends NbTestCase { 35 36 37 public ValidateLayerAutomountTest(String name) { 38 super (name); 39 } 40 41 44 public static void main(java.lang.String [] args) { 45 junit.textui.TestRunner.run(suite()); 46 } 47 48 public static Test suite() { 49 TestSuite suite = new NbTestSuite(ValidateLayerAutomountTest.class); 50 51 return suite; 52 } 53 54 58 protected String rootName () { 59 return "Mount"; 60 } 61 62 63 protected boolean skipFile (FileObject fo) { 64 return "Mount/SystemFileSystem.instance".equals (fo.getPath ()); 65 } 66 67 protected boolean correctInstance (Object obj) { 68 if (obj instanceof FileSystem) { 69 return true; 70 } 71 if (obj instanceof FileSystem[]) { 72 return true; 73 } 74 75 return false; 76 } 77 78 79 83 public void testContentCorrect () throws Exception { 84 java.util.ArrayList errors = new java.util.ArrayList (); 85 86 FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource (rootName ()); 87 if (fo == null) { 88 return; 90 } 91 DataFolder df = DataFolder.findFolder (fo); 92 verifyMenu (df, errors); 93 94 if (!errors.isEmpty()) { 95 fail ("Some files do not provide valid menu elements" + errors); 96 } 97 } 98 99 private void verifyMenu (DataFolder f, java.util.ArrayList errors) throws Exception { 100 DataObject[] arr = f.getChildren(); 101 for (int i = 0; i < arr.length; i++) { 102 if (arr[i] instanceof DataFolder) { 103 verifyMenu ((DataFolder)arr[i], errors); 104 continue; 105 } 106 FileObject file = arr[i].getPrimaryFile (); 107 108 if (skipFile (file)) { 109 continue; 110 } 111 112 Object url = file.getURL(); 113 114 InstanceCookie ic = (InstanceCookie)arr[i].getCookie(InstanceCookie.class); 115 if (ic == null) { 116 errors.add ("\n File " + file + " does not have instance cookie, url: " + url); 117 continue; 118 } 119 120 try { 121 Object obj = ic.instanceCreate(); 122 if (correctInstance (obj)) { 123 continue; 124 } 125 errors.add ("\n File " + arr[i].getPrimaryFile () + " does not provide correct instance: " + obj + " url: " + url); 126 } catch (Exception ex) { 127 errors.add ("\n File " + arr[i].getPrimaryFile () + " cannot be read " + ex + " url: " + url); 128 } 129 } 130 } 131 } 132 133 | Popular Tags |