FileDocCategorySizeDatePackage
ConcatFilterTest.javaAPI DocApache Ant 1.705233Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.filters

ConcatFilterTest

public class ConcatFilterTest extends org.apache.tools.ant.BuildFileTest
JUnit Testcases for ConcatReader

Fields Summary
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
private static final String
lSep
private static final String
FILE_PREPEND_WITH
private static final String
FILE_PREPEND
private static final String
FILE_APPEND_WITH
private static final String
FILE_APPEND
Constructors Summary
public ConcatFilterTest(String name)



       
        super(name);
    
Methods Summary
protected voiddoTest(java.lang.String target, java.lang.String expectedStart, java.lang.String expectedEnd)
Executes a target and checks the beginning and the ending of a file. The filename depends on the target name: target name testHelloWorld will search for a file result/concat.HelloWorld.test.

param
target The target to invoke
param
expectedStart The string which should be at the beginning of the file
param
expectedEnd The string which should be at the end of the file

        executeTarget(target);
        String resultContent = read("result/concat." + target.substring(4) + ".test");
        assertTrue("First 5 lines differs.", resultContent.startsWith(expectedStart));
        assertTrue("Last 5 lines differs.", resultContent.endsWith(expectedEnd));
    
protected java.lang.Stringread(java.lang.String filename)
Wrapper for FileUtils.readFully(). Additionally it resolves the filename according the the projects basedir and closes the used reader.

param
filename The name of the file to read
return
the content of the file or null if something goes wrong

        String content = null;
        try {
            File file = FILE_UTILS.resolveFile(getProject().getBaseDir(), filename);
            java.io.FileReader rdr = new java.io.FileReader(file);
            content = FileUtils.readFully(rdr);
            rdr.close();
            rdr = null;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return content;
    
public voidsetUp()

        configureProject("src/etc/testcases/filters/concat.xml");
    
public voidtearDown()

        executeTarget("cleanup");
    
public voidtestConcatFilter()

        doTest("testConcatFilter", FILE_PREPEND, FILE_APPEND);
    
public voidtestConcatFilterAfter()

        doTest("testConcatFilterAppend", FILE_PREPEND, FILE_APPEND_WITH);
    
public voidtestConcatFilterBefore()

        doTest("testConcatFilterPrepend", FILE_PREPEND_WITH, FILE_APPEND);
    
public voidtestConcatFilterBeforeAfter()

        doTest("testConcatFilterPrependAppend", FILE_PREPEND_WITH, FILE_APPEND_WITH);
    
public voidtestFilterReaderAfter()

        doTest("testFilterReaderAppend", FILE_PREPEND, FILE_APPEND_WITH);
    
public voidtestFilterReaderBefore()

        doTest("testFilterReaderPrepend", FILE_PREPEND_WITH, FILE_APPEND);
    
public voidtestFilterReaderBeforeAfter()

        doTest("testFilterReaderPrependAppend", FILE_PREPEND_WITH, FILE_APPEND_WITH);
    
public voidtestFilterReaderNoArgs()

        executeTarget("testFilterReaderNoArgs");
        File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(),"input/concatfilter.test");
        File result = FILE_UTILS.resolveFile(getProject().getBaseDir(), "result/concat.FilterReaderNoArgs.test");
        assertTrue("testFilterReaderNoArgs: Result not like expected", FILE_UTILS.contentEquals(expected, result));