FileDocCategorySizeDatePackage
TokenFilterTest.javaAPI DocApache Ant 1.7010028Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.filters

TokenFilterTest

public class TokenFilterTest extends org.apache.tools.ant.BuildFileTest

Fields Summary
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
Constructors Summary
public TokenFilterTest(String name)

    
       
        super(name);
    
Methods Summary
private voidassertStringContains(java.lang.String string, java.lang.String contains)

        assertTrue("[" + string + "] does not contain [" + contains +"]",
                   string.indexOf(contains) > -1);
    
private voidassertStringNotContains(java.lang.String string, java.lang.String contains)

        assertTrue("[" + string + "] does contain [" + contains +"]",
                   string.indexOf(contains) == -1);
    
private voidexpectFileContains(java.lang.String name, java.lang.String contains)

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

        executeTarget(target);
        expectFileContains(name, contains);
    
private java.lang.StringgetFileString(java.lang.String filename)

        Reader r = null;
        try {
            r = new FileReader(FILE_UTILS.resolveFile(getProject().getBaseDir(),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);
    
private booleanhasRegex(java.lang.String test)

        try {
            executeTarget("hasregex");
            expectFileContains("result/replaceregexp", "bye world");
        }
        catch (Throwable ex) {
            System.out.println(test + ": skipped - regex not present "
                               + ex);
            return false;
        }
        return true;
    
private booleanhasScript(java.lang.String test)

        try {
            executeTarget("hasscript");
        }
        catch (Throwable ex) {
            System.out.println(
                test + ": skipped - script not present ");
            return false;
        }
        return true;
    
public voidsetUp()

        configureProject("src/etc/testcases/filters/tokenfilter.xml");
        executeTarget("init");
    
public voidtearDown()

        executeTarget("cleanup");
    
public voidtestContainsRegex()

        if (! hasRegex("testContainsRegex"))
            return;
        String contents = getFileString(
            "containsregex", "result/containsregex");
        assertStringContains(contents, "hello world");
        assertStringNotContains(contents, "this is the moon");
        assertStringContains(contents, "World here");
    
public voidtestContainsRegex2()

        if (! hasRegex("testContainsRegex2"))
            return;
        String contents = getFileString(
            "containsregex2", "result/containsregex2");
        assertStringContains(contents, "void register_bits();");
    
public voidtestContainsString()

        String contents = getFileString(
            "containsstring", "result/containsstring");
        assertStringContains(contents, "this is a line contains foo");
        assertStringNotContains(contents, "this line does not");
    
public voidtestCustomTokenFilter()

        expectFileContains("customtokenfilter", "result/custom",
                           "Hello World");
    
public voidtestDeleteCharacters()

        String contents = getFileString(
            "deletecharacters", "result/deletechars");
        assertStringNotContains(contents, "#");
        assertStringNotContains(contents, "*");
        assertStringContains(contents, "This is some ");
    
public voidtestDosLineOutput()

        expectFileContains(
            "doslineoutput", "result/doslineoutput",
            "\r\nThis\r\nis\r\na\r\nnumber\r\nof\r\nwords\r\n");
    
public voidtestFileTokenizer()

        String contents = getFileString(
            "filetokenizer", "result/filetokenizer");
        assertStringContains(contents, "   of words");
        assertStringNotContains(contents, " This is");
    
public voidtestFilterContainsRegex()

        if (! hasRegex("testFilterContainsRegex"))
            return;
        String contents = getFileString(
            "filtercontainsregex", "result/filtercontainsregex");
        assertStringContains(contents, "hello world");
        assertStringNotContains(contents, "this is the moon");
        assertStringContains(contents, "World here");
    
public voidtestFilterReplaceRegex()

        if (! hasRegex("testFilterReplaceRegex"))
            return;
        String contents = getFileString(
            "filterreplaceregex", "result/filterreplaceregex");
        assertStringContains(contents, "world world world world");
    
public voidtestFilterReplaceString()

        String contents = getFileString(
            "filterreplacestring", "result/filterreplacestring");
        assertStringContains(contents, "This is the moon");
    
public voidtestFilterReplaceStrings()

        expectLogContaining("filterreplacestrings", "bar bar bar");
    
public voidtestHandleDollerMatch()

        if (! hasRegex("testFilterReplaceRegex"))
            return;
        executeTarget("dollermatch");
    
public voidtestReplaceRegex()

        if (! hasRegex("testReplaceRegex"))
            return;
        String contents = getFileString(
            "replaceregex", "result/replaceregex");
        assertStringContains(contents, "world world world world");
        assertStringContains(contents, "dog Cat dog");
        assertStringContains(contents, "moon Sun Sun");
        assertStringContains(contents, "found WhiteSpace");
        assertStringContains(contents, "Found digits [1234]");
        assertStringNotContains(contents, "This is a line with digits");
    
public voidtestReplaceString()

        expectFileContains(
            "replacestring", "result/replacestring",
            "this is the moon");
    
public voidtestReplaceStrings()

        expectLogContaining("replacestrings", "bar bar bar");
    
public voidtestScriptFilter()

        if (! hasScript("testScriptFilter"))
            return;

        expectFileContains("scriptfilter", "result/scriptfilter",
                           "HELLO WORLD");
    
public voidtestScriptFilter2()

        if (! hasScript("testScriptFilter"))
            return;

        expectFileContains("scriptfilter2", "result/scriptfilter2",
                           "HELLO MOON");
    
public voidtestStringTokenizer()

        expectLogContaining(
            "stringtokenizer", "#This#is#a#number#of#words#");
    
public voidtestTokenfilter()
make sure tokenfilter exists

        executeTarget("tokenfilter");
    
public voidtestTrimFile()

        String contents = getFileString(
            "trimfile", "result/trimfile");
        assertTrue("no ws at start", contents.startsWith("This is th"));
        assertTrue("no ws at end", contents.endsWith("second line."));
        assertStringContains(contents, "  This is the second");
    
public voidtestTrimFileByLine()

        String contents = getFileString(
            "trimfilebyline", "result/trimfilebyline");
        assertFalse("no ws at start", contents.startsWith("This is th"));
        assertFalse("no ws at end", contents.endsWith("second line."));
        assertStringNotContains(contents, "  This is the second");
        assertStringContains(contents, "file.\nThis is the second");
    
public voidtestTrimignore()

        expectLogContaining("trimignore", "Hello-World");
    
public voidtestUnixLineOutput()

        expectFileContains(
            "unixlineoutput", "result/unixlineoutput",
            "\nThis\nis\na\nnumber\nof\nwords\n");