~ubuntu-branches/ubuntu/jaunty/ant/jaunty-proposed

« back to all changes in this revision

Viewing changes to src/testcases/org/apache/tools/ant/types/FileSetTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Gybas
  • Date: 2002-02-14 14:28:48 UTC
  • Revision ID: james.westby@ubuntu.com-20020214142848-2ww7ynmqkj31vlmn
Tags: upstream-1.4.1
ImportĀ upstreamĀ versionĀ 1.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The Apache Software License, Version 1.1
 
3
 *
 
4
 * Copyright (c) 2000 The Apache Software Foundation.  All rights
 
5
 * reserved.
 
6
 *
 
7
 * Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted provided that the following conditions
 
9
 * are met:
 
10
 *
 
11
 * 1. Redistributions of source code must retain the above copyright
 
12
 *    notice, this list of conditions and the following disclaimer.
 
13
 *
 
14
 * 2. Redistributions in binary form must reproduce the above copyright
 
15
 *    notice, this list of conditions and the following disclaimer in
 
16
 *    the documentation and/or other materials provided with the
 
17
 *    distribution.
 
18
 *
 
19
 * 3. The end-user documentation included with the redistribution, if
 
20
 *    any, must include the following acknowlegement:
 
21
 *       "This product includes software developed by the
 
