KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > CopyTest


1 /*
2  * Copyright 2000-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.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 JavaDoc;
25 import java.io.IOException JavaDoc;
26
27 /**
28  * Tests FileSet using the Copy task.
29  *
30  */

31 public class CopyTest extends BuildFileTest {
32
33     public CopyTest(String JavaDoc 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 JavaDoc f = new File JavaDoc(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 JavaDoc f = new File JavaDoc(getProjectDir(), "copytest1dir/copy.xml");
56         if ( !f.exists()) {
57             fail("Copy failed");
58         }
59     }
60
61     public void test3() {
62         executeTarget("test3");
63         File JavaDoc file3 = new File JavaDoc(getProjectDir(), "copytest3.tmp");
64         assertTrue(file3.exists());
65         File JavaDoc file3a = new File JavaDoc(getProjectDir(), "copytest3a.tmp");
66         assertTrue(file3a.exists());
67         File JavaDoc file3b = new File JavaDoc(getProjectDir(), "copytest3b.tmp");
68         assertTrue(file3b.exists());
69         File JavaDoc file3c = new File JavaDoc(getProjectDir(), "copytest3c.tmp");
70         assertTrue(file3c.exists());
71
72         //file length checks rely on touch generating a zero byte file
73
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         //file time checks for java1.2+
84
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 JavaDoc {
102         executeTarget("testFilterSet");
103         FileUtils fileUtils = FileUtils.newFileUtils();
104         File JavaDoc tmp = new File JavaDoc(getProjectDir(), "copy.filterset.tmp");
105         File JavaDoc check = new File JavaDoc(getProjectDir(), "expected/copy.filterset.filtered");
106         assertTrue(tmp.exists());
107         assertTrue(fileUtils.contentEquals(tmp, check));
108     }
109
110     public void testFilterChain() throws IOException JavaDoc {
111         executeTarget("testFilterChain");
112         FileUtils fileUtils = FileUtils.newFileUtils();
113         File JavaDoc tmp = new File JavaDoc(getProjectDir(), "copy.filterchain.tmp");
114         File JavaDoc check = new File JavaDoc(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 JavaDoc file = new File JavaDoc(getProjectDir(),
122                                         "copytest_single_file_fileset.tmp");
123         assertTrue(file.exists());
124     }
125
126     public void testTranscoding() throws IOException JavaDoc {
127         executeTarget("testTranscoding");
128         FileUtils fileUtils = FileUtils.newFileUtils();
129         File JavaDoc f1 = getProject().resolveFile("copy/expected/utf-8");
130         File JavaDoc 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