1 19 20 package org.netbeans.modules.javadoc.search; 21 22 import java.io.BufferedInputStream ; 23 import java.io.File ; 24 import java.io.InputStream ; 25 import java.io.Reader ; 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 35 public class IndexBuilderTest extends NbTestCase { 36 37 private LocalFileSystem fs; 38 private static final String JDK14_INDEX_PATH = "docs_jdk14/api/index-files"; 39 private static final String JDK14_JA_INDEX_PATH = "docs_jdk14_ja/api/index-files"; 40 private static final String JDK15_INDEX_PATH = "docs_jdk15/api/index-files"; 41 private static final String JDK15_JA_INDEX_PATH = "docs_jdk15_ja/api/index-files"; 42 43 44 public IndexBuilderTest(String testName) { 45 super(testName); 46 } 47 48 protected void setUp() throws Exception { 49 File dataFile = getDataDir(); 50 assertNotNull("missing data file", dataFile); 51 fs = new LocalFileSystem(); 52 fs.setRootDirectory(dataFile); 53 } 54 55 public void testTitleInJDK14() throws Exception { 56 FileObject html = fs.findResource(JDK14_INDEX_PATH + "/index-4.html"); 57 58 InputStream is = new BufferedInputStream (html.getInputStream(), 1024); 59 SimpleTitleParser tp = new SimpleTitleParser(is); 60 try { 61 tp.parse(); 62 String 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 { 70 FileObject html = fs.findResource(JDK15_INDEX_PATH + "/index-4.html"); 71 72 InputStream is = new BufferedInputStream (html.getInputStream(), 1024); 73 SimpleTitleParser tp = new SimpleTitleParser(is); 74 try { 75 tp.parse(); 76 String 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 { 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 { 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 charset) throws Exception { 96 assertNotNull(html); 97 assertNotNull(title); 98 99 Reader r = new java.io.InputStreamReader (title.getInputStream(), charset); 100 101 int ic; 102 StringBuilder sb = new StringBuilder (); 103 try { 104 while ((ic = r.read()) != -1) { 105 sb.append((char) ic); 106 } 107 } finally { 108 r.close(); 109 } 110 111 InputStream is = new BufferedInputStream (html.getInputStream(), 1024); 112 SimpleTitleParser tp = new SimpleTitleParser(is); 113 try { 114 tp.parse(); 115 String titlestr = tp.getTitle(); 116 assertEquals("wrong title", sb.toString(), titlestr); 117 } finally { 118 is.close(); 119 } 120 } 121 } 122 | Popular Tags |