22
 *        Apache Software Foundation (http://www.apache.org/)."
 
23
 *    Alternately, this acknowlegement may appear in the software itself,
 
24
 *    if and wherever such third-party acknowlegements normally appear.
 
25
 *
 
26
 * 4. The names "The Jakarta Project", "Ant", and "Apache Software
 
27
 *    Foundation" must not be used to endorse or promote products derived
 
28
 *    from this software without prior written permission. For written
 
29
 *    permission, please contact apache@apache.org.
 
30
 *
 
31
 * 5. Products derived from this software may not be called "Apache"
 
32
 *    nor may "Apache" appear in their names without prior written
 
33
 *    permission of the Apache Group.
 
34
 *
 
35
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 
36
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
37
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
38
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 
39
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
40
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
41
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 
42
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
43
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
44
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 
45
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
46
 * SUCH DAMAGE.
 
47
 * ====================================================================
 
48
 *
 
49
 * This software consists of voluntary contributions made by many
 
50
 * individuals on behalf of the Apache Software Foundation.  For more
 
51
 * information on the Apache Software Foundation, please see
 
52
 * <http://www.apache.org/>.
 
53
 */
 
54
 
 
55
package org.apache.tools.ant.types;
 
56
 
 
57
import org.apache.tools.ant.BuildException;
 
58
import org.apache.tools.ant.Project;
 
59
 
 
60
import junit.framework.TestCase;
 
61
import junit.framework.AssertionFailedError;
 
62
 
 
63
import java.io.File;
 
64
 
 
65
/**
 
66
 * JUnit 3 testcases for org.apache.tools.ant.types.FileSet.
 
67
 *
 
68
 * <p>This doesn't actually test much, mainly reference handling.
 
69
 *
 
70
 * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
 
71
 */
 
72
 
 
73
public class FileSetTest extends TestCase {
 
74
 
 
75
    private Project project;
 
76
 
 
77
    public FileSetTest(String name) {
 
78
        super(name);
 
79
    }
 
80
 
 
81
    public void setUp() {
 
82
        project = new Project();
 
83
        project.setBasedir(".");
 
84
    }
 
85
 
 
86
    public void testEmptyElementIfIsReference() {
 
87
        FileSet f = new FileSet();
 
88
        f.setIncludes("**/*.java");
 
89
        try {
 
90
            f.setRefid(new Reference("dummyref"));
 
91
            fail("Can add reference to FileSet with elements from setIncludes");
 
92
        } catch (BuildException be) {
 
93
            assertEquals("You must not specify more than one attribute when using refid",
 
94
                         be.getMessage());
 
95
        }
 
96
 
 
97
        f = new FileSet();
 
98
        f.createPatternSet();
 
99
        try {
 
100
            f.setRefid(new Reference("dummyref"));
 
101
            fail("Can add reference to FileSet with nested patternset element.");
 
102
        } catch (BuildException be) {
 
103
            assertEquals("You must not specify nested elements when using refid",
 
104
                         be.getMessage());
 
105
        }
 
106
 
 
107
        f = new FileSet();
 
108
        f.createInclude();
 
109
        try {
 
110
            f.setRefid(new Reference("dummyref"));
 
111
            fail("Can add reference to FileSet with nested include element.");
 
112
        } catch (BuildException be) {
 
113
            assertEquals("You must not specify more than one attribute when using refid",
 
114
                         be.getMessage());
 
115
        }
 
116
 
 
117
        f = new FileSet();
 
118
        f.setRefid(new Reference("dummyref"));
 
119
        try {
 
120
            f.setIncludes("**/*.java");
 
121
            fail("Can set includes in FileSet that is a reference.");
 
122
        } catch (BuildException be) {
 
123
            assertEquals("You must not specify more than one attribute when using refid",
 
124
                         be.getMessage());
 
125
        }
 
126
        try {
 
127
            f.setIncludesfile(new File("/a"));
 
128
            fail("Can set includesfile in FileSet that is a reference.");
 
129
        } catch (BuildException be) {
 
130
            assertEquals("You must not specify more than one attribute when using refid",
 
131
                         be.getMessage());
 
132
        }
 
133
        try {
 
134
            f.setExcludes("**/*.java");
 
135
            fail("Can set excludes in FileSet that is a reference.");
 
136
        } catch (BuildException be) {
 
137
            assertEquals("You must not specify more than one attribute when using refid",
 
138
                         be.getMessage());
 
139
        }
 
140
        try {
 
141
            f.setExcludesfile(new File("/a"));
 
142
            fail("Can set excludesfile in FileSet that is a reference.");
 
143
        } catch (BuildException be) {
 
144
            assertEquals("You must not specify more than one attribute when using refid",
 
145
                         be.getMessage());
 
146
        }
 
147
        try {
 
148
            f.setDir(project.resolveFile("."));
 
149
            fail("Can set dir in FileSet that is a reference.");
 
150
        } catch (BuildException be) {
 
151
            assertEquals("You must not specify more than one attribute when using refid",
 
152
                         be.getMessage());
 
153
        }
 
154
        try {
 
155
            f.createInclude();
 
156
            fail("Can add nested include in FileSet that is a reference.");
 
157
        } catch (BuildException be) {
 
158
            assertEquals("You must not specify nested elements when using refid",
 
159
                         be.getMessage());
 
160
        }
 
161
        try {
 
162
            f.createExclude();
 
163
            fail("Can add nested exclude in FileSet that is a reference.");
 
164
        } catch (BuildException be) {
 
165
            assertEquals("You must not specify nested elements when using refid",
 
166
                         be.getMessage());
 
167
        }
 
168
        try {
 
169
            f.createIncludesFile();
 
170
            fail("Can add nested includesfile in FileSet that is a reference.");
 
171
        } catch (BuildException be) {
 
172
            assertEquals("You must not specify nested elements when using refid",
 
173
                         be.getMessage());
 
174
        }
 
175
        try {
 
176
            f.createExcludesFile();
 
177
            fail("Can add nested excludesfile in FileSet that is a reference.");
 
178
        } catch (BuildException be) {
 
179
            assertEquals("You must not specify nested elements when using refid",
 
180
                         be.getMessage());
 
181
        }
 
182
        try {
 
183
            f.createPatternSet();
 
184
            fail("Can add nested patternset in FileSet that is a reference.");
 
185
        } catch (BuildException be) {
 
186
            assertEquals("You must not specify nested elements when using refid",
 
187
                         be.getMessage());
 
188
        }
 
189
    }
 
190
 
 
191
    public void testCircularReferenceCheck() {
 
192
        FileSet f = new FileSet();
 
193
        project.addReference("dummy", f);
 
194
        f.setRefid(new Reference("dummy"));
 
195
        try {
 
196
            f.getDir(project);
 
197
            fail("Can make FileSet a Reference to itself.");
 
198
        } catch (BuildException be) {
 
199
            assertEquals("This data type contains a circular reference.",
 
200
                         be.getMessage());
 
201
        }
 
202
        try {
 
203
            f.getDirectoryScanner(project);
 
204
            fail("Can make FileSet a Reference to itself.");
 
205
        } catch (BuildException be) {
 
206
            assertEquals("This data type contains a circular reference.",
 
207
                         be.getMessage());
 
208
        }
 
209
 
 
210
        // dummy1 --> dummy2 --> dummy3 --> dummy1
 
211
        FileSet f1 = new FileSet();
 
212
        project.addReference("dummy1", f1);
 
213
        f1.setRefid(new Reference("dummy2"));
 
214
        FileSet f2 = new FileSet();
 
215
        project.addReference("dummy2", f2);
 
216
        f2.setRefid(new Reference("dummy3"));
 
217
        FileSet f3 = new FileSet();
 
218
        project.addReference("dummy3", f3);
 
219
        f3.setRefid(new Reference("dummy1"));
 
220
        try {
 
221
            f1.getDir(project);
 
222
            fail("Can make circular reference.");
 
223
        } catch (BuildException be) {
 
224
            assertEquals("This data type contains a circular reference.",
 
225
                         be.getMessage());
 
226
        }
 
227
        try {
 
228
            f1.getDirectoryScanner(project);
 
229
            fail("Can make circular reference.");
 
230
        } catch (BuildException be) {
 
231
            assertEquals("This data type contains a circular reference.",
 
232
                         be.getMessage());
 
233
        }
 
234
 
 
235
        // dummy1 --> dummy2 --> dummy3 
 
236
        // (which has the Project's basedir as root).
 
237
        f1 = new FileSet();
 
238
        project.addReference("dummy1", f1);
 
239
        f1.setRefid(new Reference("dummy2"));
 
240
        f2 = new FileSet();
 
241
        project.addReference("dummy2", f2);
 
242
        f2.setRefid(new Reference("dummy3"));
 
243
        f3 = new FileSet();
 
244
        project.addReference("dummy3", f3);
 
245
        f3.setDir(project.resolveFile("."));
 
246
        File dir = f1.getDir(project);
 
247
        assertEquals("Die is basedir", dir, project.getBaseDir());
 
248
    }
 
249
}