source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/taskdefs/CopyTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 5.2 KB
Line 
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
18package org.apache.tools.ant.taskdefs;
19
20import org.apache.tools.ant.BuildFileTest;
21import org.apache.tools.ant.Project;
22import org.apache.tools.ant.util.FileUtils;
23import org.apache.tools.ant.util.JavaEnvUtils;
24import java.io.File;
25import java.io.IOException;
26
27/**
28 * Tests FileSet using the Copy task.
29 *
30 */
31public 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 //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 {
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}
Note: See TracBrowser for help on using the repository browser.