KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.*;
24 import org.netbeans.editor.BaseDocument;
25 import org.netbeans.editor.ext.html.test.TestBase;
26 import org.netbeans.modules.editor.html.HTMLKit;
27
28 /**
29  *
30  * @author Tomasz Slota
31  */

32 public class HTMLFormatterTest extends TestBase {
33     /**
34      * Used for testing dynamic indentation ("smart enter")
35      */

36     public final static String JavaDoc LINE_BREAK_METATAG = "|";
37     
38     public HTMLFormatterTest(String JavaDoc testName) {
39         super(testName);
40     }
41
42     public static Test suite() {
43         TestSuite suite = new TestSuite(HTMLFormatterTest.class);
44         
45         return suite;
46     }
47
48     public void testReformatSample1(){
49         testReformat("netbeans_front_page.html");
50     }
51     
52     public void testReformatSample2(){
53         testReformat("java_sun_com.html");
54     }
55     /*
56      * This issue has been fixed on the release55 branch
57     public void testIssue71598(){
58         testReformat("issue71598.html");
59     }
60      **/

61     
62     private String JavaDoc extractCRMetatag(String JavaDoc text){
63         int indexOfMetatag = text.indexOf(LINE_BREAK_METATAG);
64         
65         if (indexOfMetatag == -1){
66             return text;
67         }
68         
69         String JavaDoc firstPart = text.substring(0, indexOfMetatag);
70         String JavaDoc secondPart = text.substring(indexOfMetatag + LINE_BREAK_METATAG.length());
71         
72         if (secondPart.indexOf(LINE_BREAK_METATAG) > -1){
73             throw new IllegalArgumentException JavaDoc("text contains more than one line break tag");
74         }
75         
76         return firstPart + secondPart;
77     }
78     
79     private void testReformat(String JavaDoc testFileName) {
80         System.out.println("testReformat(" + testFileName + ")");
81         HTMLFormatter formatter = new HTMLFormatter(HTMLKit.class);
82         BaseDocument doc = createDocument();
83          
84         try{
85             String JavaDoc txtRawHTML = Utils.readFileContentToString(new File JavaDoc(new File JavaDoc(
86                 getTestFilesDir(), "testReformat"), testFileName));
87                     
88             doc.insertString(0, txtRawHTML, null);
89             formatter.reformat(doc, 0, doc.getLength(), false);
90             getRef().print(doc.getText(0, doc.getLength()));
91         }
92         catch (Exception JavaDoc e){
93             fail(e.getMessage()); // should never happen
94
}
95         
96         compareReferenceFiles();
97     }
98
99     
100     private File JavaDoc getTestFilesDir(){
101         return new File JavaDoc(new File JavaDoc(getDataDir(), "input"), "HTMLFormatterTest");
102     }
103     
104 }
105
Popular Tags