View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
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.impl.wsdl.teststeps;
14  
15  import org.apache.log4j.Logger;
16  
17  import com.eviware.soapui.impl.wsdl.mock.MockRunnerManager;
18  import com.eviware.soapui.impl.wsdl.mock.MockRunnerManagerException;
19  import com.eviware.soapui.impl.wsdl.mock.MockRunnerManagerImpl;
20  import com.eviware.soapui.model.support.LoadTestRunListenerAdapter;
21  import com.eviware.soapui.model.testsuite.LoadTestRunContext;
22  import com.eviware.soapui.model.testsuite.LoadTestRunner;
23  import com.eviware.soapui.model.testsuite.TestCase;
24  
25  public class LoadTestRunListenerImpl extends LoadTestRunListenerAdapter
26  {
27  	private final static Logger log = 
28  		Logger.getLogger(LoadTestRunListenerImpl.class);
29  
30  	@Override
31  	public void loadTestStarted(LoadTestRunner loadTestRunner, 
32  			LoadTestRunContext context)
33  	{
34  		TestCase testCase = loadTestRunner.getLoadTest().getTestCase();
35  
36  		if (needsMockRunnerManager(testCase))
37  		{
38  			MockRunnerManager manager = MockRunnerManagerImpl.getInstance(
39  					testCase);
40  
41  			try
42  			{
43  				manager.start();
44  			}
45  			catch (MockRunnerManagerException e)
46  			{
47  				log.error("Unable to start MockRunnerManager", e);
48  			}
49  		}
50  	}
51  
52  	@Override
53  	public void loadTestStopped(LoadTestRunner loadTestRunner, 
54  			LoadTestRunContext context)
55  	{
56  		TestCase testCase = loadTestRunner.getLoadTest().getTestCase();
57  
58  		MockRunnerManager manager = MockRunnerManagerImpl.getInstance(
59  				testCase);
60  
61  		if (manager != null && manager.isStarted())
62  		{
63  			manager.stop();
64  		}
65  	}
66  
67  	@Override
68  	public void afterLoadTest(LoadTestRunner loadTestRunner, LoadTestRunContext context)
69  	{
70  		loadTestStopped(loadTestRunner, context);
71  	}
72  
73  	private boolean needsMockRunnerManager(TestCase testCase)
74  	{
75  		return testCase.getTestStepsOfType(
76  				WsdlAsyncResponseTestStep.class).size() > 0;
77  	}
78  }