1 19 20 package org.netbeans.modules.autoupdate; 21 22 import java.lang.ref.*; 23 import java.util.*; 24 25 import org.netbeans.junit.*; 27 28 import java.util.List ; 29 import java.awt.Image ; 30 import java.awt.datatransfer.Transferable ; 31 import java.beans.*; 32 import java.io.File ; 33 import java.io.FileOutputStream ; 34 import java.io.IOException ; 35 import java.util.jar.*; 36 import java.util.jar.Manifest ; 37 import java.util.regex.*; 38 import java.util.zip.ZipEntry ; 39 import java.util.zip.ZipOutputStream ; 40 41 43 44 45 public class MissingModuleXMLFileGeneratedTest extends AbstractTestHid 46 implements org.xml.sax.EntityResolver { 47 public MissingModuleXMLFileGeneratedTest (String name) { 48 super (name); 49 } 50 51 public static void main(java.lang.String [] args) { 52 if (args.length == 1) { 53 junit.textui.TestRunner.run(new MissingModuleXMLFileGeneratedTest (args[0])); 54 } else { 55 junit.textui.TestRunner.run(new NbTestSuite(MissingModuleXMLFileGeneratedTest.class)); 56 } 57 System.exit (0); 58 } 59 60 61 62 public void testNbmWithoutModuleConfigGetsCorrectlyListed () throws Exception { 63 File f = generateNbmWithoutModulesXML ("modules/autoload/naming.jar"); 64 65 ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f); 66 download (mu); 67 installNBM (Downloader.getNBM (mu)); 68 69 70 Map userFiles = findFiles (userDir); 71 assertNotNull ("Contains naming.jar", userFiles.get ("modules/autoload/naming.jar")); 72 assertNotNull ("Contains update tracking", userFiles.get ("update_tracking/org-netbeans-core-naming.xml")); 73 File config = (File )userFiles.get ("config/Modules/org-netbeans-core-naming.xml"); 74 assertNotNull ("The config file was generated", config); 75 76 assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ()); 77 78 79 assertModule ("Should be autoload", "org-netbeans-core-naming", false, true, false); 80 } 81 82 public void testEagerNbmWithoutModuleConfigGetsCorrectlyListed () throws Exception { 83 File f = generateNbmWithoutModulesXML ("modules/eager/naming.jar"); 84 85 ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f); 86 download (mu); 87 installNBM (Downloader.getNBM (mu)); 88 89 90 Map userFiles = findFiles (userDir); 91 assertNotNull ("Contains naming.jar", userFiles.get ("modules/eager/naming.jar")); 92 assertNotNull ("Contains update tracking", userFiles.get ("update_tracking/org-netbeans-core-naming.xml")); 93 File config = (File )userFiles.get ("config/Modules/org-netbeans-core-naming.xml"); 94 assertNotNull ("The config file was generated", config); 95 96 assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ()); 97 98 99 assertModule ("Should be autoload", "org-netbeans-core-naming", false, false, true); 100 } 101 102 public void testRegularNbmWithoutModuleConfigGetsCorrectlyListed () throws Exception { 103 File f = generateNbmWithoutModulesXML ("modules/naming.jar"); 104 105 ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f); 106 download (mu); 107 installNBM (Downloader.getNBM (mu)); 108 109 110 Map userFiles = findFiles (userDir); 111 assertNotNull ("Contains naming.jar", userFiles.get ("modules/naming.jar")); 112 assertNotNull ("Contains update tracking", userFiles.get ("update_tracking/org-netbeans-core-naming.xml")); 113 File config = (File )userFiles.get ("config/Modules/org-netbeans-core-naming.xml"); 114 assertNotNull ("The config file was generated", config); 115 116 assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ()); 117 118 119 assertModule ("Should be autoload", "org-netbeans-core-naming", true, false, false); 120 } 121 122 private void assertModule (String txt, String dashBase, boolean enabled, boolean autoload, boolean eager) 123 throws Exception { 124 boolean f = assertModule (userDir, txt, dashBase, enabled, autoload, eager); 125 f |= assertModule (platformDir, txt, dashBase, enabled, autoload, eager); 126 f |= assertModule (clusterDir, txt, dashBase, enabled, autoload, eager); 127 f |= assertModule (nextDir, txt, dashBase, enabled, autoload, eager); 128 129 assertTrue ("At least once cluster has to contain the module", f); 130 } 131 132 private boolean assertModule (File dir, String txt, String dashBase, boolean enabled, boolean autoload, boolean eager) 133 throws Exception { 134 if (dir == null || !dir.isDirectory ()) { 135 return false; 136 } 137 138 File config = new File (dir, "config/Modules/" + dashBase + ".xml"); 139 if (!config.isFile ()) { 140 return false; 141 } 142 143 javax.xml.parsers.DocumentBuilderFactory f; 144 f = javax.xml.parsers.DocumentBuilderFactory.newInstance (); 145 javax.xml.parsers.DocumentBuilder b = f.newDocumentBuilder (); 146 b.setEntityResolver (this); 147 148 org.w3c.dom.Document document = b.parse (config); 149 org.w3c.dom.Element e; 150 151 org.w3c.dom.NodeList list = document.getElementsByTagName ("module"); 152 assertEquals ("One module element", 1, list.getLength ()); 153 e = (org.w3c.dom.Element )list.item (0); 154 assertEquals ("The right name", dashBase.replace ('-', '.'), e.getAttribute ("name")); 155 156 boolean jarFound = false; 157 list = document.getElementsByTagName ("param"); 158 for (int i = 0; i < list.getLength (); i++) { 159 e = (org.w3c.dom.Element )list.item (i); 160 161 String name = e.getAttribute ("name"); 162 163 boolean toTest; 164 if ("autoload".equals (name)) { 165 toTest = autoload; 166 } else if ("enabled".equals (name)) { 167 toTest = enabled; 168 } else if ("eager".equals (name)) { 169 toTest = eager; 170 } else if ("jar".equals (name)) { 171 jarFound = true; 172 continue; 173 } else { 174 continue; 175 } 176 177 org.w3c.dom.Text t = (org.w3c.dom.Text )e.getChildNodes ().item (0); 178 179 String boolValue = t.getNodeValue (); 181 if (!"true".equalsIgnoreCase (boolValue)) { 182 if (!"false".equalsIgnoreCase (boolValue)) { 183 fail ("Value of attribute 'name' must be 'true' or 'false' but was: " + boolValue); 184 } 185 } 186 188 assertEquals ("Attribute " + name, toTest, Boolean.valueOf (t.getNodeValue ()).booleanValue ()); 189 } 190 191 assertTrue ("jar attribute must be specified", jarFound); 192 return true; 193 } 194 195 196 private File generateNbmWithoutModulesXML (String file) throws Exception { 197 String manifest = 198 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 199 "<!DOCTYPE module PUBLIC \"-//NetBeans//DTD Autoupdate Module Info 2.0//EN\" \"http://www.netbeans.org/dtds/autoupdate-info-2_0.dtd\">" + 200 "<module codenamebase=\"org.netbeans.core.naming\"" + 201 " homepage=\"http://contrib.netbeans.org/\"" + 202 " distribution=\"http://www.netbeans.org/download/nbms/alpha/dev/naming.nbm\"" + 203 " downloadsize=\"0\"" + 204 ">" + 205 "<manifest " + 206 " OpenIDE-Module=\"org.netbeans.core.naming/1\"" + 207 " OpenIDE-Module-Display-Category=\"Infrastructure\"" + 208 " OpenIDE-Module-IDE-Dependencies=\"IDE/1 > 3.17\"" + 209 " OpenIDE-Module-Implementation-Version=\"200404191800\"" + 210 " OpenIDE-Module-Long-Description=\"Provides implementation of JNDI over content of system file system.\"" + 211 " OpenIDE-Module-Name=\"Naming\"" + 212 " OpenIDE-Module-Short-Description=\"Implementation of JNDI.\"" + 213 " OpenIDE-Module-Specification-Version=\"1.4\"" + 214 "/>" + 215 "</module>"; 216 217 String [] fileList = { 218 "netbeans/" + file 219 }; 220 221 File f = generateNBM (fileList, manifest); 222 223 return f; 224 225 } 226 227 public org.xml.sax.InputSource resolveEntity (String publicId, String systemId) throws org.xml.sax.SAXException , IOException { 228 java.io.InputStream is = new java.io.ByteArrayInputStream (new byte[0]); 229 return new org.xml.sax.InputSource (is); 230 } 231 232 } 233 | Popular Tags |