KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > IncludeTest


1 /*
2  * Copyright 2001-2002,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  */

17
18 package org.apache.tools.ant;
19
20 import org.apache.tools.ant.BuildFileTest;
21
22 /**
23  * Test the build file inclusion using XML entities.
24  *
25  */

26 public class IncludeTest extends BuildFileTest {
27
28     public IncludeTest(String JavaDoc name) {
29         super(name);
30     }
31
32     public void test1() {
33         configureProject("src/etc/testcases/core/include/basic/include.xml");
34         expectLog("test1", "from included entity");
35     }
36
37     public void test2() {
38         configureProject("src/etc/testcases/core/include/frag#ment/include.xml");
39         expectLog("test1", "from included entity");
40     }
41
42     public void test3() {
43         configureProject("src/etc/testcases/core/include/frag#ment/simple.xml");
44         expectLog("test1", "from simple buildfile");
45     }
46
47     public void test4() {
48         configureProject("src/etc/testcases/core/include/basic/relative.xml");
49         expectLog("test1", "from included entity");
50     }
51
52     public void test5() {
53         configureProject("src/etc/testcases/core/include/frag#ment/relative.xml");
54         expectLog("test1", "from included entity");
55     }
56
57     public void testParseErrorInIncluding() {
58         try {
59             configureProject("src/etc/testcases/core/include/including_file_parse_error/build.xml");
60             fail("should have caused a parser exception");
61         } catch (BuildException e) {
62             assertTrue(e.getLocation().toString()
63                        + " should refer to build.xml",
64                        e.getLocation().toString().indexOf("build.xml:") > -1);
65         }
66     }
67
68     public void testTaskErrorInIncluding() {
69         configureProject("src/etc/testcases/core/include/including_file_task_error/build.xml");
70         try {
71             executeTarget("test");
72             fail("should have cause a build failure");
73         } catch (BuildException e) {
74             assertTrue(e.getMessage()
75                        + " should start with \'Warning: Could not find",
76                          e.getMessage().startsWith("Warning: Could not find file "));
77             assertTrue(e.getLocation().toString()
78                        + " should end with build.xml:14: ",
79                        e.getLocation().toString().endsWith("build.xml:14: "));
80         }
81     }
82
83     public void testParseErrorInIncluded() {
84         try {
85             configureProject("src/etc/testcases/core/include/included_file_parse_error/build.xml");
86             fail("should have caused a parser exception");
87         } catch (BuildException e) {
88             assertTrue(e.getLocation().toString()
89                        + " should refer to included_file.xml",
90                        e.getLocation().toString()
91                        .indexOf("included_file.xml:") > -1);
92         }
93     }
94
95     public void testTaskErrorInIncluded() {
96         configureProject("src/etc/testcases/core/include/included_file_task_error/build.xml");
97         try {
98             executeTarget("test");
99             fail("should have cause a build failure");
100         } catch (BuildException e) {
101             assertTrue(e.getMessage()
102                        + " should start with \'Warning: Could not find",
103                          e.getMessage().startsWith("Warning: Could not find file "));
104             assertTrue(e.getLocation().toString()
105                        + " should end with included_file.xml:2: ",
106                        e.getLocation().toString().endsWith("included_file.xml:2: "));
107         }
108     }
109
110     public void testWithSpaceInclude() {
111         configureProject("src/etc/testcases/core/include/with space/include.xml");
112         expectLog("test1", "from included entity in 'with space'");
113     }
114
115     public void testWithSpaceSimple() {
116         configureProject("src/etc/testcases/core/include/with space/simple.xml");
117         expectLog("test1", "from simple buildfile in 'with space'");
118     }
119
120     public void testWithSpaceRelative() {
121         configureProject("src/etc/testcases/core/include/with space/relative.xml");
122         expectLog("test1", "from included entity in 'with space'");
123     }
124
125 }
126
Popular Tags