View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.model.testsuite.TestRunContext;
19  import com.eviware.soapui.model.testsuite.TestRunnable;
20  import com.eviware.soapui.model.testsuite.TestRunner;
21  
22  /***
23   * Dummy TestRunner used when executing TestSteps one by one
24   * 
25   * @author ole.matzura
26   */
27  
28  public abstract class AbstractMockTestRunner<T extends TestRunnable> implements TestRunner
29  {
30  	private long startTime;
31  	private String reason;
32  	private final T modelItem;
33  	private final Logger logger;
34  	private Status status = Status.RUNNING;
35  	private TestRunContext context;
36  
37  	public AbstractMockTestRunner( T modelItem, Logger logger )
38  	{
39  		this.modelItem = modelItem;
40  		this.logger = logger == null ? SoapUI.ensureGroovyLog() : logger;
41  		startTime = System.currentTimeMillis();
42  	}
43  	
44  	public void setRunContext( TestRunContext context )
45  	{
46  		this.context = context;
47  	}
48  
49  	public TestRunContext getRunContext()
50  	{
51  		return context;
52  	}
53  
54  	public Logger getLog()
55  	{
56  		return logger;
57  	}
58  
59  	public T getTestRunnable()
60  	{
61  		return modelItem;
62  	}
63  
64  	public Status getStatus()
65  	{
66  		return status;
67  	}
68  
69  	public void start( boolean async )
70  	{
71  		logger.info( "Started with async [" + async + "]" );
72  		startTime = System.currentTimeMillis();
73  	}
74  	
75  	public long getTimeTaken()
76  	{
77  		return System.currentTimeMillis() - startTime;
78  	}
79  
80  	public Status waitUntilFinished()
81  	{
82  		status = Status.FINISHED;
83  		return status;
84  	}
85  
86  	public void cancel( String reason )
87  	{
88  		this.reason = reason;
89  		status = Status.CANCELED;
90  		logger.info( "Canceled with reason [" + reason + "]" );
91  	}
92  
93  	public void fail( String reason )
94  	{
95  		this.reason = reason;
96  		status = Status.FAILED;
97  		logger.error( "Failed with reason [" + reason + "]" );
98  	}
99  
100 	public long getStartTime()
101 	{
102 		return startTime;
103 	}
104 
105 	public String getReason()
106 	{
107 		return reason;
108 	}
109 }