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:
019: package org.apache.tools.ant.taskdefs;
020:
021: import org.apache.tools.ant.BuildException;
022: import org.apache.tools.ant.BuildFileTest;
023:
024: /**
025: */
026: public class MacroDefTest extends BuildFileTest {
027: public MacroDefTest(String name) {
028: super (name);
029: }
030:
031: public void setUp() {
032: configureProject("src/etc/testcases/taskdefs/macrodef.xml");
033: }
034:
035: public void testSimple() {
036: expectLog("simple", "Hello World");
037: }
038:
039: public void testText() {
040: expectLog("text", "Inner Text");
041: }
042:
043: public void testDuplicateAttribute() {
044: expectBuildException("duplicate.attribute",
045: "the attribute text has already been specified");
046: }
047:
048: public void testDuplicateElement() {
049: expectBuildException("duplicate.element",
050: "the element text has already been specified");
051: }
052:
053: public void testUri() {
054: expectLog("uri", "Hello World");
055: }
056:
057: public void testNested() {
058: expectLog("nested", "A nested element");
059: }
060:
061: public void testDouble() {
062: expectLog("double",
063: "@{prop} is 'property', value of ${property} is 'A property value'");
064: }
065:
066: public void testIgnoreCase() {
067: expectLog("ignorecase", "a is ab is b");
068: }
069:
070: public void testIgnoreElementCase() {
071: expectLog("ignore-element-case", "nested elementnested element");
072: }
073:
074: public void testTextElement() {
075: expectLogContaining("textelement", "Hello world");
076: }
077:
078: public void testTextTrim() {
079: expectLogContaining("text.trim", "[Hello world]");
080: }
081:
082: public void testDuplicateTextName() {
083: expectBuildException("duplicatetextname",
084: "the name \"text\" is already used as an attribute");
085: }
086:
087: public void testDuplicateTextName2() {
088: expectBuildException("duplicatetextname2",
089: "the attribute name \"text\" has already been used by the text element");
090: }
091:
092: public void testEscape() {
093: expectLog("escape", "a@b or a@b is avalue@bvalue");
094: }
095:
096: public void testAttributeDescription() {
097: expectLog("attribute.description", "description is hello world");
098: }
099:
100: public void testOverrideDefault() {
101: expectLog("override.default", "value is new");
102: }
103:
104: public void testImplicit() {
105: expectLog("implicit",
106: "Before implicitIn implicitAfter implicit");
107: }
108:
109: public void testImplicitNotOptional() {
110: expectSpecificBuildException(
111: "implicit.notoptional",
112: "Missing nested elements for implicit element implicit",
113: "Missing nested elements for implicit element implicit");
114: }
115:
116: public void testImplicitOptional() {
117: expectLog("implicit.optional", "Before implicitAfter implicit");
118: }
119:
120: public void testImplicitExplicit() {
121: expectSpecificBuildException(
122: "implicit.explicit",
123: "Only one element allowed when using implicit elements",
124: "Only one element allowed when using implicit elements");
125: }
126:
127: public void testBackTraceOff() {
128: try {
129: executeTarget("backtraceoff");
130: } catch (BuildException ex) {
131: if (ex.getMessage().indexOf("following error occurred") != -1) {
132: fail("error message contained backtrace - "
133: + ex.getMessage());
134: }
135: }
136: }
137:
138: public void testBackTrace() {
139: expectBuildExceptionContaining("backtraceon",
140: "Checking if a back trace is created",
141: "following error occurred");
142: }
143:
144: public void testTopLevelText() {
145: expectLogContaining("top-level-text", "Hello World");
146: }
147: }
|