Methods Summary |
---|
public void | assertDebuglogContaining(java.lang.String substring)Assert that the given substring is in the log messages.
String realLog = getFullLog();
assertTrue("expecting debug log to contain \"" + substring
+ "\" log was \""
+ realLog + "\"",
realLog.indexOf(substring) >= 0);
|
public void | assertLogContaining(java.lang.String substring)Assert that the given substring is in the log messages.
String realLog = getLog();
assertTrue("expecting log to contain \"" + substring + "\" log was \""
+ realLog + "\"",
realLog.indexOf(substring) >= 0);
|
public void | assertOutputContaining(java.lang.String substring)Assert that the given substring is in the output messages.
String realOutput = getOutput();
assertTrue("expecting output to contain \"" + substring
+ "\" output was \"" + realOutput + "\"",
realOutput.indexOf(substring) >= 0);
|
public void | assertPropertyEquals(java.lang.String property, java.lang.String value)assert that a property equals a value; comparison is case sensitive.
String result = project.getProperty(property);
assertEquals("property " + property,value,result);
|
public void | assertPropertySet(java.lang.String property)assert that a property equals "true".
assertPropertyEquals(property, "true");
|
public void | assertPropertyUnset(java.lang.String property)assert that a property is null.
assertPropertyEquals(property, null);
|
private java.lang.String | cleanBuffer(java.lang.StringBuffer buffer)
StringBuffer cleanedBuffer = new StringBuffer();
boolean cr = false;
for (int i = 0; i < buffer.length(); i++) {
char ch = buffer.charAt(i);
if (ch == '\r") {
cr = true;
continue;
}
if (!cr) {
cleanedBuffer.append(ch);
} else {
cleanedBuffer.append(ch);
}
}
return cleanedBuffer.toString();
|
public void | configureProject(java.lang.String filename)Sets up to run the named project
configureProject(filename, Project.MSG_DEBUG);
|
public void | configureProject(java.lang.String filename, int logLevel)Sets up to run the named project
logBuffer = new StringBuffer();
fullLogBuffer = new StringBuffer();
project = new Project();
project.init();
File antFile = new File(System.getProperty("root"), filename);
project.setUserProperty("ant.file" , antFile.getAbsolutePath());
project.addBuildListener(new AntTestListener(logLevel));
ProjectHelper.configureProject(project, antFile);
|
public void | executeTarget(java.lang.String targetName)Executes a target we have set up
PrintStream sysOut = System.out;
PrintStream sysErr = System.err;
try {
sysOut.flush();
sysErr.flush();
outBuffer = new StringBuffer();
PrintStream out = new PrintStream(new AntOutputStream(outBuffer));
System.setOut(out);
errBuffer = new StringBuffer();
PrintStream err = new PrintStream(new AntOutputStream(errBuffer));
System.setErr(err);
logBuffer = new StringBuffer();
fullLogBuffer = new StringBuffer();
buildException = null;
project.executeTarget(targetName);
} finally {
System.setOut(sysOut);
System.setErr(sysErr);
}
|
public void | expectBuildException(java.lang.String target, java.lang.String cause)run a target, expect for any build exception
expectSpecificBuildException(target, cause, null);
|
public void | expectBuildExceptionContaining(java.lang.String target, java.lang.String cause, java.lang.String contains)run a target, expect an exception string
containing the substring we look for (case sensitive match)
try {
executeTarget(target);
} catch (org.apache.tools.ant.BuildException ex) {
buildException = ex;
if ((null != contains) && (ex.getMessage().indexOf(contains) == -1)) {
fail("Should throw BuildException because '" + cause + "' with message containing '" + contains + "' (actual message '" + ex.getMessage() + "' instead)");
}
return;
}
fail("Should throw BuildException because: " + cause);
|
public void | expectDebuglog(java.lang.String target, java.lang.String log)Assert that the given message has been logged with a priority
>= VERBOSE when running the given target.
executeTarget(target);
String realLog = getFullLog();
assertEquals(log, realLog);
|
public void | expectLog(java.lang.String target, java.lang.String log)Assert that only the given message has been logged with a
priority <= INFO when running the given target.
executeTarget(target);
String realLog = getLog();
assertEquals(log, realLog);
|
public void | expectLogContaining(java.lang.String target, java.lang.String log)Assert that the given message has been logged with a priority
<= INFO when running the given target.
executeTarget(target);
assertLogContaining(log);
|
public void | expectOutput(java.lang.String target, java.lang.String output)execute the target, verify output matches expectations
executeTarget(target);
String realOutput = getOutput();
assertEquals(output, realOutput.trim());
|
public void | expectOutputAndError(java.lang.String target, java.lang.String output, java.lang.String error)Executes the target, verify output matches expectations
and that we got the named error at the end
executeTarget(target);
String realOutput = getOutput();
assertEquals(output, realOutput);
String realError = getError();
assertEquals(error, realError);
|
public void | expectPropertySet(java.lang.String target, java.lang.String property, java.lang.String value)call a target, verify property is as expected
executeTarget(target);
assertPropertyEquals(property, value);
|
public void | expectPropertySet(java.lang.String target, java.lang.String property)call a target, verify named property is "true".
expectPropertySet(target, property, "true");
|
public void | expectPropertyUnset(java.lang.String target, java.lang.String property)Call a target, verify property is null.
expectPropertySet(target, property, null);
|
public void | expectSpecificBuildException(java.lang.String target, java.lang.String cause, java.lang.String msg)Runs a target, wait for a build exception.
try {
executeTarget(target);
} catch (org.apache.tools.ant.BuildException ex) {
buildException = ex;
if ((null != msg) && (!ex.getMessage().equals(msg))) {
fail("Should throw BuildException because '" + cause
+ "' with message '" + msg
+ "' (actual message '" + ex.getMessage() + "' instead)");
}
return;
}
fail("Should throw BuildException because: " + cause);
|
public BuildException | getBuildException()
return buildException;
|
public java.lang.String | getError()
return cleanBuffer(errBuffer);
|
public java.lang.String | getFullLog()Gets the log the BuildFileTest object.
Only valid if configureProject() has been called.
return fullLogBuffer.toString();
|
public java.lang.String | getLog()Gets the log the BuildFileTest object.
Only valid if configureProject() has been called.
return logBuffer.toString();
|
public java.lang.String | getOutput()
return cleanBuffer(outBuffer);
|
public Project | getProject()Get the project which has been configured for a test.
return project;
|
public java.io.File | getProjectDir()Gets the directory of the project.
return project.getBaseDir();
|
public java.net.URL | getResource(java.lang.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.
URL url = getClass().getResource(resource);
assertNotNull("Could not find resource :" + resource, url);
return url;
|
protected void | tearDown()Automatically calls the target called "tearDown"
from the build file tested if it exits.
This allows to use Ant tasks directly in the build file
to clean up after each test. Note that no "setUp" target
is automatically called, since it's trivial to have a
test target depend on it.
final String tearDown = "tearDown";
if (project.getTargets().containsKey(tearDown)) {
project.executeTarget(tearDown);
}
|