source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/types/AbstractFileSetTest.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: 8.9 KB
Line 
1/*
2 * Copyright 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
18package org.apache.tools.ant.types;
19
20import org.apache.tools.ant.BuildException;
21import org.apache.tools.ant.Project;
22
23import junit.framework.TestCase;
24import junit.framework.AssertionFailedError;
25
26import java.io.File;
27
28/**
29 * Base class for FileSetTest and DirSetTest.
30 *
31 * <p>This doesn't actually test much, mainly reference handling.
32 *
33 */
34
35public abstract class AbstractFileSetTest extends TestCase {
36
37 private Project project;
38
39 public AbstractFileSetTest(String name) {
40 super(name);
41 }
42
43 public void setUp() {
44 project = new Project();
45 project.setBasedir(".");
46 }
47
48 protected abstract AbstractFileSet getInstance();
49
50 protected final Project getProject() {
51 return project;
52 }
53
54 public final void testEmptyElementIfIsReference() {
55 AbstractFileSet f = getInstance();
56 f.setIncludes("**/*.java");
57 try {
58 f.setRefid(new Reference("dummyref"));
59 fail("Can add reference to "
60 + f.getDataTypeName()
61 + " with elements from setIncludes");
62 } catch (BuildException be) {
63 assertEquals("You must not specify more than one attribute "
64 + "when using refid", be.getMessage());
65 }
66
67 f = getInstance();
68 f.createPatternSet();
69 try {
70 f.setRefid(new Reference("dummyref"));
71 fail("Can add reference to "
72 + f.getDataTypeName()
73 + " with nested patternset element.");
74 } catch (BuildException be) {
75 assertEquals("You must not specify nested elements when "
76 + "using refid", be.getMessage());
77 }
78
79 f = getInstance();
80 f.createInclude();
81 try {
82 f.setRefid(new Reference("dummyref"));
83 fail("Can add reference to "
84 + f.getDataTypeName()
85 + " with nested include element.");
86 } catch (BuildException be) {
87 assertEquals("You must not specify more than one attribute "
88 + "when using refid", be.getMessage());
89 }
90
91 f = getInstance();
92 f.setRefid(new Reference("dummyref"));
93 try {
94 f.setIncludes("**/*.java");
95 fail("Can set includes in "
96 + f.getDataTypeName()
97 + " that is a reference.");
98 } catch (BuildException be) {
99 assertEquals("You must not specify more than one attribute "
100 + "when using refid", be.getMessage());
101 }
102 try {
103 f.setIncludesfile(new File("/a"));
104 fail("Can set includesfile in "
105 + f.getDataTypeName()
106 + " that is a reference.");
107 } catch (BuildException be) {
108 assertEquals("You must not specify more than one attribute "
109 + "when using refid", be.getMessage());
110 }
111 try {
112 f.setExcludes("**/*.java");
113 fail("Can set excludes in "
114 + f.getDataTypeName()
115 + " that is a reference.");
116 } catch (BuildException be) {
117 assertEquals("You must not specify more than one attribute "
118 + "when using refid", be.getMessage());
119 }
120 try {
121 f.setExcludesfile(new File("/a"));
122 fail("Can set excludesfile in "
123 + f.getDataTypeName()
124 + " that is a reference.");
125 } catch (BuildException be) {
126 assertEquals("You must not specify more than one attribute "
127 + "when using refid", be.getMessage());
128 }
129 try {
130 f.setDir(project.resolveFile("."));
131 fail("Can set dir in "
132 + f.getDataTypeName()
133 + " that is a reference.");
134 } catch (BuildException be) {
135 assertEquals("You must not specify more than one attribute "
136 + "when using refid", be.getMessage());
137 }
138 try {
139 f.createInclude();
140 fail("Can add nested include in "
141 + f.getDataTypeName()
142 + " that is a reference.");
143 } catch (BuildException be) {
144 assertEquals("You must not specify nested elements when using "
145 + "refid", be.getMessage());
146 }
147 try {
148 f.createExclude();
149 fail("Can add nested exclude in "
150 + f.getDataTypeName()
151 + " that is a reference.");
152 } catch (BuildException be) {
153 assertEquals("You must not specify nested elements when using "
154 + "refid", be.getMessage());
155 }
156 try {
157 f.createIncludesFile();
158 fail("Can add nested includesfile in "
159 + f.getDataTypeName()
160 + " that is a reference.");
161 } catch (BuildException be) {
162 assertEquals("You must not specify nested elements when using "
163 + "refid", be.getMessage());
164 }
165 try {
166 f.createExcludesFile();
167 fail("Can add nested excludesfile in "
168 + f.getDataTypeName()
169 + " that is a reference.");
170 } catch (BuildException be) {
171 assertEquals("You must not specify nested elements when using "
172 + "refid", be.getMessage());
173 }
174 try {
175 f.createPatternSet();
176 fail("Can add nested patternset in "
177 + f.getDataTypeName()
178 + " that is a reference.");
179 } catch (BuildException be) {
180 assertEquals("You must not specify nested elements when using "
181 + "refid", be.getMessage());
182 }
183 }
184
185 public void testCircularReferenceCheck() {
186 AbstractFileSet f = getInstance();
187 project.addReference("dummy", f);
188 f.setRefid(new Reference("dummy"));
189 try {
190 f.getDir(project);
191 fail("Can make " + f.getDataTypeName()
192 + " a Reference to itself.");
193 } catch (BuildException be) {
194 assertEquals("This data type contains a circular reference.",
195 be.getMessage());
196 }
197 try {
198 f.getDirectoryScanner(project);
199 fail("Can make " + f.getDataTypeName()
200 + " a Reference to itself.");
201 } catch (BuildException be) {
202 assertEquals("This data type contains a circular reference.",
203 be.getMessage());
204 }
205
206 // dummy1 --> dummy2 --> dummy3 --> dummy1
207 AbstractFileSet f1 = getInstance();
208 project.addReference("dummy1", f1);
209 f1.setRefid(new Reference("dummy2"));
210 AbstractFileSet f2 = getInstance();
211 project.addReference("dummy2", f2);
212 f2.setRefid(new Reference("dummy3"));
213 AbstractFileSet f3 = getInstance();
214 project.addReference("dummy3", f3);
215 f3.setRefid(new Reference("dummy1"));
216 try {
217 f1.getDir(project);
218 fail("Can make circular reference.");
219 } catch (BuildException be) {
220 assertEquals("This data type contains a circular reference.",
221 be.getMessage());
222 }
223 try {
224 f1.getDirectoryScanner(project);
225 fail("Can make circular reference.");
226 } catch (BuildException be) {
227 assertEquals("This data type contains a circular reference.",
228 be.getMessage());
229 }
230
231 // dummy1 --> dummy2 --> dummy3
232 // (which has the Project's basedir as root).
233 f1 = getInstance();
234 project.addReference("dummy1", f1);
235 f1.setRefid(new Reference("dummy2"));
236 f2 = getInstance();
237 project.addReference("dummy2", f2);
238 f2.setRefid(new Reference("dummy3"));
239 f3 = getInstance();
240 project.addReference("dummy3", f3);
241 f3.setDir(project.resolveFile("."));
242 File dir = f1.getDir(project);
243 assertEquals("Dir is basedir", dir, project.getBaseDir());
244 }
245}
Note: See TracBrowser for help on using the repository browser.