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.panels.support;
14  
15  import org.apache.log4j.Logger;
16  
17  import com.eviware.soapui.SoapUI;
18  import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
19  import com.eviware.soapui.model.testsuite.LoadTest;
20  import com.eviware.soapui.model.testsuite.LoadTestRunner;
21  
22  public class MockLoadTestRunner implements LoadTestRunner
23  {
24  	private long startTime;
25  	private String reason;
26  	private final WsdlLoadTest loadTest;
27  	private final Logger logger;
28  	private Status status = Status.RUNNING;
29  	
30  	public MockLoadTestRunner(WsdlLoadTest modelItem, Logger logger)
31  	{
32  		loadTest = modelItem;
33  		this.logger = logger == null ? SoapUI.ensureGroovyLog() : logger;
34  		startTime = System.currentTimeMillis();
35  	}
36  
37  	public void cancel(String reason)
38  	{
39  		this.reason = reason;
40  		status = Status.CANCELED;
41  		logger.info( "Canceled with reason [" + reason + "]" );
42  	}
43  
44  	public void fail(String reason)
45  	{
46  		this.reason = reason;
47  		status = Status.CANCELED;
48  		logger.info( "Failed with reason [" + reason + "]" );
49  	}
50  
51  	public LoadTest getLoadTest()
52  	{
53  		return loadTest;
54  	}
55  
56  	public float getProgress()
57  	{
58  		return 0;
59  	}
60  
61  	public String getReason()
62  	{
63  		return reason;
64  	}
65  
66  	public int getRunningThreadCount()
67  	{
68  		return (int) loadTest.getThreadCount();
69  	}
70  
71  	public Status getStatus()
72  	{
73  		return status;
74  	}
75  
76  	public long getTimeTaken()
77  	{
78  		return System.currentTimeMillis()-startTime;
79  	}
80  }