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;
020:
021: import junit.framework.AssertionFailedError;
022:
023: import org.apache.tools.ant.BuildFileTest;
024:
025: /**
026: * Test the build file inclusion using XML entities.
027: *
028: */
029: public class IncludeTest extends BuildFileTest {
030:
031: public IncludeTest(String name) {
032: super (name);
033: }
034:
035: public void test1() {
036: configureProject("src/etc/testcases/core/include/basic/include.xml");
037: expectLog("test1", "from included entity");
038: }
039:
040: public void test2() {
041: configureProject("src/etc/testcases/core/include/frag#ment/include.xml");
042: expectLog("test1", "from included entity");
043: }
044:
045: public void test3() {
046: configureProject("src/etc/testcases/core/include/frag#ment/simple.xml");
047: expectLog("test1", "from simple buildfile");
048: }
049:
050: public void test4() {
051: configureProject("src/etc/testcases/core/include/basic/relative.xml");
052: expectLog("test1", "from included entity");
053: }
054:
055: public void test5() {
056: configureProject("src/etc/testcases/core/include/frag#ment/relative.xml");
057: expectLog("test1", "from included entity");
058: }
059:
060: public void testParseErrorInIncluding() {
061: try {
062: configureProject("src/etc/testcases/core/include/including_file_parse_error/build.xml");
063: fail("should have caused a parser exception");
064: } catch (BuildException e) {
065: assertTrue(e.getLocation().toString()
066: + " should refer to build.xml", e.getLocation()
067: .toString().indexOf("build.xml:") > -1);
068: }
069: }
070:
071: public void testTaskErrorInIncluding() {
072: configureProject("src/etc/testcases/core/include/including_file_task_error/build.xml");
073: try {
074: executeTarget("test");
075: fail("should have cause a build failure");
076: } catch (BuildException e) {
077: assertTrue(e.getMessage()
078: + " should start with \'Warning: Could not find", e
079: .getMessage().startsWith(
080: "Warning: Could not find file "));
081: assertTrue(e.getLocation().toString()
082: + " should end with build.xml:14: ", e
083: .getLocation().toString()
084: .endsWith("build.xml:14: "));
085: }
086: }
087:
088: public void testParseErrorInIncluded() {
089: try {
090: configureProject("src/etc/testcases/core/include/included_file_parse_error/build.xml");
091: fail("should have caused a parser exception");
092: } catch (BuildException e) {
093: assertTrue(e.getLocation().toString()
094: + " should refer to included_file.xml", e
095: .getLocation().toString().indexOf(
096: "included_file.xml:") > -1);
097: }
098: }
099:
100: public void testTaskErrorInIncluded() {
101: configureProject("src/etc/testcases/core/include/included_file_task_error/build.xml");
102: try {
103: executeTarget("test");
104: fail("should have cause a build failure");
105: } catch (BuildException e) {
106: assertTrue(e.getMessage()
107: + " should start with \'Warning: Could not find", e
108: .getMessage().startsWith(
109: "Warning: Could not find file "));
110: assertTrue(e.getLocation().toString()
111: + " should end with included_file.xml:2: ", e
112: .getLocation().toString().endsWith(
113: "included_file.xml:2: "));
114: }
115: }
116:
117: public void testWithSpaceInclude() {
118: configureProject("src/etc/testcases/core/include/with space/include.xml");
119: try {
120: expectLog("test1", "from included entity in 'with space'");
121: } catch (Throwable t) {
122: throw new AssertionFailedError(t.toString() + "; log=\n"
123: + getFullLog());
124: }
125: }
126:
127: public void testWithSpaceSimple() {
128: configureProject("src/etc/testcases/core/include/with space/simple.xml");
129: expectLog("test1", "from simple buildfile in 'with space'");
130: }
131:
132: public void testWithSpaceRelative() {
133: configureProject("src/etc/testcases/core/include/with space/relative.xml");
134: expectLog("test1", "from included entity in 'with space'");
135: }
136:
137: }
|