KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > unix > SymlinkTest


1 /*
2  * Copyright 2002,2004-2005 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 /*
19  * Since the initial version of this file was deveolped on the clock on
20  * an NSF grant I should say the following boilerplate:
21  *
22  * This material is based upon work supported by the National Science
23  * Foundaton under Grant No. EIA-0196404. Any opinions, findings, and
24  * conclusions or recommendations expressed in this material are those
25  * of the author and do not necessarily reflect the views of the
26  * National Science Foundation.
27  */

28
29 package org.apache.tools.ant.taskdefs.optional.unix;
30
31 import org.apache.tools.ant.taskdefs.condition.Os;
32
33 import org.apache.tools.ant.BuildFileTest;
34 import org.apache.tools.ant.Project;
35
36 /**
37  * Test cases for the Symlink task. Link creation, link deletion, recording
38  * of links in multiple directories, and restoration of links recorded are
39  * all tested. A separate test for the utility method Symlink.deleteSymlink
40  * is not included because action="delete" only prints a message and calls
41  * Symlink.deleteSymlink, making a separate test redundant.
42  *
43  */

44
45 public class SymlinkTest extends BuildFileTest {
46
47     private Project p;
48     private boolean supportsSymlinks = Os.isFamily("unix");
49
50     public SymlinkTest(String JavaDoc name) {
51         super(name);
52     }
53
54     public void setUp() {
55         if (supportsSymlinks) {
56             configureProject("src/etc/testcases/taskdefs/optional/unix/symlink.xml");
57             executeTarget("setup");
58         }
59     }
60
61
62     public void testSingle() {
63         if (supportsSymlinks) {
64             executeTarget("test-single");
65             p = getProject();
66             assertNotNull("Failed to create file",
67                           p.getProperty("test.single.file.created"));
68             assertNotNull("Failed to create link",
69                           p.getProperty("test.single.link.created"));
70         }
71     }
72
73     public void testDelete() {
74         if (supportsSymlinks) {
75             executeTarget("test-delete");
76             p = getProject();
77             String JavaDoc linkDeleted = p.getProperty("test.delete.link.still.there");
78             assertNotNull("Actual file deleted by symlink",
79                           p.getProperty("test.delete.file.still.there"));
80             if (linkDeleted != null) {
81                 fail(linkDeleted);
82             }
83         }
84     }
85
86     public void testRecord() {
87         if (supportsSymlinks) {
88             executeTarget("test-record");
89             p = getProject();
90
91             assertNotNull("Failed to create dir1",
92                           p.getProperty("test.record.dir1.created"));
93
94             assertNotNull("Failed to create dir2",
95                           p.getProperty("test.record.dir2.created"));
96
97             assertNotNull("Failed to create file1",
98                           p.getProperty("test.record.file1.created"));
99
100             assertNotNull("Failed to create file2",
101                           p.getProperty("test.record.file2.created"));
102
103             assertNotNull("Failed to create fileA",
104                           p.getProperty("test.record.fileA.created"));
105
106             assertNotNull("Failed to create fileB",
107                           p.getProperty("test.record.fileB.created"));
108
109             assertNotNull("Failed to create fileC",
110                           p.getProperty("test.record.fileC.created"));
111
112             assertNotNull("Failed to create link1",
113                           p.getProperty("test.record.link1.created"));
114
115             assertNotNull("Failed to create link2",
116                           p.getProperty("test.record.link2.created"));
117
118             assertNotNull("Failed to create link3",
119                           p.getProperty("test.record.link3.created"));
120
121             assertNotNull("Failed to create dirlink",
122                           p.getProperty("test.record.dirlink.created"));
123
124             assertNotNull("Failed to create dirlink2",
125                           p.getProperty("test.record.dirlink2.created"));
126
127             assertNotNull("Couldn't record links in dir1",
128                           p.getProperty("test.record.dir1.recorded"));
129
130             assertNotNull("Couldn't record links in dir2",
131                           p.getProperty("test.record.dir2.recorded"));
132
133             String JavaDoc dir3rec = p.getProperty("test.record.dir3.recorded");
134
135             if (dir3rec != null) {
136                 fail(dir3rec);
137             }
138
139         }
140     }
141
142     public void testRecreate() {
143         if (supportsSymlinks) {
144             executeTarget("test-recreate");
145             p = getProject();
146             String JavaDoc link1Rem = p.getProperty("test.recreate.link1.not.removed");
147             String JavaDoc link2Rem = p.getProperty("test.recreate.link2.not.removed");
148             String JavaDoc link3Rem = p.getProperty("test.recreate.link3.not.removed");
149             String JavaDoc dirlinkRem = p.getProperty("test.recreate.dirlink.not.removed");
150             if (link1Rem != null) {
151                 fail(link1Rem);
152             }
153             if (link2Rem != null) {
154                 fail(link2Rem);
155             }
156             if (link3Rem != null) {
157                 fail(link3Rem);
158             }
159             if (dirlinkRem != null) {
160                 fail(dirlinkRem);
161             }
162             assertNotNull("Failed to recreate link1",
163                           p.getProperty("test.recreate.link1.recreated"));
164             assertNotNull("Failed to recreate link2",
165                           p.getProperty("test.recreate.link2.recreated"));
166             assertNotNull("Failed to recreate link3",
167                           p.getProperty("test.recreate.link3.recreated"));
168             assertNotNull("Failed to recreate dirlink",
169                           p.getProperty("test.recreate.dirlink.recreated"));
170             
171             String JavaDoc doubleRecreate = p.getProperty("test.recreate.dirlink2.recreated.twice");
172
173             if (doubleRecreate != null) {
174                 fail(doubleRecreate);
175             }
176
177             assertNotNull("Failed to alter dirlink3",
178                           p.getProperty("test.recreate.dirlink3.was.altered"));
179
180         }
181     }
182
183     public void tearDown() {
184         if (supportsSymlinks) {
185             executeTarget("teardown");
186         }
187     }
188
189 }
190
Popular Tags