Class BuildFileTest

  • Direct Known Subclasses:
    AbstractAntTester

    public abstract class BuildFileTest
    extends Object
    A BuildFileTest is a TestCase which executes targets from an Ant buildfile for testing. This class provides a number of utility methods for particular build file tests which extend this class.
    Author:
    Nico Seessle, Conor MacNeill
    • Field Detail

      • project

        protected org.apache.tools.ant.Project project
        Field project.
    • Constructor Detail

      • BuildFileTest

        public BuildFileTest()
    • Method Detail

      • expectBuildException

        protected final void expectBuildException​(String target,
                                                  String cause)
        Run a target, expect any build exception.
        Parameters:
        target - target to run
        cause - information string to reader of report
      • expectLog

        protected final void expectLog​(String target,
                                       String log)
        Assert that only the given message has been logged with a priority >= INFO when running the given target.
        Parameters:
        target - String
        log - String
      • assertLogContaining

        protected final void assertLogContaining​(String substring)
        Assert that the given substring is in the log messages.
        Parameters:
        substring - String
      • expectLogContaining

        protected final void expectLogContaining​(String target,
                                                 String log)
        Assert that the given message has been logged with a priority >= INFO when running the given target.
        Parameters:
        target - String
        log - String
      • getLog

        protected final String getLog()
        Gets the log the BuildFileTest object. Only valid if configureProject() has been called.
        Returns:
        The log value
        Precondition:
        logBuffer!=null
      • expectDebuglog

        protected final void expectDebuglog​(String target,
                                            String log)
        Assert that the given message has been logged with a priority >= DEBUG when running the given target.
        Parameters:
        target - String
        log - String
      • getFullLog

        protected final String getFullLog()
        Gets the log the BuildFileTest object. Only valid if configureProject() has been called.
        Returns:
        The log value
        Precondition:
        fullLogBuffer!=null
      • expectOutput

        protected final void expectOutput​(String target,
                                          String output)
        Execute the target, verify output matches expectations.
        Parameters:
        target - target to execute
        output - output to look for
      • expectOutputAndError

        protected final void expectOutputAndError​(String target,
                                                  String output,
                                                  String error)
        Execute the target, verify output matches expectations and that we got the named error at the end.
        Parameters:
        target - target to execute
        output - output to look for
        error - Description of Parameter
      • getOutput

        protected final String getOutput()
        Method getOutput.
        Returns:
        String
      • getError

        protected final String getError()
        Method getError.
        Returns:
        String
      • getBuildException

        protected final org.apache.tools.ant.BuildException getBuildException()
        Method getBuildException.
        Returns:
        BuildException
      • configureProject

        protected final void configureProject​(String filename)
                                       throws org.apache.tools.ant.BuildException
        Set up to run the named project.
        Parameters:
        filename - name of project file to run
        Throws:
        org.apache.tools.ant.BuildException - if project setup fails
      • configureProject

        protected final void configureProject​(String filename,
                                              int logLevel)
                                       throws org.apache.tools.ant.BuildException
        Set up to run the named project.
        Parameters:
        filename - name of project file to run
        logLevel - int
        Throws:
        org.apache.tools.ant.BuildException - if project setup fails
      • executeTarget

        protected final void executeTarget​(String targetName)
        Execute a target we have set up.
        Parameters:
        targetName - target to run
        Precondition:
        configureProject has been called
      • getProject

        protected final org.apache.tools.ant.Project getProject()
        Get the project which has been configured for a test.
        Returns:
        the Project instance for this test.
      • getProjectDir

        protected final File getProjectDir()
        Get the directory of the project.
        Returns:
        the base dir of the project
      • expectSpecificBuildException

        protected final void expectSpecificBuildException​(String target,
                                                          String cause,
                                                          String msg)
        Run a target, wait for a build exception.
        Parameters:
        target - target to run
        cause - information string to reader of report
        msg - the message value of the build exception we are waiting for set to null for any build exception to be valid
      • expectBuildExceptionContaining

        protected final void expectBuildExceptionContaining​(String target,
                                                            String cause,
                                                            String contains)
        Run a target, expect an exception string, containing the substring we look for (case sensitive match).
        Parameters:
        target - target to run
        cause - information string to reader of report
        contains - substring of the build exception to look for
      • expectPropertySet

        protected final void expectPropertySet​(String target,
                                               String property,
                                               String value)
        Call a target, verify property is as expected.
        Parameters:
        target - build file target
        property - property name
        value - expected value
      • assertPropertyEquals

        protected final void assertPropertyEquals​(String property,
                                                  String value)
        Assert that a property equals a value; comparison is case sensitive.
        Parameters:
        property - property name
        value - expected value
      • assertPropertySet

        protected final void assertPropertySet​(String property)
        Assert that a property equals "true".
        Parameters:
        property - property name
      • assertPropertyUnset

        protected final void assertPropertyUnset​(String property)
        Assert that a property is null.
        Parameters:
        property - property name
      • expectPropertySet

        protected final void expectPropertySet​(String target,
                                               String property)
        Call a target, verify named property is "true".
        Parameters:
        target - build file target
        property - property name
      • expectPropertyUnset

        protected final void expectPropertyUnset​(String target,
                                                 String property)
        Call a target, verify property is null.
        Parameters:
        target - build file target
        property - property name
      • getResource

        protected final URL getResource​(String resource)
        Retrieve a resource from the caller classloader to avoid assuming a vm working directory. The resource path must be relative to the package name or absolute from the root path.
        Parameters:
        resource - the resource to retrieve its url.
        Returns:
        URL