KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > FileListTest


1 /*
2  * Copyright 2001,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.types;
19
20 import org.apache.tools.ant.BuildException;
21 import org.apache.tools.ant.Project;
22
23 import junit.framework.TestCase;
24 import junit.framework.AssertionFailedError;
25
26 import java.io.File JavaDoc;
27
28 /**
29  * JUnit 3 testcases for org.apache.tools.ant.types.FileList.
30  *
31  * <p>This doesn't actually test much, mainly reference handling.
32  * Adapted from FileSetTest.</p>
33  *
34  */

35
36 public class FileListTest extends TestCase {
37
38     private Project project;
39
40     public FileListTest(String JavaDoc name) {
41         super(name);
42     }
43
44     public void setUp() {
45         project = new Project();
46         project.setBasedir(".");
47     }
48
49     public void testEmptyElementIfIsReference() {
50         FileList f = new FileList();
51         f.setDir(project.resolveFile("."));
52         try {
53             f.setRefid(new Reference("dummyref"));
54             fail("Can add reference to FileList with directory attribute set.");
55         } catch (BuildException be) {
56             assertEquals("You must not specify more than one attribute when using refid",
57                          be.getMessage());
58         }
59
60         f = new FileList();
61         f.setFiles("foo.xml,c/d/bar.xml");
62         try {
63             f.setRefid(new Reference("dummyref"));
64             fail("Can add reference to FileList with file attribute set.");
65         } catch (BuildException be) {
66             assertEquals("You must not specify more than one attribute when using refid",
67                          be.getMessage());
68         }
69
70         f = new FileList();
71         f.setRefid(new Reference("dummyref"));
72         try {
73             f.setFiles("a/b/foo.java");
74             fail("Can set files in FileList that is a reference.");
75         } catch (BuildException be) {
76             assertEquals("You must not specify more than one attribute when using refid",
77                          be.getMessage());
78         }
79         try {
80             f.setDir(project.resolveFile("."));
81             fail("Can set dir in FileList that is a reference.");
82         } catch (BuildException be) {
83             assertEquals("You must not specify more than one attribute when using refid",
84                          be.getMessage());
85         }
86     }
87
88     public void testCircularReferenceCheck() {
89         FileList f = new FileList();
90         project.addReference("dummy", f);
91         f.setRefid(new Reference("dummy"));
92         try {
93             f.getDir(project);
94             fail("Can make FileList a Reference to itself.");
95         } catch (BuildException be) {
96             assertEquals("This data type contains a circular reference.",
97                          be.getMessage());
98         }
99         try {
100             f.getFiles(project);
101             fail("Can make FileList a Reference to itself.");
102         } catch (BuildException be) {
103             assertEquals("This data type contains a circular reference.",
104                          be.getMessage());
105         }
106
107         // dummy1 --> dummy2 --> dummy3 --> dummy1
108
FileList f1 = new FileList();
109         project.addReference("dummy1", f1);
110         f1.setRefid(new Reference("dummy2"));
111         FileList f2 = new FileList();
112         project.addReference("dummy2", f2);
113         f2.setRefid(new Reference("dummy3"));
114         FileList f3 = new FileList();
115         project.addReference("dummy3", f3);
116         f3.setRefid(new Reference("dummy1"));
117         try {
118             f1.getDir(project);
119             fail("Can make circular reference.");
120         } catch (BuildException be) {
121             assertEquals("This data type contains a circular reference.",
122                          be.getMessage());
123         }
124         try {
125             f1.getFiles(project);
126             fail("Can make circular reference.");
127         } catch (BuildException be) {
128             assertEquals("This data type contains a circular reference.",
129                          be.getMessage());
130         }
131
132         // dummy1 --> dummy2 --> dummy3
133
// (which has the Project's basedir as root).
134
f1 = new FileList();
135         project.addReference("dummy1", f1);
136         f1.setRefid(new Reference("dummy2"));
137         f2 = new FileList();
138         project.addReference("dummy2", f2);
139         f2.setRefid(new Reference("dummy3"));
140         f3 = new FileList();
141         project.addReference("dummy3", f3);
142         f3.setDir(project.resolveFile("."));
143         File JavaDoc dir = f1.getDir(project);
144         assertEquals("Dir is basedir", dir, project.getBaseDir());
145     }
146 }
147
Popular Tags