/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.FileUtilities; import org.apache.tools.ant.util.FileUtils; import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import java.io.File; import java.io.FileReader; import java.io.IOException; import static org.apache.tools.ant.AntAssert.assertContains; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests FileSet using the Copy task. * */ public class CopyTest { @Rule public final BuildFileRule buildRule = new BuildFileRule(); @Before public void setUp() { buildRule.configureProject("src/etc/testcases/taskdefs/copy.xml"); buildRule.executeTarget("setUp"); } @Test public void test1() { buildRule.executeTarget("test1"); File f = new File(buildRule.getProject().getProperty("output"), "copytest1.tmp"); if ( !f.exists()) { fail("Copy failed"); } } @Test public void test2() { buildRule.executeTarget("test2"); File f = new File(buildRule.getProject().getProperty("output"), "copytest1dir/copy.xml"); if ( !f.exists()) { fail("Copy failed"); } } @Test public void test3() { buildRule.executeTarget("test3"); File file3 = new File(buildRule.getProject().getProperty("output"), "copytest3.tmp"); //rollback file timestamp instead of delaying test FileUtilities.rollbackTimetamps(file3, 3); buildRule.executeTarget("test3Part2"); assertTrue(file3.exists()); File file3a = new File(buildRule.getProject().getProperty("output"), "copytest3a.tmp"); assertTrue(file3a.exists()); File file3b = new File(buildRule.getProject().getProperty("output"), "copytest3b.tmp"); assertTrue(file3b.exists()); File file3c = new File(buildRule.getProject().getProperty("output"), "copytest3c.tmp"); assertTrue(file3c.exists()); //file length checks rely on touch generating a zero byte file if(file3.length()==0) { fail("could not overwrite an existing, older file"); } if(file3c.length()!=0) { fail("could not force overwrite an existing, newer file"); } if(file3b.length()==0) { fail("unexpectedly overwrote an existing, newer file"); } //file time checks for java1.2+ assertTrue(file3a.lastModified()==file3.lastModified()); assertTrue(file3c.lastModified()