1 17 package org.apache.tools.ant.taskdefs.optional; 18 19 import java.io.*; 20 import java.util.Properties ; 21 22 import org.apache.tools.ant.BuildFileTest; 23 import org.apache.tools.ant.taskdefs.optional.jsp.JspMangler; 24 import org.apache.tools.ant.taskdefs.optional.jsp.Jasper41Mangler; 25 import org.apache.tools.ant.taskdefs.optional.jsp.JspC; 26 import org.apache.tools.ant.taskdefs.optional.jsp.JspNameMangler; 27 import org.apache.tools.ant.taskdefs.optional.jsp.compilers.JspCompilerAdapterFactory; 28 import org.apache.tools.ant.taskdefs.optional.jsp.compilers.JspCompilerAdapter; 29 30 36 public class JspcTest extends BuildFileTest { 37 40 private File baseDir; 41 44 private File outDir; 45 46 49 private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/"; 50 51 52 57 public JspcTest(String name) { 58 super(name); 59 } 60 61 62 65 public void setUp() { 66 configureProject(TASKDEFS_DIR + "jspc.xml"); 67 baseDir = new File(TASKDEFS_DIR); 68 outDir = new File(baseDir, "jsp/java"); 69 } 70 71 72 75 public void tearDown() { 76 executeTarget("cleanup"); 77 } 78 79 80 83 public void testSimple() throws Exception { 84 executeJspCompile("testSimple", "simple_jsp.java"); 85 } 86 87 88 91 public void testUriroot() throws Exception { 92 executeJspCompile("testUriroot", "uriroot_jsp.java"); 93 } 94 95 96 99 public void testXml() throws Exception { 100 executeJspCompile("testXml", "xml_jsp.java"); 101 } 102 103 104 107 public void testKeyword() throws Exception { 108 executeJspCompile("testKeyword", "default_jsp.java"); 109 } 110 111 112 115 public void testInvalidClassname() throws Exception { 116 executeJspCompile("testInvalidClassname", 117 "_1nvalid_0002dclassname_jsp.java"); 118 } 119 120 121 124 public void testNoTld() throws Exception { 125 expectBuildExceptionContaining("testNoTld", 129 "not found", 130 "Java returned: 9"); 131 } 132 133 134 137 public void testNotAJspFile() throws Exception { 138 executeTarget("testNotAJspFile"); 139 } 140 141 145 150 157 protected void executeJspCompile(String target, String javafile) 158 throws Exception { 159 executeTarget(target); 160 assertJavaFileCreated(javafile); 161 } 162 163 164 170 protected void assertJavaFileCreated(String filename) 171 throws Exception { 172 File file = getOutputFile(filename); 173 assertTrue("file " + filename + " not found", file.exists()); 174 assertTrue("file " + filename + " is empty", file.length() > 0); 175 } 176 177 183 protected File getOutputFile(String subpath) { 184 return new File(outDir, subpath); 185 } 186 187 190 public void testJasperNameManglerSelection() { 191 JspCompilerAdapter adapter= 192 JspCompilerAdapterFactory.getCompiler("jasper", null,null); 193 JspMangler mangler=adapter.createMangler(); 194 assertTrue(mangler instanceof JspNameMangler); 195 adapter= JspCompilerAdapterFactory.getCompiler("jasper41", null, null); 196 mangler = adapter.createMangler(); 197 assertTrue(mangler instanceof Jasper41Mangler); 198 } 199 200 public void testJasper41() { 201 JspMangler mangler = new Jasper41Mangler(); 202 assertMapped(mangler, "for.jsp", "for_jsp"); 204 assertMapped(mangler, "0.jsp", "_0_jsp"); 206 assertMapped(mangler, "_.jsp", "___jsp"); 208 assertMapped(mangler, "-.jsp", "__0002d_jsp"); 210 char s = File.separatorChar; 212 assertMapped(mangler, "" + s + s + "somewhere" + s + "file" + s + "index.jsp", "index_jsp"); 213 } 214 215 221 protected void assertMapped(JspMangler mangler, String filename, String classname) { 222 String mappedname = mangler.mapJspToJavaName(new File(filename)); 223 assertTrue(filename+" should have mapped to "+classname 224 +" but instead mapped to "+mappedname, 225 classname.equals(mappedname)); 226 } 227 228 229 } 230 231 | Popular Tags |