KickJava   Java API By Example, From Geeks To Geeks.

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


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.BufferedInputStream JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.Reader JavaDoc;
26 import org.netbeans.junit.NbTestCase;
27 import org.netbeans.modules.javadoc.search.IndexBuilder.SimpleTitleParser;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.LocalFileSystem;
30
31 /**
32  *
33  * @author Jan Pokorsky
34  */

35 public class IndexBuilderTest extends NbTestCase {
36
37     private LocalFileSystem fs;
38     private static final String JavaDoc JDK14_INDEX_PATH = "docs_jdk14/api/index-files";
39     private static final String JavaDoc JDK14_JA_INDEX_PATH = "docs_jdk14_ja/api/index-files";
40     private static final String JavaDoc JDK15_INDEX_PATH = "docs_jdk15/api/index-files";
41     private static final String JavaDoc JDK15_JA_INDEX_PATH = "docs_jdk15_ja/api/index-files";
42
43     /** Creates a new instance of IndexBuilderTest */
44     public IndexBuilderTest(String JavaDoc testName) {
45         super(testName);
46     }
47     
48     protected void setUp() throws Exception JavaDoc {
49         File JavaDoc dataFile = getDataDir();
50         assertNotNull("missing data file", dataFile);
51         fs = new LocalFileSystem();
52         fs.setRootDirectory(dataFile);
53     }
54
55     public void testTitleInJDK14() throws Exception JavaDoc {
56         FileObject html = fs.findResource(JDK14_INDEX_PATH + "/index-4.html");
57
58         InputStream JavaDoc is = new BufferedInputStream JavaDoc(html.getInputStream(), 1024);
59         SimpleTitleParser tp = new SimpleTitleParser(is);
60         try {
61             tp.parse();
62             String JavaDoc titlestr = tp.getTitle();
63             assertEquals("wrong title", "D-Index (Java 2 Platform SE v1.4.2)", titlestr);
64         } finally {
65             is.close();
66         }
67     }
68
69     public void testTitleInJDK15() throws Exception JavaDoc {
70         FileObject html = fs.findResource(JDK15_INDEX_PATH + "/index-4.html");
71
72         InputStream JavaDoc is = new BufferedInputStream JavaDoc(html.getInputStream(), 1024);
73         SimpleTitleParser tp = new SimpleTitleParser(is);
74         try {
75             tp.parse();
76             String JavaDoc titlestr = tp.getTitle();
77             assertEquals("wrong title", "D-Index (Java 2 Platform SE 5.0)", titlestr);
78         } finally {
79             is.close();
80         }
81     }
82
83     public void testTitleInJDK14_ja() throws Exception JavaDoc {
84         FileObject html = fs.findResource(JDK14_JA_INDEX_PATH + "/index-4.html");
85         FileObject html2 = fs.findResource(JDK14_JA_INDEX_PATH + "/index-4.title");
86         japanaseIndexes(html, html2, "iso-2022-jp");
87     }
88
89     public void testTitleInJDK15_ja() throws Exception JavaDoc {
90         FileObject html = fs.findResource(JDK15_JA_INDEX_PATH + "/index-4.html");
91         FileObject html2 = fs.findResource(JDK15_JA_INDEX_PATH + "/index-4.title");
92         japanaseIndexes(html, html2, "euc-jp");
93     }
94
95     private void japanaseIndexes(FileObject html, FileObject title, String JavaDoc charset) throws Exception JavaDoc {
96         assertNotNull(html);
97         assertNotNull(title);
98
99         Reader JavaDoc r = new java.io.InputStreamReader JavaDoc(title.getInputStream(), charset);
100
101         int ic;
102         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
103         try {
104             while ((ic = r.read()) != -1) {
105                 sb.append((char) ic);
106             }
107         } finally {
108             r.close();
109         }
110
111         InputStream JavaDoc is = new BufferedInputStream JavaDoc(html.getInputStream(), 1024);
112         SimpleTitleParser tp = new SimpleTitleParser(is);
113         try {
114             tp.parse();
115             String JavaDoc titlestr = tp.getTitle();
116             assertEquals("wrong title", sb.toString(), titlestr);
117         } finally {
118             is.close();
119         }
120     }
121 }
122
Popular Tags