1 19 20 package org.netbeans.test.web.core.syntax; 21 22 import java.io.BufferedReader ; 23 import java.io.File ; 24 import java.io.FileReader ; 25 import java.io.IOException ; 26 import junit.framework.Test; 27 import junit.framework.TestSuite; 28 import org.netbeans.api.jsp.lexer.JspTokenId; 29 import org.netbeans.api.lexer.Language; 30 import org.netbeans.editor.BaseDocument; 31 import org.netbeans.editor.BaseKit; 32 import org.netbeans.junit.NbTestCase; 33 import org.netbeans.modules.editor.NbEditorDocument; 34 import org.netbeans.modules.web.core.syntax.JSPKit; 35 import org.netbeans.modules.web.core.syntax.formatting.JspFormatter; 36 37 41 public class JSPFormatterTest extends NbTestCase { 42 private static final String PROP_MIME_TYPE = "mimeType"; 44 48 49 public JSPFormatterTest(String testName) { 50 super(testName); 51 } 52 53 public static Test suite() { 54 TestSuite suite = new TestSuite(JSPFormatterTest.class); 55 56 return suite; 57 } 58 59 61 public void testReformatSample1() throws Exception { 62 testReformat("TestPage1.jsp"); 63 } 64 65 public void testReformatSample2() throws Exception { 66 testReformat("TestPage2.jsp"); 67 } 68 69 public void testIssue82272() throws Exception { 70 testReformat("issue82272.jsp"); 71 } 72 73 public void testIssue83616() throws Exception { 74 testReformat("issue83616.jsp"); 75 } 76 77 79 private void testReformat(String testFileName) throws Exception { 80 System.out.println("testReformat(" + testFileName + ")"); 81 JspFormatter formatter = new JspFormatter(JSPKit.class); 82 BaseDocument doc = createDocument(); 83 84 85 String txtRawJSP = readFileContentToString(new File (new File ( 86 getTestFilesDir(), "testReformat"), testFileName)); 87 88 doc.insertString(0, txtRawJSP, null); 89 formatter.reformat(doc, 0, doc.getLength(), false); 90 getRef().print(doc.getText(0, doc.getLength())); 91 92 compareReferenceFiles(); 93 } 94 95 private String readFileContentToString(File file) throws IOException { 96 StringBuffer buff = new StringBuffer (); 97 BufferedReader rdr = new BufferedReader (new FileReader (file)); 98 99 String line; 100 101 try{ 102 while ((line = rdr.readLine()) != null){ 103 buff.append(line + "\n"); 104 } 105 } finally{ 106 rdr.close(); 107 } 108 109 return buff.toString(); 110 } 111 112 private File getTestFilesDir(){ 113 return new File (new File (getDataDir(), "input"), "JSPFormatterTest"); 114 } 115 116 protected BaseDocument createDocument() { 117 NbEditorDocument doc = new NbEditorDocument(JSPKit.class); 118 doc.putProperty(PROP_MIME_TYPE, BaseKit.getKit(JSPKit.class).getContentType()); 119 doc.putProperty(Language.class, JspTokenId.language()); 121 return doc; 122 } 123 } 124 | Popular Tags |