FileDocCategorySizeDatePackage
EchoPropertiesTest.javaAPI DocApache Ant 1.707859Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.taskdefs.optional

EchoPropertiesTest

public class EchoPropertiesTest extends org.apache.tools.ant.BuildFileTest
Tests the EchoProperties task.
created
17-Jan-2002
since
Ant 1.5

Fields Summary
private static final String
TASKDEFS_DIR
private static final String
GOOD_OUTFILE
private static final String
GOOD_OUTFILE_XML
private static final String
PREFIX_OUTFILE
private static final String
TEST_VALUE
private static final String
BAD_OUTFILE
Constructors Summary
public EchoPropertiesTest(String name)


       
        super(name);
    
Methods Summary
protected voidassertGoodFile()

        File f = createRelativeFile( GOOD_OUTFILE );
        assertTrue(
            "Did not create "+f.getAbsolutePath(),
            f.exists() );
        Properties props=loadPropFile(GOOD_OUTFILE);
        props.list(System.out);
        assertEquals("test property not found ",
                     TEST_VALUE, props.getProperty("test.property"));
/*
        // read in the file
        FileReader fr = new FileReader( f );
        try {
            BufferedReader br = new BufferedReader( fr );
            String read = null;
            while ( (read = br.readLine()) != null)
            {
                if (read.indexOf("test.property" + TEST_VALUE) >= 0)
                {
                    // found the property we set - it's good.
                    return;
                }
            }
            fail( "did not encounter set property in generated file." );
        } finally {
            try { fr.close(); } catch(IOException e) {}
        }
*/
    
protected java.io.FilecreateRelativeFile(java.lang.String filename)

        if (filename.equals( "." )) {
            return getProjectDir();
        }
        // else
        return new File( getProjectDir(), filename );
    
protected java.util.PropertiesloadPropFile(java.lang.String relativeFilename)

        File f = createRelativeFile( relativeFilename );
        Properties props=new Properties();
        InputStream in=null;
        try  {
            in=new BufferedInputStream(new FileInputStream(f));
            props.load(in);
        } finally {
            if(in!=null) {
                try { in.close(); } catch(IOException e) {}
            }
        }
        return props;
    
public voidsetUp()

        configureProject(TASKDEFS_DIR + "echoproperties.xml");
        project.setProperty( "test.property", TEST_VALUE );
    
public voidtearDown()

        executeTarget("cleanup");
    
public voidtestEchoPrefix()

        testEchoPrefixVarious("testEchoPrefix");
    
public voidtestEchoPrefixAsDoublyNegatedPropertyset()

        testEchoPrefixVarious("testEchoPrefixAsDoublyNegatedPropertyset");
    
public voidtestEchoPrefixAsNegatedPropertyset()

        testEchoPrefixVarious("testEchoPrefixAsNegatedPropertyset");
    
public voidtestEchoPrefixAsPropertyset()

        testEchoPrefixVarious("testEchoPrefixAsPropertyset");
    
private voidtestEchoPrefixVarious(java.lang.String target)

        executeTarget(target);
        Properties props = loadPropFile(PREFIX_OUTFILE);
        assertEquals("prefix didn't include 'a.set' property",
            "true", props.getProperty("a.set"));
        assertNull("prefix failed to filter out property 'b.set'",
            props.getProperty("b.set"));
    
public voidtestEchoToBadFile()

        expectBuildExceptionContaining( "testEchoToBadFile",
            "destfile is a directory", "destfile is a directory!" );
    
public voidtestEchoToBadFileFail()

        expectBuildExceptionContaining( "testEchoToBadFileFail",
            "destfile is a directory", "destfile is a directory!" );
    
public voidtestEchoToBadFileNoFail()

        expectLog( "testEchoToBadFileNoFail", "destfile is a directory!");
    
public voidtestEchoToGoodFile()

        executeTarget( "testEchoToGoodFile" );
        assertGoodFile();
    
public voidtestEchoToGoodFileFail()

        executeTarget( "testEchoToGoodFileFail" );
        assertGoodFile();
    
public voidtestEchoToGoodFileNoFail()

        executeTarget( "testEchoToGoodFileNoFail" );
        assertGoodFile();
    
public voidtestEchoToGoodFileXml()

        executeTarget( "testEchoToGoodFileXml" );

        // read in the file
        File f = createRelativeFile( GOOD_OUTFILE_XML );
        FileReader fr = new FileReader( f );
        try {
            BufferedReader br = new BufferedReader( fr );
            String read = null;
            while ( (read = br.readLine()) != null) {
                if (read.indexOf("<property name=\"test.property\" value=\""+TEST_VALUE+"\" />") >= 0) {
                    // found the property we set - it's good.
                    return;
                }
            }
            fail( "did not encounter set property in generated file." );
        } finally {
            try {
                fr.close();
            } catch(IOException e) {}
        }
    
public voidtestEchoToLog()

        expectLogContaining("testEchoToLog", "test.property="+TEST_VALUE);
    
public voidtestEchoWithEmptyPrefixToLog()

        expectLogContaining("testEchoWithEmptyPrefixToLog", "test.property="+TEST_VALUE);
    
public voidtestReadBadFile()

        expectBuildExceptionContaining( "testReadBadFile",
            "srcfile is a directory", "srcfile is a directory!" );
    
public voidtestReadBadFileFail()

        expectBuildExceptionContaining( "testReadBadFile",
            "srcfile is a directory", "srcfile is a directory!" );
    
public voidtestReadBadFileNoFail()

        expectLog( "testReadBadFileNoFail", "srcfile is a directory!" );
    
public voidtestWithEmptyPrefixAndRegex()

        expectLogContaining("testEchoWithEmptyPrefixToLog", "test.property="+TEST_VALUE);
    
public voidtestWithPrefixAndRegex()

        expectSpecificBuildException("testWithPrefixAndRegex",
                "The target must fail with prefix and regex attributes set",
                "Please specify either prefix or regex, but not both");
    
public voidtestWithRegex()

        executeTarget("testWithRegex");
        assertDebuglogContaining("ant.home=");
    
protected java.lang.StringtoAbsolute(java.lang.String filename)

        return createRelativeFile( filename ).getAbsolutePath();