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: package org.apache.tools.ant.taskdefs;
020:
021: import org.apache.tools.ant.BuildFileTest;
022: import org.apache.tools.ant.util.FileUtils;
023: import java.io.File;
024: import java.io.IOException;
025:
026: /**
027: * Tests the Move task.
028: *
029: */
030: public class MoveTest extends BuildFileTest {
031:
032: /** Utilities used for file operations */
033: private static final FileUtils FILE_UTILS = FileUtils
034: .getFileUtils();
035:
036: public MoveTest(String name) {
037: super (name);
038: }
039:
040: public void setUp() {
041: configureProject("src/etc/testcases/taskdefs/move.xml");
042: }
043:
044: public void tearDown() {
045: executeTarget("cleanup");
046: }
047:
048: public void testFilterSet() throws IOException {
049: executeTarget("testFilterSet");
050: File tmp = new File(getProjectDir(), "move.filterset.tmp");
051: File check = new File(getProjectDir(),
052: "expected/copy.filterset.filtered");
053: assertTrue(tmp.exists());
054: assertTrue(FILE_UTILS.contentEquals(tmp, check));
055: }
056:
057: public void testFilterChain() throws IOException {
058: executeTarget("testFilterChain");
059: File tmp = new File(getProjectDir(), "move.filterchain.tmp");
060: File check = new File(getProjectDir(),
061: "expected/copy.filterset.filtered");
062: assertTrue(tmp.exists());
063: assertTrue(FILE_UTILS.contentEquals(tmp, check));
064: }
065:
066: /** Bugzilla Report 11732 */
067: public void testDirectoryRemoval() throws IOException {
068: executeTarget("testDirectoryRemoval");
069: assertTrue(!getProject().resolveFile("E/B/1").exists());
070: assertTrue(getProject().resolveFile("E/C/2").exists());
071: assertTrue(getProject().resolveFile("E/D/3").exists());
072: assertTrue(getProject().resolveFile("A/B/1").exists());
073: assertTrue(!getProject().resolveFile("A/C/2").exists());
074: assertTrue(!getProject().resolveFile("A/D/3").exists());
075: assertTrue(!getProject().resolveFile("A/C").exists());
076: assertTrue(!getProject().resolveFile("A/D").exists());
077: }
078:
079: /** Bugzilla Report 18886 */
080: public void testDirectoryRetaining() throws IOException {
081: executeTarget("testDirectoryRetaining");
082: assertTrue(getProject().resolveFile("E").exists());
083: assertTrue(getProject().resolveFile("E/1").exists());
084: assertTrue(!getProject().resolveFile("A/1").exists());
085: assertTrue(getProject().resolveFile("A").exists());
086: }
087:
088: public void testCompleteDirectoryMove() throws IOException {
089: testCompleteDirectoryMove("testCompleteDirectoryMove");
090: }
091:
092: public void testCompleteDirectoryMove2() throws IOException {
093: testCompleteDirectoryMove("testCompleteDirectoryMove2");
094: }
095:
096: private void testCompleteDirectoryMove(String target)
097: throws IOException {
098: executeTarget(target);
099: assertTrue(getProject().resolveFile("E").exists());
100: assertTrue(getProject().resolveFile("E/1").exists());
101: assertTrue(!getProject().resolveFile("A/1").exists());
102: // <path> swallows the basedir, it seems
103: //assertTrue(!getProject().resolveFile("A").exists());
104: }
105:
106: public void testPathElementMove() throws IOException {
107: executeTarget("testPathElementMove");
108: assertTrue(getProject().resolveFile("E").exists());
109: assertTrue(getProject().resolveFile("E/1").exists());
110: assertTrue(!getProject().resolveFile("A/1").exists());
111: assertTrue(getProject().resolveFile("A").exists());
112: }
113:
114: public void testMoveFileAndFileset() {
115: executeTarget("testMoveFileAndFileset");
116: }
117:
118: public void testCompleteDirectoryMoveToExistingDir() {
119: executeTarget("testCompleteDirectoryMoveToExistingDir");
120: }
121:
122: public void testCompleteDirectoryMoveFileToFile() {
123: executeTarget("testCompleteDirectoryMoveFileToFile");
124: }
125:
126: public void testCompleteDirectoryMoveFileToDir() {
127: executeTarget("testCompleteDirectoryMoveFileToDir");
128: }
129:
130: public void testCompleteDirectoryMoveFileAndFileset() {
131: executeTarget("testCompleteDirectoryMoveFileAndFileset");
132: }
133:
134: public void testCompleteDirectoryMoveFileToExistingFile() {
135: executeTarget("testCompleteDirectoryMoveFileToExistingFile");
136: }
137:
138: public void testCompleteDirectoryMoveFileToExistingDir() {
139: executeTarget("testCompleteDirectoryMoveFileToExistingDir");
140: }
141:
142: public void testCompleteDirectoryMoveFileToDirWithExistingFile() {
143: executeTarget("testCompleteDirectoryMoveFileToDirWithExistingFile");
144: }
145:
146: public void testCompleteDirectoryMoveFileToDirWithExistingDir() {
147: executeTarget("testCompleteDirectoryMoveFileToDirWithExistingDir");
148: }
149:
150: }
|