KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javadoc > search > SearchThreadJdk12Test


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.javadoc.search;
21
22 import java.io.File JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.LinkedList JavaDoc;
25 import org.netbeans.junit.NbTestCase;
26 import org.openide.filesystems.LocalFileSystem;
27 import org.openide.filesystems.FileObject;
28
29 /**
30  *
31  * @author Jan Pokorsky
32  */

33 public final class SearchThreadJdk12Test extends NbTestCase {
34
35     private LocalFileSystem fs;
36     private static final String JavaDoc JDK14_INDEX_PATH = "docs_jdk14/api/index-files";
37     private static final String JavaDoc JDK15_INDEX_PATH = "docs_jdk15/api/index-files";
38
39     public SearchThreadJdk12Test(String JavaDoc testName) {
40         super(testName);
41     }
42
43     protected void setUp() throws Exception JavaDoc {
44         File JavaDoc 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 JavaDoc {
51         FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH);
52         assertNotNull(idxFolder);
53         
54         String JavaDoc toFind = "DataFlavor";
55         MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();
56         SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true);
57         search.run(); // not go() since we do not want to post the task to another thread
58
assertTrue("not finished", diiConsumer.isFinished);
59         assertEquals("search result", 6, diiConsumer.l.size());
60         
61         // class DataFlavor
62
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         // constructor
69
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 JavaDoc {
78         FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH);
79         assertNotNull(idxFolder);
80         
81         String JavaDoc toFind = "DatabaseMetaData";
82         MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();
83         SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true);
84         search.run(); // not go() since we do not want to post the task to another thread
85
assertTrue("not finished", diiConsumer.isFinished);
86         assertEquals("search result", 1, diiConsumer.l.size());
87         
88         // DatabaseMetaData
89
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 JavaDoc {
98         FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH);
99         assertNotNull(idxFolder);
100         
101         String JavaDoc toFind = "DataFormatException";
102         MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();
103         SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true);
104         search.run(); // not go() since we do not want to post the task to another thread
105
assertTrue("not finished", diiConsumer.isFinished);
106         assertEquals("search result", 3, diiConsumer.l.size());
107         
108         // DataFormatException
109
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         // DataFormatException(String) - constructor
117
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 JavaDoc {
126         FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH);
127         assertNotNull(idxFolder);
128         
129         String JavaDoc toFind = "damageLineRange";
130         MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();
131         SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true);
132         search.run(); // not go() since we do not want to post the task to another thread
133
assertTrue("not finished", diiConsumer.isFinished);
134         assertEquals("search result", 1, diiConsumer.l.size());
135         
136         // damageLineRange(int, int, Shape, Component)
137
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 JavaDoc {
146         FileObject idxFolder = fs.findResource(JDK14_INDEX_PATH);
147         assertNotNull(idxFolder);
148         
149         String JavaDoc toFind = "darkShadow";
150         MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();
151         SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true);
152         search.run(); // not go() since we do not want to post the task to another thread
153
assertTrue("not finished", diiConsumer.isFinished);
154         assertEquals("search result", 4, diiConsumer.l.size());
155         
156         // darkShadow
157
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         // darkShadowColor - static variable
165
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 JavaDoc {
174         FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH);
175         assertNotNull(idxFolder);
176         
177         String JavaDoc toFind = "DataFlavor";
178         MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();
179         SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true);
180         search.run(); // not go() since we do not want to post the task to another thread
181
assertTrue("not finished", diiConsumer.isFinished);
182         assertEquals("search result", 6, diiConsumer.l.size());
183         
184         // class DataFlavor
185
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         // constructor
192
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 JavaDoc {
201         // see issue #54244
202
FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH);
203         assertNotNull(idxFolder);
204         
205         String JavaDoc toFind = "DemoHashMap";
206         MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();
207         SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true);
208         search.run(); // not go() since we do not want to post the task to another thread
209
assertTrue("not finished", diiConsumer.isFinished);
210         assertEquals("search result", 2, diiConsumer.l.size());
211         
212         // class DemoHashMap<K,V>
213
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         // generic constructor DemoHashMap(Map<? extends K, ? extends V>)
220
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 JavaDoc {
229         FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH);
230         assertNotNull(idxFolder);
231         
232         String JavaDoc toFind = "damageLineRange";
233         MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();
234         SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true);
235         search.run(); // not go() since we do not want to post the task to another thread
236
assertTrue("not finished", diiConsumer.isFinished);
237         assertEquals("search result", 1, diiConsumer.l.size());
238         
239         // damageLineRange(int, int, Shape, Component)
240
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 JavaDoc {
249         FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH);
250         assertNotNull(idxFolder);
251         
252         String JavaDoc toFind = "darkShadow";
253         MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();
254         SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true);
255         search.run(); // not go() since we do not want to post the task to another thread
256
assertTrue("not finished", diiConsumer.isFinished);
257         assertEquals("search result", 4, diiConsumer.l.size());
258         
259         // darkShadow
260
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         // darkShadowColor - static variable
268
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 JavaDoc {
277         FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH);
278         assertNotNull(idxFolder);
279         
280         String JavaDoc toFind = "DataFormatException";
281         MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();
282         SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true);
283         search.run(); // not go() since we do not want to post the task to another thread
284
assertTrue("not finished", diiConsumer.isFinished);
285         assertEquals("search result", 3, diiConsumer.l.size());
286         
287         // DataFormatException
288
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         // DataFormatException(String) - constructor
296
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 JavaDoc {
305         FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH);
306         assertNotNull(idxFolder);
307         
308         String JavaDoc toFind = "DatabaseMetaData";
309         MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();
310         SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true);
311         search.run(); // not go() since we do not want to post the task to another thread
312
assertTrue("not finished", diiConsumer.isFinished);
313         assertEquals("search result", 1, diiConsumer.l.size());
314         
315         // DatabaseMetaData
316
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 JavaDoc {
325         FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH);
326         assertNotNull(idxFolder);
327         
328         String JavaDoc toFind = "DemoMemoryType";
329         MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();
330         SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true);
331         search.run(); // not go() since we do not want to post the task to another thread
332
assertTrue("not finished", diiConsumer.isFinished);
333         assertEquals("search result", 1, diiConsumer.l.size());
334         
335         // DemoMemoryType
336
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 JavaDoc {
345         FileObject idxFolder = fs.findResource(JDK15_INDEX_PATH);
346         assertNotNull(idxFolder);
347         
348         String JavaDoc toFind = "Deprecated";
349         MyDocIndexItemConsumer diiConsumer = new MyDocIndexItemConsumer();
350         SearchThreadJdk12 search = new SearchThreadJdk12(toFind, idxFolder, diiConsumer, true);
351         search.run(); // not go() since we do not want to post the task to another thread
352
assertTrue("not finished", diiConsumer.isFinished);
353         assertEquals("search result", 1, diiConsumer.l.size());
354         
355         // Deprecated
356
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 JavaDoc l = new LinkedList JavaDoc();
367             
368         public void addDocIndexItem(DocIndexItem dii) {
369 // try {
370
// System.out.println("dc: " + dii.getDeclaringClass() + ", field: " + dii.getField() +
371
// ", pkg: " + dii.getPackage() + ", remark: " + dii.getRemark() + ", url: " + dii.getURL().toString());
372
// } catch (Exception e) {
373
// e.printStackTrace();
374
// }
375
l.add(dii);
376         }
377
378         public void indexSearchThreadFinished(IndexSearchThread ist) {
379 // System.out.println("-------------------------------");
380
isFinished = true;
381         }
382     }
383 }
384
Popular Tags