prantl.ant.eclipse
Class BuildFileTestBase

java.lang.Object
  extended by TestCase
      extended by prantl.ant.eclipse.BuildFileTestBase

public abstract class BuildFileTestBase
extends TestCase

Simplifies testing of an ant task with a prepared build file automating the task execution and providing content of the log, standard output and error and an eventual exception.

Since:
Ant-Eclipse 1.0
Author:
Ferdinand Prantl <prantl@users.sourceforge.net> (based on org.apache.tools.ant.BuildFileTest from the Ant distribution)

Constructor Summary
protected BuildFileTestBase(java.lang.String name)
          Passes the construction of a new instance of the test fixture from the descendant to the ancestor.
 
Method Summary
protected  void assertBuildExceptionContains(java.lang.String part)
          Checks that the message of the last thrown exception has the specified value as a substring.
protected  void assertBuildExceptionEquals(java.lang.String message)
          Checks that the message of the last thrown exception has the specified value.
protected  void assertErrorContains(java.lang.String part)
          Checks that the captured standard error has the specified value as a substring.
protected  void assertErrorEquals(java.lang.String content)
          Checks that the captured standard error has the specified content.
protected  void assertLogContains(java.lang.String part)
          Checks that the captured log has the specified value as a substring.
protected  void assertLogEquals(java.lang.String content)
          Checks that the captured log has the specified content.
protected  void assertOutputContains(java.lang.String part)
          Checks that the captured standard output has the specified value as a substring.
protected  void assertOutputEquals(java.lang.String content)
          Checks that the captured standard output has the specified content.
protected  void assertPropertyContains(java.lang.String property, java.lang.String part)
          Checks that the property has the specified value as a substring.
protected  void assertPropertyEquals(java.lang.String property, java.lang.String value)
          Checks that the property has the specified value.
protected  void assertPropertyFalse(java.lang.String property)
          Checks that the property has been set to false.
protected  void assertPropertyTrue(java.lang.String property)
          Checks that the property has been set to true.
protected  void assertPropertyUnset(java.lang.String property)
          Checks that the property has never been set.
protected  void executeFailingTarget(java.lang.String targetName, java.lang.String cause)
          Executes the specified target expecting an exception to be thrown during the run.
protected  void executeTarget(java.lang.String targetName)
          Executes the specified target expecting a successful run.
protected  BuildException getBuildException()
          Gets the most recently thrown exception instance or null if there has been none thrown (the task execution was successful).
protected  java.lang.String getError()
          Gets the most recent standard error or null if there has been none written yet.
protected  java.lang.String getLog()
          Gets the most recent log or null if there has been none written yet.
protected  java.lang.String getOutput()
          Gets the most recent standard output or null if there has been none written yet.
protected  Project getProject()
          Gets the project, which has been most recently initialized or null if there has been none yet.
protected  java.lang.String normalizeEolns(java.lang.StringBuffer buffer)
          Returns a new string copy with all possible forms of an end-of-line delimiter made of carriage-return and/or line-feed (\r, \n, \r\n) replaced by a single line-feed character (\n).
protected  void parseBuildFile(java.lang.String fileName)
          Initializes a new project from the specified build file capturing selected traces.
protected  void parseInvalidBuildFile(java.lang.String fileName, java.lang.String cause)
          Initializes a new project from the specified build file capturing selected traces and expecting an exception to be thrown during the parsing.
protected  void setLogLevel(int logLevel)
          Sets the maximum log level of messages to be captured.
protected  void setTargetName(java.lang.String targetName)
          Sets the name of the target, which traces only will be captured.
protected  void setTaskName(java.lang.String taskName)
          Sets the name of the task, which traces only will be captured.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BuildFileTestBase

protected BuildFileTestBase(java.lang.String name)
Passes the construction of a new instance of the test fixture from the descendant to the ancestor.

Parameters:
name - The name of the test fixture.
Since:
Ant-Eclipse 1.0
See Also:
TestCase#TestCase(String)
Method Detail

setTargetName

protected void setTargetName(java.lang.String targetName)
Sets the name of the target, which traces only will be captured. Null turns off the matching, any target will be monitored.

Parameters:
targetName - The name of the target to capture the traces of.
Since:
Ant-Eclipse 1.0

setTaskName

protected void setTaskName(java.lang.String taskName)
Sets the name of the task, which traces only will be captured. Null turns off the matching, any task will be monitored.

Parameters:
taskName - The name of the target to capture the traces of.
Since:
Ant-Eclipse 1.0

setLogLevel

protected void setLogLevel(int logLevel)
Sets the maximum log level of messages to be captured. -1 turns off the matching, any log level will be monitored.

Parameters:
logLevel - Maximum log level of the captured traces.
Since:
Ant-Eclipse 1.0

parseBuildFile

protected void parseBuildFile(java.lang.String fileName)
Initializes a new project from the specified build file capturing selected traces. This is usually the first call in a file-oriented test case; most methods of this class expect this one having been called before. Log capturing can be controlled by calling setTarget, setTask and setLogLevel. The previous project and captured log is discarded by calling this method.

Parameters:
fileName - The name of the project file to process.
Throws:
java.lang.NullPointerException - If the parameter fileName is null.
Since:
Ant-Eclipse 1.0

parseInvalidBuildFile

protected void parseInvalidBuildFile(java.lang.String fileName,
                                     java.lang.String cause)
Initializes a new project from the specified build file capturing selected traces and expecting an exception to be thrown during the parsing. This is usually the only call in a file-oriented test case; most checking methods of this class expect this one having been called before. Log capturing can be controlled by calling setTarget, setTask and setLogLevel. The previous project and captured log is discarded by calling this method.

