1 17 package org.apache.tools.ant.taskdefs.optional.script; 18 19 import org.apache.tools.ant.BuildFileTest; 20 import org.apache.tools.ant.Project; 21 import org.apache.tools.ant.types.FileSet; 22 import java.io.File ; 23 24 29 public class ScriptDefTest extends BuildFileTest { 30 31 public ScriptDefTest(String name) { 32 super(name); 33 } 34 35 38 public void setUp() { 39 configureProject("src/etc/testcases/taskdefs/optional/script/scriptdef.xml"); 40 } 41 42 public void testSimple() { 43 executeTarget("simple"); 44 Project project = getProject(); 46 FileSet fileset = (FileSet) project.getReference("testfileset"); 47 File baseDir = fileset.getDir(project); 48 String log = getLog(); 49 assertTrue("Expecting attribute value printed", 50 log.indexOf("Attribute attr1 = test") != -1); 51 52 assertTrue("Expecting nested element value printed", 53 log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1); 54 } 55 56 public void testNoLang() { 57 expectBuildExceptionContaining("nolang", 58 "Absence of language attribute not detected", 59 "requires a language attribute"); 60 } 61 62 public void testNoName() { 63 expectBuildExceptionContaining("noname", 64 "Absence of name attribute not detected", 65 "scriptdef requires a name attribute"); 66 } 67 68 public void testNestedByClassName() { 69 executeTarget("nestedbyclassname"); 70 Project project = getProject(); 72 FileSet fileset = (FileSet) project.getReference("testfileset"); 73 File baseDir = fileset.getDir(project); 74 String log = getLog(); 75 assertTrue("Expecting attribute value to be printed", 76 log.indexOf("Attribute attr1 = test") != -1); 77 78 assertTrue("Expecting nested element value to be printed", 79 log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1); 80 } 81 82 public void testNoElement() { 83 expectOutput("noelement", "Attribute attr1 = test"); 84 } 85 86 public void testException() { 87 expectBuildExceptionContaining("exception", 88 "Should have thrown an exception in the script", 89 "TypeError"); 90 } 91 92 public void testDoubleDef() { 93 executeTarget("doubledef"); 94 String log = getLog(); 95 assertTrue("Task1 did not execute", 96 log.indexOf("Task1") != -1); 97 assertTrue("Task2 did not execute", 98 log.indexOf("Task2") != -1); 99 } 100 101 public void testDoubleAttribute() { 102 expectBuildExceptionContaining("doubleAttributeDef", 103 "Should have detected duplicate attribute definition", 104 "attr1 attribute more than once"); 105 } 106 107 public void testProperty() { 108 executeTarget("property"); 109 Project project = getProject(); 111 String log = getLog(); 112 assertTrue("Expecting property in attribute value replaced", 113 log.indexOf("Attribute value = test") != -1); 114 } 115 116 117 } 118 | Popular Tags |