FileDocCategorySizeDatePackage
CopyTest.javaAPI DocApache Ant 1.708433Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs

CopyTest

public class CopyTest extends org.apache.tools.ant.BuildFileTest
Tests FileSet using the Copy task.

Fields Summary
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
Utilities used for file operations
Constructors Summary
public CopyTest(String name)


       
        super(name);
    
Methods Summary
public void_testFileResourceWithMapper()

        executeTarget("testFileResourceWithMapper");
        File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file1.txt.bak");
        File file2 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file2.txt.bak");
        File file3 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file3.txt.bak");
        assertTrue(file1.exists());
        assertTrue(file2.exists());
        assertTrue(file3.exists());
    
public void_testOnlineResources()

        executeTarget("testOnlineResources");
    
public void_testResourcePlain()

        executeTarget("testResourcePlain");
    
public void_testResourcePlainWithFilter()

        executeTarget("testResourcePlainWithFilter");
    
public void_testResourcePlainWithMapper()

        executeTarget("testResourcePlainWithMapper");
    
public voidsetUp()

        configureProject("src/etc/testcases/taskdefs/copy.xml");
    
public voidtearDown()

        executeTarget("cleanup");
    
public voidtest1()

        executeTarget("test1");
        File f = new File(getProjectDir(), "copytest1.tmp");
        if ( !f.exists()) {
            fail("Copy failed");
        }
    
public voidtest2()

        executeTarget("test2");
        File f = new File(getProjectDir(), "copytest1dir/copy.xml");
        if ( !f.exists()) {
            fail("Copy failed");
        }
    
public voidtest3()

        executeTarget("test3");
        File file3  = new File(getProjectDir(), "copytest3.tmp");
        assertTrue(file3.exists());
        File file3a = new File(getProjectDir(), "copytest3a.tmp");
        assertTrue(file3a.exists());
        File file3b = new File(getProjectDir(), "copytest3b.tmp");
        assertTrue(file3b.exists());
        File file3c = new File(getProjectDir(), "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()<file3a.lastModified());

    
public voidtestDirset()

        executeTarget("testDirset");
    
public voidtestFileResourcePlain()

        executeTarget("testFileResourcePlain");
        File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file1.txt");
        File file2 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file2.txt");
        File file3 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file3.txt");
        assertTrue(file1.exists());
        assertTrue(file2.exists());
        assertTrue(file3.exists());
    
public voidtestFileResourceWithFilter()

        executeTarget("testFileResourceWithFilter");
        File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/fileNR.txt");
        assertTrue(file1.exists());
        try {
            String file1Content = FILE_UTILS.readFully(new FileReader(file1));
            assertEquals("This is file 42", file1Content);
        } catch (IOException e) {
            // no-op: not a real business error
        }
    
public voidtestFilterChain()

        executeTarget("testFilterChain");
        File tmp  = new File(getProjectDir(), "copy.filterchain.tmp");
        File check  = new File(getProjectDir(), "expected/copy.filterset.filtered");
        assertTrue(tmp.exists());
        assertTrue(FILE_UTILS.contentEquals(tmp, check));
    
public voidtestFilterSet()

        executeTarget("testFilterSet");
        File tmp  = new File(getProjectDir(), "copy.filterset.tmp");
        File check  = new File(getProjectDir(), "expected/copy.filterset.filtered");
        assertTrue(tmp.exists());
        assertTrue(FILE_UTILS.contentEquals(tmp, check));
    
public voidtestFilterTest()

        executeTarget("filtertest");
        assertTrue(getOutput().indexOf("loop in tokens") == -1);
    
public voidtestInfiniteFilter()

        executeTarget("infinitetest");
        assertTrue(getOutput().indexOf("loop in tokens") != -1);
    
public voidtestMissingDirBail()

        expectBuildException("testMissingDirBail", "not-there doesn't exist");
        assertTrue(getBuildException().getMessage().endsWith(" not found."));
    
public voidtestMissingDirIgnore()

        expectLogContaining("testMissingDirIgnore", "Warning: ");
    
public voidtestMissingFileBail()

        expectBuildException("testMissingFileBail", "not-there doesn't exist");
        assertTrue(getBuildException().getMessage()
                   .startsWith("Warning: Could not find file "));
    
public voidtestMissingFileIgnore()

        expectLogContaining("testMissingFileIgnore",
                            "Warning: Could not find file ");
    
public voidtestPathAsResource()

        executeTarget("testPathAsResource");
        File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file1.txt");
        File file2 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file2.txt");
        File file3 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file3.txt");
        assertTrue(file1.exists());
        assertTrue(file2.exists());
        assertTrue(file3.exists());
    
public voidtestSingleFileFileset()

        executeTarget("test_single_file_fileset");
        File file  = new File(getProjectDir(),
                                        "copytest_single_file_fileset.tmp");
        assertTrue(file.exists());
    
public voidtestSingleFilePath()

        executeTarget("test_single_file_path");
        File file  = new File(getProjectDir(),
                                        "copytest_single_file_path.tmp");
        assertTrue(file.exists());
    
public voidtestTranscoding()

        executeTarget("testTranscoding");
        File f1 = getProject().resolveFile("copy/expected/utf-8");
        File f2 = getProject().resolveFile("copytest1.tmp");
        assertTrue(FILE_UTILS.contentEquals(f1, f2));
    
public voidtestZipfileset()

        executeTarget("testZipfileset");
        File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file1.txt");
        File file2 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file2.txt");
        File file3 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file3.txt");
        assertTrue(file1.exists());
        assertTrue(file2.exists());
        assertTrue(file3.exists());