1 17 18 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 44 45 public class SymlinkTest extends BuildFileTest { 46 47 private Project p; 48 private boolean supportsSymlinks = Os.isFamily("unix"); 49 50 public SymlinkTest(String 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 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 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 link1Rem = p.getProperty("test.recreate.link1.not.removed"); 147 String link2Rem = p.getProperty("test.recreate.link2.not.removed"); 148 String link3Rem = p.getProperty("test.recreate.link3.not.removed"); 149 String 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 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 |