KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > web > core > syntax > JspColoringTest


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.test.web.core.syntax;
21
22 import java.io.File JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.List JavaDoc;
25 import junit.framework.Test;
26 import org.netbeans.junit.AssertionFailedErrorException;
27 import org.netbeans.junit.NbTestCase;
28 import org.netbeans.editor.BaseDocument;
29 import org.netbeans.editor.TokenID;
30 import org.netbeans.editor.TokenItem;
31 import org.netbeans.editor.ext.ExtSyntaxSupport;
32 import org.netbeans.test.web.FileObjectFilter;
33 import org.netbeans.test.web.RecurrentSuiteFactory;
34 import org.openide.cookies.EditorCookie;
35 import org.openide.filesystems.FileObject;
36 import org.openide.loaders.DataObject;
37
38 /**
39  *
40  * @author ms113234
41  */

42 public class JspColoringTest extends NbTestCase {
43     private FileObject testFileObj;
44     
45     /** Need to be defined because of JUnit */
46     public JspColoringTest(String JavaDoc name, FileObject testFileObj) {
47         super(name);
48         this.testFileObj = testFileObj;
49     }
50     
51     public void setUp() {
52         System.out.println("######## "+getName()+" #######");
53     }
54     
55     public void tearDown() {
56         compareReferenceFiles();
57     }
58     
59     public static Test suite() {
60         // find folder with test projects and define file objects filter
61
File JavaDoc datadir = new JspColoringTest(null, null).getDataDir();
62         File JavaDoc projectsDir = new File JavaDoc(datadir, "JspColoringTestProjects");
63         FileObjectFilter filter = new FileObjectFilter() {
64             public boolean accept(FileObject fo) {
65                 String JavaDoc strs[] = new String JavaDoc[] {"jsp", "jspx", "jspf", "html", "tag", "tagx"};
66                 List JavaDoc exts = Arrays.asList(strs);
67                 return fo.getName().startsWith("test") && exts.contains(fo.getExt());
68             }
69         };
70         return RecurrentSuiteFactory.createSuite(JspColoringTest.class, projectsDir, filter);
71     }
72     
73     public void runTest() throws Exception JavaDoc {
74         dumpTokens(testFileObj);
75     }
76     
77     private void dumpTokens(FileObject fileObj) {
78         try {
79             DataObject dataObj = DataObject.find(fileObj);
80             EditorCookie ed = (EditorCookie) dataObj.getCookie(EditorCookie.class);
81             BaseDocument doc = (BaseDocument) ed.openDocument();
82             ExtSyntaxSupport ess = (ExtSyntaxSupport) doc.getSyntaxSupport();
83             TokenItem token = ess.getTokenChain(0, doc.getLength());
84             
85             while (token != null) {
86                 TokenID tokenID = token.getTokenID();
87                 ref(tokenID.getName()+ ": " + token.getImage());
88                 token = token.getNext();
89             }
90         } catch (Exception JavaDoc ex) {
91             throw new AssertionFailedErrorException(ex);
92         }
93     }
94     
95     /** Use for execution inside IDE */
96     public static void main(java.lang.String JavaDoc[] args) {
97         // run whole suite
98
junit.textui.TestRunner.run(suite());
99     }
100 }
101
Popular Tags