001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: /*
020: * Since the initial version of this file was deveolped on the clock on
021: * an NSF grant I should say the following boilerplate:
022: *
023: * This material is based upon work supported by the National Science
024: * Foundaton under Grant No. EIA-0196404. Any opinions, findings, and
025: * conclusions or recommendations expressed in this material are those
026: * of the author and do not necessarily reflect the views of the
027: * National Science Foundation.
028: */
029:
030: package org.apache.tools.ant.taskdefs.optional.unix;
031:
032: import org.apache.tools.ant.taskdefs.condition.Os;
033:
034: import org.apache.tools.ant.BuildFileTest;
035: import org.apache.tools.ant.Project;
036:
037: /**
038: * Test cases for the Symlink task. Link creation, link deletion, recording
039: * of links in multiple directories, and restoration of links recorded are
040: * all tested. A separate test for the utility method Symlink.deleteSymlink
041: * is not included because action="delete" only prints a message and calls
042: * Symlink.deleteSymlink, making a separate test redundant.
043: *
044: */
045:
046: public class SymlinkTest extends BuildFileTest {
047:
048: private Project p;
049: private boolean supportsSymlinks = Os.isFamily("unix");
050:
051: public SymlinkTest(String name) {
052: super (name);
053: }
054:
055: public void setUp() {
056: if (supportsSymlinks) {
057: configureProject("src/etc/testcases/taskdefs/optional/unix/symlink.xml");
058: executeTarget("setup");
059: }
060: }
061:
062: public void testSingle() {
063: if (supportsSymlinks) {
064: executeTarget("test-single");
065: p = getProject();
066: assertNotNull("Failed to create file", p
067: .getProperty("test.single.file.created"));
068: assertNotNull("Failed to create link", p
069: .getProperty("test.single.link.created"));
070: }
071: }
072:
073: public void testDelete() {
074: if (supportsSymlinks) {
075: executeTarget("test-delete");
076: p = getProject();
077: String linkDeleted = p
078: .getProperty("test.delete.link.still.there");
079: assertNotNull("Actual file deleted by symlink", p
080: .getProperty("test.delete.file.still.there"));
081: if (linkDeleted != null) {
082: fail(linkDeleted);
083: }
084: }
085: }
086:
087: public void testRecord() {
088: if (supportsSymlinks) {
089: executeTarget("test-record");
090: p = getProject();
091:
092: assertNotNull("Failed to create dir1", p
093: .getProperty("test.record.dir1.created"));
094:
095: assertNotNull("Failed to create dir2", p
096: .getProperty("test.record.dir2.created"));
097:
098: assertNotNull("Failed to create file1", p
099: .getProperty("test.record.file1.created"));
100:
101: assertNotNull("Failed to create file2", p
102: .getProperty("test.record.file2.created"));
103:
104: assertNotNull("Failed to create fileA", p
105: .getProperty("test.record.fileA.created"));
106:
107: assertNotNull("Failed to create fileB", p
108: .getProperty("test.record.fileB.created"));
109:
110: assertNotNull("Failed to create fileC", p
111: .getProperty("test.record.fileC.created"));
112:
113: assertNotNull("Failed to create link1", p
114: .getProperty("test.record.link1.created"));
115:
116: assertNotNull("Failed to create link2", p
117: .getProperty("test.record.link2.created"));
118:
119: assertNotNull("Failed to create link3", p
120: .getProperty("test.record.link3.created"));
121:
122: assertNotNull("Failed to create dirlink", p
123: .getProperty("test.record.dirlink.created"));
124:
125: assertNotNull("Failed to create dirlink2", p
126: .getProperty("test.record.dirlink2.created"));
127:
128: assertNotNull("Couldn't record links in dir1", p
129: .getProperty("test.record.dir1.recorded"));
130:
131: assertNotNull("Couldn't record links in dir2", p
132: .getProperty("test.record.dir2.recorded"));
133:
134: String dir3rec = p.getProperty("test.record.dir3.recorded");
135:
136: if (dir3rec != null) {
137: fail(dir3rec);
138: }
139:
140: }
141: }
142:
143: public void testRecreate() {
144: if (supportsSymlinks) {
145: executeTarget("test-recreate");
146: p = getProject();
147: String link1Rem = p
148: .getProperty("test.recreate.link1.not.removed");
149: String link2Rem = p
150: .getProperty("test.recreate.link2.not.removed");
151: String link3Rem = p
152: .getProperty("test.recreate.link3.not.removed");
153: String dirlinkRem = p
154: .getProperty("test.recreate.dirlink.not.removed");
155: if (link1Rem != null) {
156: fail(link1Rem);
157: }
158: if (link2Rem != null) {
159: fail(link2Rem);
160: }
161: if (link3Rem != null) {
162: fail(link3Rem);
163: }
164: if (dirlinkRem != null) {
165: fail(dirlinkRem);
166: }
167: assertNotNull("Failed to recreate link1", p
168: .getProperty("test.recreate.link1.recreated"));
169: assertNotNull("Failed to recreate link2", p
170: .getProperty("test.recreate.link2.recreated"));
171: assertNotNull("Failed to recreate link3", p
172: .getProperty("test.recreate.link3.recreated"));
173: assertNotNull("Failed to recreate dirlink", p
174: .getProperty("test.recreate.dirlink.recreated"));
175:
176: String doubleRecreate = p
177: .getProperty("test.recreate.dirlink2.recreated.twice");
178:
179: if (doubleRecreate != null) {
180: fail(doubleRecreate);
181: }
182:
183: assertNotNull("Failed to alter dirlink3", p
184: .getProperty("test.recreate.dirlink3.was.altered"));
185:
186: }
187: }
188:
189: public void tearDown() {
190: if (supportsSymlinks) {
191: executeTarget("teardown");
192: }
193: }
194:
195: }
|