Package org.apache.tools.ant
Class BuildFileTest
- java.lang.Object
-
- org.apache.tools.ant.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 Summary
Fields Modifier and Type Field Description protected org.apache.tools.ant.Project
project
Field project.
-
Constructor Summary
Constructors Constructor Description BuildFileTest()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
assertLogContaining(String substring)
Assert that the given substring is in the log messages.protected void
assertPropertyEquals(String property, String value)
Assert that a property equals a value; comparison is case sensitive.protected void
assertPropertySet(String property)
Assert that a property equals "true".protected void
assertPropertyUnset(String property)
Assert that a property is null.protected void
configureProject(String filename)
Set up to run the named project.protected void
configureProject(String filename, int logLevel)
Set up to run the named project.protected void
executeTarget(String targetName)
Execute a target we have set up.protected void
expectBuildException(String target, String cause)
Run a target, expect any build exception.protected void
expectBuildExceptionContaining(String target, String cause, String contains)
Run a target, expect an exception string, containing the substring we look for (case sensitive match).protected void
expectDebuglog(String target, String log)
Assert that the given message has been logged with a priority >= DEBUG when running the given target.protected void
expectLog(String target, String log)
Assert that only the given message has been logged with a priority >= INFO when running the given target.protected void
expectLogContaining(String target, String log)
Assert that the given message has been logged with a priority >= INFO when running the given target.protected void
expectOutput(String target, String output)
Execute the target, verify output matches expectations.protected 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.protected void
expectPropertySet(String target, String property)
Call a target, verify named property is "true".protected void
expectPropertySet(String target, String property, String value)
Call a target, verify property is as expected.protected void
expectPropertyUnset(String target, String property)
Call a target, verify property is null.protected void
expectSpecificBuildException(String target, String cause, String msg)
Run a target, wait for a build exception.protected org.apache.tools.ant.BuildException
getBuildException()
Method getBuildException.protected String
getError()
Method getError.protected String
getFullLog()
Gets the log the BuildFileTest object.protected String
getLog()
Gets the log the BuildFileTest object.protected String
getOutput()
Method getOutput.protected org.apache.tools.ant.Project
getProject()
Get the project which has been configured for a test.protected File
getProjectDir()
Get the directory of the project.protected URL
getResource(String resource)
Retrieve a resource from the caller classloader to avoid assuming a vm working directory.
-
-
-
Method Detail
-
expectBuildException
protected final void expectBuildException(String target, String cause)
Run a target, expect any build exception.- Parameters:
target
- target to runcause
- 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
- Stringlog
- 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
- Stringlog
- 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
- Stringlog
- 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 executeoutput
- 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 executeoutput
- output to look forerror
- 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 runlogLevel
- 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 runcause
- information string to reader of reportmsg
- 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 runcause
- information string to reader of reportcontains
- 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 targetproperty
- property namevalue
- 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 namevalue
- 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 targetproperty
- property name
-
expectPropertyUnset
protected final void expectPropertyUnset(String target, String property)
Call a target, verify property is null.- Parameters:
target
- build file targetproperty
- 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
-
-