KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jspparser > FastScanTest


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.web.jspparser;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.PrintStream JavaDoc;
25 import java.util.StringTokenizer JavaDoc;
26
27 import junit.framework.*;
28 import org.netbeans.junit.*;
29 import org.netbeans.modules.web.jsps.parserapi.JspParserAPI;
30 import org.netbeans.modules.web.jsps.parserapi.JspParserFactory;
31 import org.openide.filesystems.FileObject;
32 import org.openide.filesystems.FileUtil;
33 import org.openide.filesystems.Repository;
34
35 /** JUnit test suite with Jemmy support
36  *
37  * @author pj97932
38  * @version 1.0
39  */

40 public class FastScanTest extends NbTestCase {
41     
42     /** constructor required by JUnit
43      * @param testName method name to be used as testcase
44      */

45     public FastScanTest(String JavaDoc testName) {
46         super(testName);
47     }
48     
49     public void testPage1() throws Exception JavaDoc {
50         doFastScanTest("jspparser-data/wmroot", "subdir/Page1.jsp", new JspParserAPI.JspOpenInfo(false, "ISO-8859-1"));
51         
52     }
53     
54     public void testXMLFromExamples1() throws Exception JavaDoc {
55         doFastScanTest("project3/web", "xml/xml.jsp", new JspParserAPI.JspOpenInfo(true, "UTF-8"));
56     }
57     
58     public void testXMLFromExamples2() throws Exception JavaDoc {
59         doFastScanTest("project3/web", "jsp2/jspx/basic.jspx", new JspParserAPI.JspOpenInfo(true, "UTF-8"));
60     }
61     
62     public void doFastScanTest(String JavaDoc wmRootPath, String JavaDoc path, JspParserAPI.JspOpenInfo correctInfo) throws Exception JavaDoc {
63         try{
64             FileObject wmRoot = TestUtil.getFileInWorkDir(wmRootPath, this);
65             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(path, "/");
66             FileObject tempFile = wmRoot;
67             String JavaDoc ss;
68             while (st.hasMoreTokens()) {
69                 tempFile = tempFile.getFileObject(st.nextToken());
70             }
71             parseIt(wmRoot, tempFile, correctInfo);
72         }catch(RuntimeException JavaDoc e){
73             e.printStackTrace();
74             e.printStackTrace(getRef());
75             fail("Initialization of test failed! ->" + e);
76         }
77     }
78     
79     private void parseIt(FileObject root, FileObject jspFile, JspParserAPI.JspOpenInfo correctInfo) throws Exception JavaDoc {
80         log("calling parseIt, root: " + root + " file: " + jspFile);
81         JspParserAPI api = JspParserFactory.getJspParser();
82         JspParserAPI.JspOpenInfo info = api.getJspOpenInfo(jspFile, TestUtil.getWebModule(jspFile), false);
83         log("file: " + jspFile + " enc: " + info.getEncoding() + " isXML: " + info.isXmlSyntax());
84         assertEquals(correctInfo, info);
85     }
86     
87 }
88
Popular Tags