FileDocCategorySizeDatePackage
JspcTest.javaAPI DocApache Ant 1.706629Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs.optional

JspcTest

public class JspcTest extends org.apache.tools.ant.BuildFileTest
Tests the Jspc task.
created
07 March 2002
since
Ant 1.5

Fields Summary
private File
baseDir
Description of the Field
private File
outDir
Description of the Field
private static final String
TASKDEFS_DIR
Description of the Field
Constructors Summary
public JspcTest(String name)
Constructor for the JspcTest object

param
name Description of Parameter



                   
       
        super(name);
    
Methods Summary
protected voidassertJavaFileCreated(java.lang.String filename)
verify that a named file was created

param
filename Description of Parameter
exception
Exception trouble

        File file = getOutputFile(filename);
        assertTrue("file " + filename + " not found", file.exists());
        assertTrue("file " + filename + " is empty", file.length() > 0);
    
protected voidassertMapped(org.apache.tools.ant.taskdefs.optional.jsp.JspMangler mangler, java.lang.String filename, java.lang.String classname)
assert our mapping rules

param
mangler
param
filename
param
classname

        String mappedname = mangler.mapJspToJavaName(new File(filename));
        assertTrue(filename+" should have mapped to "+classname
                    +" but instead mapped to "+mappedname,
                    classname.equals(mappedname));
    
protected voidexecuteJspCompile(java.lang.String target, java.lang.String javafile)
run a target then verify the named file gets created

param
target Description of Parameter
param
javafile Description of Parameter
exception
Exception trouble

        executeTarget(target);
        assertJavaFileCreated(javafile);
    
protected java.io.FilegetOutputFile(java.lang.String subpath)
Gets the OutputFile attribute of the JspcTest object

param
subpath Description of Parameter
return
The OutputFile value

        return new File(outDir, subpath);
    
public voidsetUp()
The JUnit setup method

        configureProject(TASKDEFS_DIR + "jspc.xml");
        baseDir = new File(System.getProperty("root"), TASKDEFS_DIR);
        outDir = new File(baseDir, "jsp/java");
    
public voidtearDown()
The teardown method for JUnit

        executeTarget("cleanup");
    
public voidtestInvalidClassname()
what happens to 1nvalid-classname

        executeJspCompile("testInvalidClassname",
                "_1nvalid_0002dclassname_jsp.java");
    
public voidtestJasper41()

        JspMangler mangler = new Jasper41Mangler();
        //java keywords are not special
        assertMapped(mangler, "for.jsp", "for_jsp");
        //underscores go in front of invalid start chars
        assertMapped(mangler, "0.jsp", "_0_jsp");
        //underscores at the front get an underscore too
        assertMapped(mangler, "_.jsp", "___jsp");
        //non java char at start => underscore then the the _hex value
        assertMapped(mangler, "-.jsp", "__0002d_jsp");
        //and paths are stripped
        char s = File.separatorChar;
        assertMapped(mangler, "" + s + s + "somewhere" + s + "file" + s + "index.jsp", "index_jsp");
    
public voidtestJasperNameManglerSelection()
verify that we select the appropriate mangler

        JspCompilerAdapter adapter=
                JspCompilerAdapterFactory.getCompiler("jasper", null,null);
        JspMangler mangler=adapter.createMangler();
        assertTrue(mangler instanceof JspNameMangler);
        adapter= JspCompilerAdapterFactory.getCompiler("jasper41", null, null);
        mangler = adapter.createMangler();
        assertTrue(mangler instanceof Jasper41Mangler);
    
public voidtestKeyword()
try a keyword in a file

        executeJspCompile("testKeyword", "default_jsp.java");
    
public voidtestNoTld()
A unit test for JUnit

//         expectBuildExceptionContaining("testNoTld",
//                 "Jasper found an error in a file",
//                 "Java returned: 9");
         expectBuildExceptionContaining("testNoTld",
                 "not found",
                 "Java returned: 9");
    
public voidtestNotAJspFile()
A unit test for JUnit

        executeTarget("testNotAJspFile");
    
public voidtestSimple()
A unit test for JUnit

        executeJspCompile("testSimple", "simple_jsp.java");
    
public voidtestUriroot()
A unit test for JUnit

        executeJspCompile("testUriroot", "uriroot_jsp.java");
    
public voidtestXml()
A unit test for JUnit

        executeJspCompile("testXml", "xml_jsp.java");