1   /*
2    *  soapui, copyright (C) 2005 Ole Matzura / eviware.com 
3    *
4    *  SoapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
7    *
8    *  SoapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.model.impl.wsdl;
14  
15  import junit.framework.TestCase;
16  
17  import com.eviware.soapui.impl.wsdl.WsdlProject;
18  import com.eviware.soapui.impl.wsdl.WsdlTestCase;
19  import com.eviware.soapui.impl.wsdl.teststeps.WsdlAssertion;
20  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
21  import com.eviware.soapui.impl.wsdl.teststeps.WsdlAssertion.AssertionStatus;
22  import com.eviware.soapui.model.iface.Submit;
23  import com.eviware.soapui.model.testsuite.TestRunListener;
24  import com.eviware.soapui.model.testsuite.TestRunner;
25  import com.eviware.soapui.model.testsuite.TestStep;
26  import com.eviware.soapui.model.testsuite.TestSuite;
27  
28  public class WsdlProjectTestCase extends TestCase implements TestRunListener
29  {
30  	public void testLoad() throws Exception
31  	{
32  		WsdlProject project = new WsdlProject( "Test-soapui-project.xml" );
33  		TestSuite testSuite = project.getTestSuiteAt( 0 );
34  		WsdlTestCase testCase = (WsdlTestCase) testSuite.getTestCaseAt( 0 );
35  
36  		testCase.addTestRunListener( this );
37  		testCase.run().waitUntilFinished();
38  	}
39  
40  	public boolean beforeRun(TestRunner testRunner)
41  	{
42  		return true;
43  	}
44  
45  	public boolean beforeStep(TestRunner testRunner)
46  	{
47  		return true;
48  	}
49  
50  	public boolean afterStep(TestRunner testRunner)
51  	{
52  		TestStep currentStep = testRunner.getCurrentStep();
53  		
54  		if( currentStep instanceof WsdlTestRequestStep )
55  		{
56  			WsdlTestRequestStep requestStep = (WsdlTestRequestStep) currentStep;
57  			for( int c = 0; c < requestStep.getAssertionCount(); c++ )
58  			{
59  				WsdlAssertion assertion = requestStep.getAssertionAt( c );
60  				System.out.println( "Assertion [" + assertion.getName() + "] has status " + assertion.getStatus());
61  				if( assertion.getStatus() == AssertionStatus.FAILED )
62  				{
63  					System.out.println( "-> " + assertion.getErrors());
64  				}
65  			}
66  		}	
67  		
68  		return true;
69  	}
70  
71  	public void afterRun(TestRunner testRunner)
72  	{
73  	}
74  
75  	public boolean onSubmit(Submit submit)
76  	{
77  		return true;
78  	}
79  
80  	public void afterSubmit(Submit submit)
81  	{
82  	}
83  	
84  }