1 19 20 package org.netbeans.modules.web.jspparser; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.PrintStream ; 25 import java.util.StringTokenizer ; 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 40 public class FastScanTest extends NbTestCase { 41 42 45 public FastScanTest(String testName) { 46 super(testName); 47 } 48 49 public void testPage1() throws Exception { 50 doFastScanTest("jspparser-data/wmroot", "subdir/Page1.jsp", new JspParserAPI.JspOpenInfo(false, "ISO-8859-1")); 51 52 } 53 54 public void testXMLFromExamples1() throws Exception { 55 doFastScanTest("project3/web", "xml/xml.jsp", new JspParserAPI.JspOpenInfo(true, "UTF-8")); 56 } 57 58 public void testXMLFromExamples2() throws Exception { 59 doFastScanTest("project3/web", "jsp2/jspx/basic.jspx", new JspParserAPI.JspOpenInfo(true, "UTF-8")); 60 } 61 62 public void doFastScanTest(String wmRootPath, String path, JspParserAPI.JspOpenInfo correctInfo) throws Exception { 63 try{ 64 FileObject wmRoot = TestUtil.getFileInWorkDir(wmRootPath, this); 65 StringTokenizer st = new StringTokenizer (path, "/"); 66 FileObject tempFile = wmRoot; 67 String ss; 68 while (st.hasMoreTokens()) { 69 tempFile = tempFile.getFileObject(st.nextToken()); 70 } 71 parseIt(wmRoot, tempFile, correctInfo); 72 }catch(RuntimeException 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 { 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 |