// start by listening to all testcases.. (since one testcase can call
// another)
for( int c = 0; c < project.getTestSuiteCount(); c++ )
{
TestSuite suite = project.getTestSuiteAt( c );
for( int i = 0; i < suite.getTestCaseCount(); i++ )
{
TestCase tc = suite.getTestCaseAt( i );
if( ( testSuite == null || suite.getName().equals( testSuite ) ) && testCase != null
&& tc.getName().equals( testCase ) )
testCasesToRun.add( tc );
addListeners( tc );
}
}
try
{
// validate testSuite argument
if( testCase != null && testCasesToRun.size() == 0 )
{
if( testSuite == null )
throw new Exception( "TestCase with name [" + testCase + "] is missing in Project [" + project.getName()
+ "]" );
else
throw new Exception( "TestCase with name [" + testCase + "] in TestSuite [" + testSuite
+ "] is missing in Project [" + project.getName() + "]" );
}
// decide what to run
if( testCasesToRun.size() > 0 )
{
for( TestCase testCase : testCasesToRun )
runTestCase( ( WsdlTestCase )testCase );
}
else if( testSuite != null )
{
WsdlTestSuite ts = project.getTestSuiteByName( testSuite );
if( ts == null )
throw new Exception( "TestSuite with name [" + testSuite + "] not found in project" );
else
runSuite( ts );
}
else
{
runProject( project );
}
long timeTaken = ( System.nanoTime() - startTime ) / 1000000;
if( printReport )
{
printReport( timeTaken );
}
exportReports( project );
if( saveAfterRun && !project.isRemote() )
{
try
{
project.save();
}
catch( Throwable t )
{
log.error( "Failed to save project", t );
}
}
if( ( assertions.size() > 0 || failedTests.size() > 0 ) && !ignoreErrors )
{
throwFailureException();
}
return true;
}
finally
{
for( int c = 0; c < project.getTestSuiteCount(); c++ )
{
TestSuite suite = project.getTestSuiteAt( c );
for( int i = 0; i < suite.getTestCaseCount(); i++ )
{
TestCase tc = suite.getTestCaseAt( i );
removeListeners( tc );
}
}
}
}