Parameters:
fileName - The name of the project file to process.
cause - The reason why the exception should have been thrown
Throws:
java.lang.NullPointerException - If the parameters fileName or cause are null.
Since:
Ant-Eclipse 1.0

executeTarget

protected void executeTarget(java.lang.String targetName)
Executes the specified target expecting a successful run.

Parameters:
targetName - The name of the target to execute.
Throws:
BuildException - If the parameter targetName is null.
Since:
Ant-Eclipse 1.0

executeFailingTarget

protected void executeFailingTarget(java.lang.String targetName,
                                    java.lang.String cause)
Executes the specified target expecting an exception to be thrown during the run.

Parameters:
targetName - The name of the target to execute.
cause - The reason why the exception should have been thrown if it had not happened to be written in a sentence after 'bacause'.
Throws:
BuildException - If the parameters targetName or cause are null.
Since:
Ant-Eclipse 1.0

getProject

protected Project getProject()
Gets the project, which has been most recently initialized or null if there has been none yet.

Returns:
The recently initialized project instance.
Since:
Ant-Eclipse 1.0

getLog

protected java.lang.String getLog()
Gets the most recent log or null if there has been none written yet.

Returns:
The content of the log.
Since:
Ant-Eclipse 1.0

getOutput

protected java.lang.String getOutput()
Gets the most recent standard output or null if there has been none written yet.

Returns:
The content of the standard output.
Since:
Ant-Eclipse 1.0

getError

protected java.lang.String getError()
Gets the most recent standard error or null if there has been none written yet.

Returns:
The content of the standard error.
Since:
Ant-Eclipse 1.0

getBuildException

protected BuildException getBuildException()
Gets the most recently thrown exception instance or null if there has been none thrown (the task execution was successful).

Returns:
The content of the standard error.
Since:
Ant-Eclipse 1.0

assertLogEquals

protected void assertLogEquals(java.lang.String content)
Checks that the captured log has the specified content. The comparison is case sensitive.

Parameters:
content - The content to be matched.
Since:
Ant-Eclipse 1.0

assertLogContains

protected void assertLogContains(java.lang.String part)
Checks that the captured log has the specified value as a substring. The comparison is case sensitive.

Parameters:
part - The part of the content to be searched for.
Since:
Ant-Eclipse 1.0

assertOutputEquals

protected void assertOutputEquals(java.lang.String content)
Checks that the captured standard output has the specified content. The comparison is case sensitive.

Parameters:
content - The content to be matched.
Since:
Ant-Eclipse 1.0

assertOutputContains

protected void assertOutputContains(java.lang.String part)
Checks that the captured standard output has the specified value as a substring. The comparison is case sensitive.

Parameters:
part - The part of the content to be searched for.
Since:
Ant-Eclipse 1.0

assertErrorEquals

protected void assertErrorEquals(java.lang.String content)
Checks that the captured standard error has the specified content. The comparison is case sensitive.

Parameters:
content - The content to be matched.
Since:
Ant-Eclipse 1.0

assertErrorContains

protected void assertErrorContains(java.lang.String part)
Checks that the captured standard error has the specified value as a substring. The comparison is case sensitive.

Parameters:
part - The part of the content to be searched for.
Since:
Ant-Eclipse 1.0

assertBuildExceptionEquals

protected void assertBuildExceptionEquals(java.lang.String message)
Checks that the message of the last thrown exception has the specified value. The comparison is case sensitive.

Parameters:
message - The message to be matched.
Since:
Ant-Eclipse 1.0

assertBuildExceptionContains

protected void assertBuildExceptionContains(java.lang.String part)
Checks that the message of the last thrown exception has the specified value as a substring. The comparison is case sensitive.

Parameters:
part - The part of the message to be searched for.
Since:
Ant-Eclipse 1.0

assertPropertyEquals

protected void assertPropertyEquals(java.lang.String property,
                                    java.lang.String value)
Checks that the property has the specified value. The comparison is case sensitive.

Parameters:
property - The name of the property to check.
value - The expected value.
Since:
Ant-Eclipse 1.0

assertPropertyContains

protected void assertPropertyContains(java.lang.String property,
                                      java.lang.String part)
Checks that the property has the specified value as a substring. The comparison is case sensitive.

Parameters:
property - The name of the property to check.
part - The part of the value to be searched for.
Since:
Ant-Eclipse 1.0

assertPropertyTrue

protected void assertPropertyTrue(java.lang.String property)
Checks that the property has been set to true.

Parameters:
property - The name of the property to check.
Since:
Ant-Eclipse 1.0

assertPropertyFalse

protected void assertPropertyFalse(java.lang.String property)
Checks that the property has been set to false.

Parameters:
property - The name of the property to check.
Since:
Ant-Eclipse 1.0

assertPropertyUnset

protected void assertPropertyUnset(java.lang.String property)
Checks that the property has never been set.

Parameters:
property - The name of the property to check.
Since:
Ant-Eclipse 1.0

normalizeEolns

protected java.lang.String normalizeEolns(java.lang.StringBuffer buffer)
Returns a new string copy with all possible forms of an end-of-line delimiter made of carriage-return and/or line-feed (\r, \n, \r\n) replaced by a single line-feed character (\n).

Parameters:
buffer - The source buffer to normalize eolns in.
Returns:
A new string with the content of the source buffer but with normalized eolns.
Since:
Ant-Eclipse 1.0