{
initGroovyLog();
getAssertions().clear();
String projectFile = getProjectFile();
WsdlProject project = ( WsdlProject )ProjectFactoryRegistry.getProjectFactory( "wsdl" ).createNew( projectFile,
getProjectPassword() );
if( project.isDisabled() )
throw new Exception( "Failed to load soapUI project file [" + projectFile + "]" );
initProject( project );
ensureOutputFolder( project );
log.info( "Running soapUI tests in project [" + project.getName() + "]" );
String testSuite = getTestSuite();
String testCase = getTestCase();
long startTime = System.nanoTime();
List<TestCase> testCasesToRun = new ArrayList<TestCase>();
// 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( suite.getName() ) ) && testCase != null
&& tc.getName().equals( testCase ) )
testCasesToRun.add( tc );
addListeners( tc );
}
}
// decide what to run
if( testCasesToRun.size() > 0 )
{
for( TestCase tc : testCasesToRun )
{
runTestCase( ( WsdlTestCase )tc );
}
}
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( isPrintReport() )
{
printReport( timeTaken );
}
exportReports( project );
if( isSaveAfterRun() && !project.isRemote() )
{
try
{
project.save();
}
catch( Throwable t )
{
log.error( "Failed to save project", t );
}