1 19 20 package org.netbeans.modules.javadoc.search; 21 22 import java.io.File ; 23 import java.util.List ; 24 import java.util.LinkedList ; 25 import org.netbeans.junit.NbTestCase; 26 import org.openide.filesystems.LocalFileSystem; 27 import org.openide.filesystems.FileObject; 28 29 33 public final class SearchThreadJdk12Test extends NbTestCase { 34 35 private LocalFileSystem fs; 36 private static final String JDK14_INDEX_PATH = "docs_jdk14/api/index-files"; 37 private static final String JDK15_INDEX_PATH = "docs_jdk15/api/index-files"; 38 39 public SearchThreadJdk12Test(String testName) { 40 super(testName); 41 } 42 43 protected void setUp() throws Exception { 44 File dataFile = getDataDir(); 45 assertNotNull("missing data file", dataFile); 46 fs = new LocalFileSystem(); 47 fs.setRootDirectory(dataFile); 48 } 49 50 public void testSearchInJDK14_Class() throws Exception { 51 FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH); 52 assertNotNull(idxFolder); 53 54 String toFind = "DataFlavor"; 55 MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); 56 SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true); 57 search.run(); assertTrue("not finished", diiConsumer.isFinished); 59 assertEquals("search result", 6, diiConsumer.l.size()); 60 61 DocIndexItem dii = (DocIndexItem) diiConsumer.l.get(0); 63 assertEquals("field", "DataFlavor", dii.getField()); 64 assertEquals("declaring class", "DataFlavor", dii.getDeclaringClass()); 65 assertEquals("remark", " - class java.awt.datatransfer.DataFlavor.", dii.getRemark()); 66 assertEquals("package", "java.awt.datatransfer.", dii.getPackage()); 67 assertTrue("url", dii.getURL().toString().endsWith("api/java/awt/datatransfer/DataFlavor.html")); 68 dii = (DocIndexItem) diiConsumer.l.get(1); 70 assertEquals("field", "DataFlavor()", dii.getField()); 71 assertEquals("declaring class", "DataFlavor", dii.getDeclaringClass()); 72 assertEquals("remark", " - Constructor for class java.awt.datatransfer.DataFlavor", dii.getRemark()); 73 assertEquals("package", "java.awt.datatransfer.", dii.getPackage()); 74 assertTrue("url", dii.getURL().toString().endsWith("api/java/awt/datatransfer/DataFlavor.html#DataFlavor()")); 75 } 76 77 public void testSearchInJDK14_Interface() throws Exception { 78 FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH); 79 assertNotNull(idxFolder); 80 81 String toFind = "DatabaseMetaData"; 82 MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); 83 SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true); 84 search.run(); assertTrue("not finished", diiConsumer.isFinished); 86 assertEquals("search result", 1, diiConsumer.l.size()); 87 88 DocIndexItem dii = (DocIndexItem) diiConsumer.l.get(0); 90 assertEquals("field", "DatabaseMetaData", dii.getField()); 91 assertEquals("declaring class", "DatabaseMetaData", dii.getDeclaringClass()); 92 assertEquals("remark", " - interface java.sql.DatabaseMetaData.", dii.getRemark()); 93 assertEquals("package", "java.sql.", dii.getPackage()); 94 assertTrue("url", dii.getURL().toString().endsWith("api/java/sql/DatabaseMetaData.html")); 95 } 96 97 public void testSearchInJDK14_Exception() throws Exception { 98 FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH); 99 assertNotNull(idxFolder); 100 101 String toFind = "DataFormatException"; 102 MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); 103 SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true); 104 search.run(); assertTrue("not finished", diiConsumer.isFinished); 106 assertEquals("search result", 3, diiConsumer.l.size()); 107 108 DocIndexItem dii = (DocIndexItem) diiConsumer.l.get(0); 110 assertEquals("field", "DataFormatException", dii.getField()); 111 assertEquals("declaring class", "DataFormatException", dii.getDeclaringClass()); 112 assertEquals("remark", " - exception java.util.zip.DataFormatException.", dii.getRemark()); 113 assertEquals("package", "java.util.zip.", dii.getPackage()); 114 assertTrue("url", dii.getURL().toString().endsWith("api/java/util/zip/DataFormatException.html")); 115 116 dii = (DocIndexItem) diiConsumer.l.get(2); 118 assertEquals("field", "DataFormatException(String)", dii.getField()); 119 assertEquals("declaring class", "DataFormatException", dii.getDeclaringClass()); 120 assertEquals("remark", " - Constructor for class java.util.zip.DataFormatException", dii.getRemark()); 121 assertEquals("package", "java.util.zip.", dii.getPackage()); 122 assertTrue("url", dii.getURL().toString().endsWith("api/java/util/zip/DataFormatException.html#DataFormatException(java.lang.String)")); 123 } 124 125 public void testSearchInJDK14_Method() throws Exception { 126 FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH); 127 assertNotNull(idxFolder); 128 129 String toFind = "damageLineRange"; 130 MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); 131 SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true); 132 search.run(); assertTrue("not finished", diiConsumer.isFinished); 134 assertEquals("search result", 1, diiConsumer.l.size()); 135 136 DocIndexItem dii = (DocIndexItem) diiConsumer.l.get(0); 138 assertEquals("field", "damageLineRange(int, int, Shape, Component)", dii.getField()); 139 assertEquals("declaring class", "PlainView", dii.getDeclaringClass()); 140 assertEquals("remark", " - Method in class javax.swing.text.PlainView", dii.getRemark()); 141 assertEquals("package", "javax.swing.text.", dii.getPackage()); 142 assertTrue("url", dii.getURL().toString().endsWith("api/javax/swing/text/PlainView.html#damageLineRange(int, int, java.awt.Shape, java.awt.Component)")); 143 } 144 145 public void testSearchInJDK14_Variables() throws Exception { 146 FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH); 147 assertNotNull(idxFolder); 148 149 String toFind = "darkShadow"; 150 MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); 151 SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true); 152 search.run(); assertTrue("not finished", diiConsumer.isFinished); 154 assertEquals("search result", 4, diiConsumer.l.size()); 155 156 DocIndexItem dii = (DocIndexItem) diiConsumer.l.get(0); 158 assertEquals("field", "darkShadow", dii.getField()); 159 assertEquals("declaring class", "BasicBorders.ButtonBorder", dii.getDeclaringClass()); 160 assertEquals("remark", " - Variable in class javax.swing.plaf.basic.BasicBorders.ButtonBorder", dii.getRemark()); 161 assertEquals("package", "javax.swing.plaf.basic.", dii.getPackage()); 162 assertTrue("url", dii.getURL().toString().endsWith("api/javax/swing/plaf/basic/BasicBorders.ButtonBorder.html#darkShadow")); 163 164 dii = (DocIndexItem) diiConsumer.l.get(3); 166 assertEquals("field", "darkShadowColor", dii.getField()); 167 assertEquals("declaring class", "MetalSliderUI", dii.getDeclaringClass()); 168 assertEquals("remark", " - Static variable in class javax.swing.plaf.metal.MetalSliderUI", dii.getRemark()); 169 assertEquals("package", "javax.swing.plaf.metal.", dii.getPackage()); 170 assertTrue("url", dii.getURL().toString().endsWith("api/javax/swing/plaf/metal/MetalSliderUI.html#darkShadowColor")); 171 } 172 173 public void testSearchInJDK15_Class() throws Exception { 174 FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); 175 assertNotNull(idxFolder); 176 177 String toFind = "DataFlavor"; 178 MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); 179 SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true); 180 search.run(); assertTrue("not finished", diiConsumer.isFinished); 182 assertEquals("search result", 6, diiConsumer.l.size()); 183 184 DocIndexItem dii = (DocIndexItem) diiConsumer.l.get(0); 186 assertEquals("field", "DataFlavor", dii.getField()); 187 assertEquals("declaring class", "java.awt.datatransfer", dii.getDeclaringClass()); 188 assertEquals("remark", " - Class in java.awt.datatransfer", dii.getRemark()); 189 assertEquals("package", "java.awt.datatransfer.", dii.getPackage()); 190 assertTrue("url", dii.getURL().toString().endsWith("api/java/awt/datatransfer/DataFlavor.html")); 191 dii = (DocIndexItem) diiConsumer.l.get(1); 193 assertEquals("field", "DataFlavor()", dii.getField()); 194 assertEquals("declaring class", "DataFlavor", dii.getDeclaringClass()); 195 assertEquals("remark", " - Constructor for class java.awt.datatransfer.DataFlavor", dii.getRemark()); 196 assertEquals("package", "java.awt.datatransfer.", dii.getPackage()); 197 assertTrue("url", dii.getURL().toString().endsWith("api/java/awt/datatransfer/DataFlavor.html#DataFlavor()")); 198 } 199 200 public void testSearchInJDK15_GenericClass_54244() throws Exception { 201 FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); 203 assertNotNull(idxFolder); 204 205 String toFind = "DemoHashMap"; 206 MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); 207 SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true); 208 search.run(); assertTrue("not finished", diiConsumer.isFinished); 210 assertEquals("search result", 2, diiConsumer.l.size()); 211 212 DocIndexItem dii = (DocIndexItem) diiConsumer.l.get(0); 214 assertEquals("field", "DemoHashMap", dii.getField()); 215 assertEquals("declaring class", "java.util", dii.getDeclaringClass()); 216 assertEquals("remark", " - Class in java.util", dii.getRemark()); 217 assertEquals("package", "java.util.", dii.getPackage()); 218 assertTrue("url", dii.getURL().toString().endsWith("api/java/util/DemoHashMap.html")); 219 dii = (DocIndexItem) diiConsumer.l.get(1); 221 assertEquals("field", "DemoHashMap(Map<? extends K, ? extends V>)", dii.getField()); 222 assertEquals("declaring class", "DemoHashMap", dii.getDeclaringClass()); 223 assertEquals("remark", " - Constructor for class java.util.DemoHashMap", dii.getRemark()); 224 assertEquals("package", "java.util.", dii.getPackage()); 225 assertTrue("url", dii.getURL().toString().endsWith("api/java/util/DemoHashMap.html#DemoHashMap(java.util.Map)")); 226 } 227 228 public void testSearchInJDK15_Method() throws Exception { 229 FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); 230 assertNotNull(idxFolder); 231 232 String toFind = "damageLineRange"; 233 MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); 234 SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true); 235 search.run(); assertTrue("not finished", diiConsumer.isFinished); 237 assertEquals("search result", 1, diiConsumer.l.size()); 238 239 DocIndexItem dii = (DocIndexItem) diiConsumer.l.get(0); 241 assertEquals("field", "damageLineRange(int, int, Shape, Component)", dii.getField()); 242 assertEquals("declaring class", "PlainView", dii.getDeclaringClass()); 243 assertEquals("remark", " - Method in class javax.swing.text.PlainView", dii.getRemark()); 244 assertEquals("package", "javax.swing.text.", dii.getPackage()); 245 assertTrue("url", dii.getURL().toString().endsWith("api/javax/swing/text/PlainView.html#damageLineRange(int, int, java.awt.Shape, java.awt.Component)")); 246 } 247 248 public void testSearchInJDK15_Variables() throws Exception { 249 FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); 250 assertNotNull(idxFolder); 251 252 String toFind = "darkShadow"; 253 MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); 254 SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true); 255 search.run(); assertTrue("not finished", diiConsumer.isFinished); 257 assertEquals("search result", 4, diiConsumer.l.size()); 258 259 DocIndexItem dii = (DocIndexItem) diiConsumer.l.get(0); 261 assertEquals("field", "darkShadow", dii.getField()); 262 assertEquals("declaring class", "BasicBorders.ButtonBorder", dii.getDeclaringClass()); 263 assertEquals("remark", " - Variable in class javax.swing.plaf.basic.BasicBorders.ButtonBorder", dii.getRemark()); 264 assertEquals("package", "javax.swing.plaf.basic.", dii.getPackage()); 265 assertTrue("url", dii.getURL().toString().endsWith("api/javax/swing/plaf/basic/BasicBorders.ButtonBorder.html#darkShadow")); 266 267 dii = (DocIndexItem) diiConsumer.l.get(3); 269 assertEquals("field", "darkShadowColor", dii.getField()); 270 assertEquals("declaring class", "MetalSliderUI", dii.getDeclaringClass()); 271 assertEquals("remark", " - Static variable in class javax.swing.plaf.metal.MetalSliderUI", dii.getRemark()); 272 assertEquals("package", "javax.swing.plaf.metal.", dii.getPackage()); 273 assertTrue("url", dii.getURL().toString().endsWith("api/javax/swing/plaf/metal/MetalSliderUI.html#darkShadowColor")); 274 } 275 276 public void testSearchInJDK15_Exception() throws Exception { 277 FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); 278 assertNotNull(idxFolder); 279 280 String toFind = "DataFormatException"; 281 MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); 282 SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true); 283 search.run(); assertTrue("not finished", diiConsumer.isFinished); 285 assertEquals("search result", 3, diiConsumer.l.size()); 286 287 DocIndexItem dii = (DocIndexItem) diiConsumer.l.get(0); 289 assertEquals("field", "DataFormatException", dii.getField()); 290 assertEquals("declaring class", "java.util.zip", dii.getDeclaringClass()); 291 assertEquals("remark", " - Exception in java.util.zip", dii.getRemark()); 292 assertEquals("package", "java.util.zip.", dii.getPackage()); 293 assertTrue("url", dii.getURL().toString().endsWith("api/java/util/zip/DataFormatException.html")); 294 295 dii = (DocIndexItem) diiConsumer.l.get(2); 297 assertEquals("field", "DataFormatException(String)", dii.getField()); 298 assertEquals("declaring class", "DataFormatException", dii.getDeclaringClass()); 299 assertEquals("remark", " - Constructor for exception java.util.zip.DataFormatException", dii.getRemark()); 300 assertEquals("package", "java.util.zip.", dii.getPackage()); 301 assertTrue("url", dii.getURL().toString().endsWith("api/java/util/zip/DataFormatException.html#DataFormatException(java.lang.String)")); 302 } 303 304 public void testSearchInJDK15_Interface() throws Exception { 305 FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); 306 assertNotNull(idxFolder); 307 308 String toFind = "DatabaseMetaData"; 309 MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); 310 SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true); 311 search.run(); assertTrue("not finished", diiConsumer.isFinished); 313 assertEquals("search result", 1, diiConsumer.l.size()); 314 315 DocIndexItem dii = (DocIndexItem) diiConsumer.l.get(0); 317 assertEquals("field", "DatabaseMetaData", dii.getField()); 318 assertEquals("declaring class", "java.sql", dii.getDeclaringClass()); 319 assertEquals("remark", " - Interface in java.sql", dii.getRemark()); 320 assertEquals("package", "java.sql.", dii.getPackage()); 321 assertTrue("url", dii.getURL().toString().endsWith("api/java/sql/DatabaseMetaData.html")); 322 } 323 324 public void testSearchInJDK15_Enum() throws Exception { 325 FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); 326 assertNotNull(idxFolder); 327 328 String toFind = "DemoMemoryType"; 329 MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); 330 SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true); 331 search.run(); assertTrue("not finished", diiConsumer.isFinished); 333 assertEquals("search result", 1, diiConsumer.l.size()); 334 335 DocIndexItem dii = (DocIndexItem) diiConsumer.l.get(0); 337 assertEquals("field", "DemoMemoryType", dii.getField()); 338 assertEquals("declaring class", "java.lang.management", dii.getDeclaringClass()); 339 assertEquals("remark", " - Enum in java.lang.management", dii.getRemark()); 340 assertEquals("package", "java.lang.management.", dii.getPackage()); 341 assertTrue("url", dii.getURL().toString().endsWith("api/java/lang/management/DemoMemoryType.html")); 342 } 343 344 public void testSearchInJDK15_AnnotationType() throws Exception { 345 FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH); 346 assertNotNull(idxFolder); 347 348 String toFind = "Deprecated"; 349 MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer(); 350 SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true); 351 search.run(); assertTrue("not finished", diiConsumer.isFinished); 353 assertEquals("search result", 1, diiConsumer.l.size()); 354 355 DocIndexItem dii = (DocIndexItem) diiConsumer.l.get(0); 357 assertEquals("field", "Deprecated", dii.getField()); 358 assertEquals("declaring class", "java.lang", dii.getDeclaringClass()); 359 assertEquals("remark", " - Annotation Type in java.lang", dii.getRemark()); 360 assertEquals("package", "java.lang.", dii.getPackage()); 361 assertTrue("url", dii.getURL().toString().endsWith("api/java/lang/Deprecated.html")); 362 } 363 364 private static final class MyDocIndexItemConsumer implements IndexSearchThread.DocIndexItemConsumer { 365 boolean isFinished = false; 366 List l = new LinkedList (); 367 368 public void addDocIndexItem(DocIndexItem dii) { 369 l.add(dii); 376 } 377 378 public void indexSearchThreadFinished(IndexSearchThread ist) { 379 isFinished = true; 381 } 382 } 383 } 384 | Popular Tags |