FileDocCategorySizeDatePackage
ConcatTest.javaAPI DocApache Ant 1.707535Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs

ConcatTest

public class ConcatTest extends org.apache.tools.ant.BuildFileTest
A test class for the 'concat' task, used to concatenate a series of files into a single stream.

Fields Summary
private static final String
tempFile
The name of the temporary file.
private static final String
tempFile2
The name of the temporary file.
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
Utilities used for file operations
Constructors Summary
public ConcatTest(String name)
Required constructor.


           
       
        super(name);
    
Methods Summary
private voidexpectFileContains(java.lang.String target, java.lang.String filename, java.lang.String contains)

        String content = getFileString(target, filename);
        assertTrue(
            "expecting file " + filename + " to contain " +
            contains +
            " but got " + content, content.indexOf(contains) > -1);
    
private java.lang.StringgetFileString(java.lang.String filename)

        Reader r = null;
        try {
            r = new FileReader(getProject().resolveFile(filename));
            return  FileUtils.readFully(r);
        }
        finally {
            FileUtils.close(r);
        }

    
private java.lang.StringgetFileString(java.lang.String target, java.lang.String filename)

        executeTarget(target);
        return getFileString(filename);
    
public voidsetUp()
Test set up, called by the unit test framework prior to each test.

        configureProject("src/etc/testcases/taskdefs/concat.xml");
    
public voidtearDown()
Test tear down, called by the unit test framework prior to each test.

        executeTarget("cleanup");
    
public voidtest1()
Expect an exception when insufficient information is provided.

        expectBuildException("test1", "Insufficient information.");
    
public voidtest2()
Expect an exception when the destination file is invalid.

        expectBuildException("test2", "Invalid destination file.");
    
public voidtest3()
Cats the string 'Hello, World!' to a temporary file.


        File file = new File(getProjectDir(), tempFile);
        if (file.exists()) {
            file.delete();
        }

        executeTarget("test3");

        assertTrue(file.exists());
    
public voidtest4()
Cats the file created in test3 three times.

        test3();

        File file = new File(getProjectDir(), tempFile);
        final long origSize = file.length();

        executeTarget("test4");

        File file2 = new File(getProjectDir(), tempFile2);
        final long newSize = file2.length();

        assertEquals(origSize * 3, newSize);
    
public voidtest5()
Cats the string 'Hello, World!' to the console.

        expectLog("test5", "Hello, World!");
    
public voidtest6()

        String filename = "src/etc/testcases/taskdefs/thisfiledoesnotexist"
            .replace('/", File.separatorChar);
        expectLogContaining("test6", filename +" does not exist.");
    
public voidtestAppend()

        test3();

        File file = new File(getProjectDir(), tempFile);
        final long origSize = file.length();

        executeTarget("testAppend");

        File file2 = new File(getProjectDir(), tempFile2);
        final long newSize = file2.length();

        assertEquals(origSize*2, newSize);

    
public voidtestConcatNoNewline()

        expectLog("testConcatNoNewline", "ab");
    
public voidtestConcatNoNewlineEncoding()

        expectLog("testConcatNoNewlineEncoding", "ab");
    
public voidtestFilter()

        executeTarget("testfilter");
        assertTrue(getLog().indexOf("REPLACED") > -1);
    
public voidtestNoOverwrite()

        executeTarget("testnooverwrite");
        File file2 = new File(getProjectDir(), tempFile2);
        long size = file2.length();
        assertEquals(size, 0);
    
public voidtestPath()

        test3();

        File file = new File(getProjectDir(), tempFile);
        final long origSize = file.length();

        executeTarget("testPath");

        File file2 = new File(getProjectDir(), tempFile2);
        final long newSize = file2.length();

        assertEquals(origSize, newSize);

    
public voidtestResources()

        executeTarget("testResources");
    
public voidtestTranscoding()

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

        test3();
        expectLog("testfileheader", "Hello, World!Hello, World!");
    
public voidtestfilterinline()
Check if filter inline works

        executeTarget("testfilterinline");
        assertTrue(getLog().indexOf("REPLACED") > -1);
    
public voidtestfixlastline()
Check if fixlastline works

        expectFileContains(
            "testfixlastline", "concat.line4",
            "end of line" + System.getProperty("line.separator")
            + "This has");
    
public voidtestfixlastlineeol()
Check if fixlastline works with eol

        expectFileContains(
            "testfixlastlineeol", "concat.linecr",
            "end of line\rThis has");
    
public voidtestheaderfooter()

        test3();
        expectLog("testheaderfooter", "headerHello, World!footer");
    
public voidtestmultireader()
Check if multireader works

        executeTarget("testmultireader");
        assertTrue(getLog().indexOf("Bye") > -1);
        assertTrue(getLog().indexOf("Hello") == -1);
    
public voidtestsame()
Expect an exception when attempting to cat an file to itself

        expectBuildException("samefile", "output file same as input");