source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 3.9 KB
Line 
1/*
2 * Copyright 2003-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.apache.tools.ant.taskdefs.optional.script;
18
19import org.apache.tools.ant.BuildFileTest;
20import org.apache.tools.ant.Project;
21import org.apache.tools.ant.types.FileSet;
22import java.io.File;
23
24/**
25 * Tests the examples of the <scriptdef> task.
26 *
27 * @since Ant 1.6
28 */
29public class ScriptDefTest extends BuildFileTest {
30
31 public ScriptDefTest(String name) {
32 super(name);
33 }
34
35 /**
36 * The JUnit setup method
37 */
38 public void setUp() {
39 configureProject("src/etc/testcases/taskdefs/optional/script/scriptdef.xml");
40 }
41
42 public void testSimple() {
43 executeTarget("simple");
44 // get the fileset and its basedir
45 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 // get the fileset and its basedir
71 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 // get the fileset and its basedir
110 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}
Note: See TracBrowser for help on using the repository browser.