1 17 18 package org.apache.tools.ant.taskdefs; 19 20 import org.apache.tools.ant.BuildFileTest; 21 import org.apache.tools.ant.Project; 22 import org.apache.tools.ant.util.FileUtils; 23 import org.apache.tools.ant.util.JavaEnvUtils; 24 import java.io.File ; 25 import java.io.IOException ; 26 27 31 public class CopyTest extends BuildFileTest { 32 33 public CopyTest(String name) { 34 super(name); 35 } 36 37 public void setUp() { 38 configureProject("src/etc/testcases/taskdefs/copy.xml"); 39 } 40 41 public void test1() { 42 executeTarget("test1"); 43 File f = new File (getProjectDir(), "copytest1.tmp"); 44 if ( !f.exists()) { 45 fail("Copy failed"); 46 } 47 } 48 49 public void tearDown() { 50 executeTarget("cleanup"); 51 } 52 53 public void test2() { 54 executeTarget("test2"); 55 File f = new File (getProjectDir(), "copytest1dir/copy.xml"); 56 if ( !f.exists()) { 57 fail("Copy failed"); 58 } 59 } 60 61 public void test3() { 62 executeTarget("test3"); 63 File file3 = new File (getProjectDir(), "copytest3.tmp"); 64 assertTrue(file3.exists()); 65 File file3a = new File (getProjectDir(), "copytest3a.tmp"); 66 assertTrue(file3a.exists()); 67 File file3b = new File (getProjectDir(), "copytest3b.tmp"); 68 assertTrue(file3b.exists()); 69 File file3c = new File (getProjectDir(), "copytest3c.tmp"); 70 assertTrue(file3c.exists()); 71 72 if(file3.length()==0) { 74 fail("could not overwrite an existing, older file"); 75 } 76 if(file3c.length()!=0) { 77 fail("could not force overwrite an existing, newer file"); 78 } 79 if(file3b.length()==0) { 80 fail("unexpectedly overwrote an existing, newer file"); 81 } 82 83 if (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) { 85 assertTrue(file3a.lastModified()==file3.lastModified()); 86 assertTrue(file3c.lastModified()<file3a.lastModified()); 87 } 88 89 } 90 91 public void testFilterTest() { 92 executeTarget("filtertest"); 93 assertTrue(getOutput().indexOf("loop in tokens") == -1); 94 } 95 96 public void testInfiniteFilter() { 97 executeTarget("infinitetest"); 98 assertTrue(getOutput().indexOf("loop in tokens") != -1); 99 } 100 101 public void testFilterSet() throws IOException { 102 executeTarget("testFilterSet"); 103 FileUtils fileUtils = FileUtils.newFileUtils(); 104 File tmp = new File (getProjectDir(), "copy.filterset.tmp"); 105 File check = new File (getProjectDir(), "expected/copy.filterset.filtered"); 106 assertTrue(tmp.exists()); 107 assertTrue(fileUtils.contentEquals(tmp, check)); 108 } 109 110 public void testFilterChain() throws IOException { 111 executeTarget("testFilterChain"); 112 FileUtils fileUtils = FileUtils.newFileUtils(); 113 File tmp = new File (getProjectDir(), "copy.filterchain.tmp"); 114 File check = new File (getProjectDir(), "expected/copy.filterset.filtered"); 115 assertTrue(tmp.exists()); 116 assertTrue(fileUtils.contentEquals(tmp, check)); 117 } 118 119 public void testSingleFileFileset() { 120 executeTarget("test_single_file_fileset"); 121 File file = new File (getProjectDir(), 122 "copytest_single_file_fileset.tmp"); 123 assertTrue(file.exists()); 124 } 125 126 public void testTranscoding() throws IOException { 127 executeTarget("testTranscoding"); 128 FileUtils fileUtils = FileUtils.newFileUtils(); 129 File f1 = getProject().resolveFile("copy/expected/utf-8"); 130 File f2 = getProject().resolveFile("copytest1.tmp"); 131 assertTrue(fileUtils.contentEquals(f1, f2)); 132 } 133 134 public void testMissingFileIgnore() { 135 expectLogContaining("testMissingFileIgnore", 136 "Warning: Could not find file "); 137 } 138 139 public void testMissingFileBail() { 140 expectBuildException("testMissingFileBail", "not-there doesn't exist"); 141 assertTrue(getBuildException().getMessage() 142 .startsWith("Warning: Could not find file ")); 143 } 144 145 public void testMissingDirIgnore() { 146 expectLogContaining("testMissingDirIgnore", "Warning: "); 147 } 148 149 public void testMissingDirBail() { 150 expectBuildException("testMissingDirBail", "not-there doesn't exist"); 151 assertTrue(getBuildException().getMessage().endsWith(" not found.")); 152 } 153 } 154 | Popular Tags |