FileDocCategorySizeDatePackage
ScriptDefTest.javaAPI DocApache Ant 1.703956Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs.optional.script

ScriptDefTest

public class ScriptDefTest extends org.apache.tools.ant.BuildFileTest
Tests the examples of the <scriptdef> task.
since
Ant 1.6

Fields Summary
Constructors Summary
public ScriptDefTest(String name)

        super(name);
    
Methods Summary
public voidsetUp()
The JUnit setup method

        configureProject("src/etc/testcases/taskdefs/optional/script/scriptdef.xml");
    
public voidtestDoubleAttribute()

        expectBuildExceptionContaining("doubleAttributeDef",
            "Should have detected duplicate attribute definition",
            "attr1 attribute more than once");
    
public voidtestDoubleDef()

        executeTarget("doubledef");
        String log = getLog();
        assertTrue("Task1 did not execute",
            log.indexOf("Task1") != -1);
        assertTrue("Task2 did not execute",
            log.indexOf("Task2") != -1);
    
public voidtestException()

        expectBuildExceptionContaining("exception",
            "Should have thrown an exception in the script",
            "TypeError");
    
public voidtestNestedByClassName()

        executeTarget("nestedbyclassname");
        // get the fileset and its basedir
        Project p = getProject();
        FileSet fileset = (FileSet) p.getReference("testfileset");
        File baseDir = fileset.getDir(p);
        String log = getLog();
        assertTrue("Expecting attribute value to be printed",
            log.indexOf("Attribute attr1 = test") != -1);

        assertTrue("Expecting nested element value to be printed",
            log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1);
    
public voidtestNoElement()

        expectOutput("noelement", "Attribute attr1 = test");
    
public voidtestNoLang()

        expectBuildExceptionContaining("nolang",
            "Absence of language attribute not detected",
            "requires a language attribute");
    
public voidtestNoName()

        expectBuildExceptionContaining("noname",
            "Absence of name attribute not detected",
            "scriptdef requires a name attribute");
    
public voidtestProperty()

        executeTarget("property");
        // get the fileset and its basedir
        String log = getLog();
        assertTrue("Expecting property in attribute value replaced",
            log.indexOf("Attribute value = test") != -1);
    
public voidtestSimple()

        executeTarget("simple");
        // get the fileset and its basedir
        Project p = getProject();
        FileSet fileset = (FileSet) p.getReference("testfileset");
        File baseDir = fileset.getDir(p);
        String log = getLog();
        assertTrue("Expecting attribute value printed",
            log.indexOf("Attribute attr1 = test") != -1);

        assertTrue("Expecting nested element value printed",
            log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1);