KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > ext > html > HTMLCompletionQueryTest


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.editor.ext.html;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.PrintStream JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28 import javax.swing.JEditorPane JavaDoc;
29 import javax.swing.text.BadLocationException JavaDoc;
30 import javax.swing.text.JTextComponent JavaDoc;
31 import org.netbeans.editor.BaseDocument;
32 import org.netbeans.editor.TokenContext;
33 import org.netbeans.editor.TokenContextPath;
34 import org.netbeans.editor.TokenID;
35 import org.netbeans.editor.TokenItem;
36 import org.netbeans.editor.ext.CompletionQuery;
37 import org.netbeans.editor.ext.html.HTMLSyntax;
38 import org.netbeans.editor.ext.html.dtd.DTD;
39 import org.netbeans.editor.ext.html.test.TestBase;
40 import org.netbeans.junit.NbTestCase;
41 import org.netbeans.modules.editor.html.HTMLKit;
42 import org.netbeans.modules.editor.html.NbReaderProvider;
43
44 import org.openide.ErrorManager;
45
46 /**Html completion test
47  * This class extends TestBase class which provides access to the html editor module layer
48  *
49  * @author Marek Fukala
50  */

51 public class HTMLCompletionQueryTest extends TestBase {
52     
53     public HTMLCompletionQueryTest() throws IOException JavaDoc, BadLocationException JavaDoc {
54         super("htmlsyntaxsupporttest");
55         NbReaderProvider.setupReaders(); //initialize DTD providers
56
}
57
58     public void setUp() {
59     }
60         
61     public void tearDown() {
62     }
63     
64     //test methods -----------
65
public void testIndexHtml() throws IOException JavaDoc, BadLocationException JavaDoc {
66         testCompletionResults(new File JavaDoc(getDataDir(), "input/HTMLCompletionQueryTest/index.html"));
67     }
68     
69     // causing OutOfMemoryError
70
// public void testNetbeansFrontPageHtml() throws IOException, BadLocationException {
71
// testCompletionResults(new File(getDataDir(), "input/HTMLCompletionQueryTest/truncated_netbeans_front_page.html"));
72
// }
73

74     //helper methods ------------
75
private void testCompletionResults(File JavaDoc inputFile) throws IOException JavaDoc, BadLocationException JavaDoc {
76         String JavaDoc content = Utils.readFileContentToString(inputFile);
77         BaseDocument doc = createDocument();
78         doc.insertString(0,content,null);
79         HTMLSyntaxSupport sup = new HTMLSyntaxSupport(doc);
80         HTMLCompletionQuery query = new HTMLCompletionQuery();
81         
82         JEditorPane JavaDoc component = new JEditorPane JavaDoc();
83         for(int i = 0; i < doc.getLength(); i++) {
84             CompletionQuery.Result result = query.query(component, HTMLKit.class, doc, i, sup);
85             if(result == null) {
86                 getRef().println(i+" => NO RESULT");
87             } else {
88                 List JavaDoc data = result.getData();
89                 if(data == null) {
90                     getRef().println(i + " => NO RESULT");
91                 } else {
92                     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
93                     sb.append('[');
94                     Iterator JavaDoc itr = data.iterator();
95                     while(itr.hasNext()) {
96                         sb.append(itr.next());
97                         if(itr.hasNext()) sb.append(',');
98                     }
99                     sb.append(']');
100                     getRef().println(sb.toString());
101                 }
102             }
103             
104         }
105         
106         compareReferenceFiles();
107     }
108     
109 }
110
Popular Tags