001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.tools.ant.taskdefs.optional.script;
019:
020: import org.apache.tools.ant.BuildFileTest;
021: import org.apache.tools.ant.Project;
022: import org.apache.tools.ant.types.FileSet;
023: import java.io.File;
024:
025: /**
026: * Tests the examples of the <scriptdef> task.
027: *
028: * @since Ant 1.6
029: */
030: public class ScriptDefTest extends BuildFileTest {
031:
032: public ScriptDefTest(String name) {
033: super (name);
034: }
035:
036: /**
037: * The JUnit setup method
038: */
039: public void setUp() {
040: configureProject("src/etc/testcases/taskdefs/optional/script/scriptdef.xml");
041: }
042:
043: public void testSimple() {
044: executeTarget("simple");
045: // get the fileset and its basedir
046: Project p = getProject();
047: FileSet fileset = (FileSet) p.getReference("testfileset");
048: File baseDir = fileset.getDir(p);
049: String log = getLog();
050: assertTrue("Expecting attribute value printed", log
051: .indexOf("Attribute attr1 = test") != -1);
052:
053: assertTrue("Expecting nested element value printed", log
054: .indexOf("Fileset basedir = "
055: + baseDir.getAbsolutePath()) != -1);
056: }
057:
058: public void testNoLang() {
059: expectBuildExceptionContaining("nolang",
060: "Absence of language attribute not detected",
061: "requires a language attribute");
062: }
063:
064: public void testNoName() {
065: expectBuildExceptionContaining("noname",
066: "Absence of name attribute not detected",
067: "scriptdef requires a name attribute");
068: }
069:
070: public void testNestedByClassName() {
071: executeTarget("nestedbyclassname");
072: // get the fileset and its basedir
073: Project p = getProject();
074: FileSet fileset = (FileSet) p.getReference("testfileset");
075: File baseDir = fileset.getDir(p);
076: String log = getLog();
077: assertTrue("Expecting attribute value to be printed", log
078: .indexOf("Attribute attr1 = test") != -1);
079:
080: assertTrue("Expecting nested element value to be printed", log
081: .indexOf("Fileset basedir = "
082: + baseDir.getAbsolutePath()) != -1);
083: }
084:
085: public void testNoElement() {
086: expectOutput("noelement", "Attribute attr1 = test");
087: }
088:
089: public void testException() {
090: expectBuildExceptionContaining("exception",
091: "Should have thrown an exception in the script",
092: "TypeError");
093: }
094:
095: public void testDoubleDef() {
096: executeTarget("doubledef");
097: String log = getLog();
098: assertTrue("Task1 did not execute", log.indexOf("Task1") != -1);
099: assertTrue("Task2 did not execute", log.indexOf("Task2") != -1);
100: }
101:
102: public void testDoubleAttribute() {
103: expectBuildExceptionContaining("doubleAttributeDef",
104: "Should have detected duplicate attribute definition",
105: "attr1 attribute more than once");
106: }
107:
108: public void testProperty() {
109: executeTarget("property");
110: // get the fileset and its basedir
111: String log = getLog();
112: assertTrue("Expecting property in attribute value replaced",
113: log.indexOf("Attribute value = test") != -1);
114: }
115:
116: }
|