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:
023: public class SyncTest extends BuildFileTest {
024:
025: public SyncTest(String name) {
026: super (name);
027: }
028:
029: public void setUp() {
030: configureProject("src/etc/testcases/taskdefs/sync.xml");
031: }
032:
033: public void tearDown() {
034: executeTarget("cleanup");
035: }
036:
037: public void testSimpleCopy() {
038: executeTarget("simplecopy");
039: String d = getProject().getProperty("dest") + "/a/b/c/d";
040: assertFileIsPresent(d);
041: assertTrue(getFullLog().indexOf("dangling") == -1);
042: }
043:
044: public void testEmptyCopy() {
045: executeTarget("emptycopy");
046: String d = getProject().getProperty("dest") + "/a/b/c/d";
047: assertFileIsNotPresent(d);
048: String c = getProject().getProperty("dest") + "/a/b/c";
049: assertFileIsNotPresent(c);
050: assertTrue(getFullLog().indexOf("dangling") == -1);
051: }
052:
053: public void testEmptyDirCopy() {
054: executeTarget("emptydircopy");
055: String d = getProject().getProperty("dest") + "/a/b/c/d";
056: assertFileIsNotPresent(d);
057: String c = getProject().getProperty("dest") + "/a/b/c";
058: assertFileIsPresent(c);
059: assertTrue(getFullLog().indexOf("dangling") == -1);
060: }
061:
062: public void testCopyAndRemove() {
063: testCopyAndRemove("copyandremove");
064: }
065:
066: public void testCopyAndRemoveWithFileList() {
067: testCopyAndRemove("copyandremove-with-filelist");
068: }
069:
070: public void testCopyAndRemoveWithZipfileset() {
071: testCopyAndRemove("copyandremove-with-zipfileset");
072: }
073:
074: private void testCopyAndRemove(String target) {
075: executeTarget(target);
076: String d = getProject().getProperty("dest") + "/a/b/c/d";
077: assertFileIsPresent(d);
078: String f = getProject().getProperty("dest") + "/e/f";
079: assertFileIsNotPresent(f);
080: assertTrue(getFullLog().indexOf("Removing orphan file:") > -1);
081: assertDebuglogContaining("Removed 1 dangling file from");
082: assertDebuglogContaining("Removed 1 dangling directory from");
083: }
084:
085: public void testCopyAndRemoveEmptyPreserve() {
086: executeTarget("copyandremove-emptypreserve");
087: String d = getProject().getProperty("dest") + "/a/b/c/d";
088: assertFileIsPresent(d);
089: String f = getProject().getProperty("dest") + "/e/f";
090: assertFileIsNotPresent(f);
091: assertTrue(getFullLog().indexOf("Removing orphan file:") > -1);
092: assertDebuglogContaining("Removed 1 dangling file from");
093: assertDebuglogContaining("Removed 1 dangling directory from");
094: }
095:
096: public void testEmptyDirCopyAndRemove() {
097: executeTarget("emptydircopyandremove");
098: String d = getProject().getProperty("dest") + "/a/b/c/d";
099: assertFileIsNotPresent(d);
100: String c = getProject().getProperty("dest") + "/a/b/c";
101: assertFileIsPresent(c);
102: String f = getProject().getProperty("dest") + "/e/f";
103: assertFileIsNotPresent(f);
104: assertTrue(getFullLog().indexOf("Removing orphan directory:") > -1);
105: assertDebuglogContaining("NO dangling file to remove from");
106: assertDebuglogContaining("Removed 2 dangling directories from");
107: }
108:
109: public void testCopyNoRemove() {
110: executeTarget("copynoremove");
111: String d = getProject().getProperty("dest") + "/a/b/c/d";
112: assertFileIsPresent(d);
113: String f = getProject().getProperty("dest") + "/e/f";
114: assertFileIsPresent(f);
115: assertTrue(getFullLog().indexOf("Removing orphan file:") == -1);
116: }
117:
118: public void testCopyNoRemoveSelectors() {
119: executeTarget("copynoremove-selectors");
120: String d = getProject().getProperty("dest") + "/a/b/c/d";
121: assertFileIsPresent(d);
122: String f = getProject().getProperty("dest") + "/e/f";
123: assertFileIsPresent(f);
124: assertTrue(getFullLog().indexOf("Removing orphan file:") == -1);
125: }
126:
127: public void assertFileIsPresent(String f) {
128: assertTrue("Expected file " + f, getProject().resolveFile(f)
129: .exists());
130: }
131:
132: public void assertFileIsNotPresent(String f) {
133: assertTrue("Didn't expect file " + f, !getProject()
134: .resolveFile(f).exists());
135: }
136: }
|