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 java.util.ArrayList;
16  import java.util.List;
17  
18  import org.apache.log4j.Logger;
19  
20  import com.eviware.soapui.SoapUI;
21  import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
22  import com.eviware.soapui.model.testsuite.TestCase;
23  import com.eviware.soapui.model.testsuite.TestRunner;
24  import com.eviware.soapui.model.testsuite.TestStepResult;
25  
26  /***
27   * Dummy TestRunner used when executing TestSteps one by one 
28   * 
29   * @author ole.matzura
30   */
31  
32  public class MockTestRunner implements TestRunner
33  {
34  	private long startTime;
35  	private String reason;
36  	private final WsdlTestCase testCase;
37  	private final Logger logger;
38  	private Status status = Status.RUNNING;
39  
40  	public MockTestRunner( WsdlTestCase testCase )
41  	{
42  		this( testCase, null );
43  	}
44  	
45  	public MockTestRunner( WsdlTestCase testCase, Logger logger )
46  	{
47  		this.testCase = testCase;
48  		this.logger = logger == null ? SoapUI.ensureGroovyLog() : logger;
49  		startTime = System.currentTimeMillis();
50  	}
51  	
52  	public Logger getLog()
53  	{
54  		return logger;
55  	}
56  
57  	public TestCase getTestCase()
58  	{
59  		return testCase;
60  	}
61  
62  	public List<TestStepResult> getResults()
63  	{
64  		return new ArrayList<TestStepResult>();
65  	}
66  
67  	public Status getStatus()
68  	{
69  		return status;
70  	}
71  
72  	public void start( boolean async )
73  	{
74  		
75  	}
76  
77  	public long getTimeTaken()
78  	{
79  		return System.currentTimeMillis()-startTime;
80  	}
81  
82  	public Status waitUntilFinished()
83  	{
84  		status = Status.FINISHED;
85  		return status;
86  	}
87  
88  	public void cancel(String reason)
89  	{
90  		this.reason = reason;
91  		status = Status.CANCELED;
92  		logger.info( "Canceled with reason [" + reason + "]" );
93  	}
94  
95  	public void gotoStep(int index)
96  	{
97  		logger.info( "Going to step " + index + " [" + 
98  					testCase.getTestStepAt( index ).getName() + "]");
99  	}
100 	
101 	public void gotoStepByName(String stepName)
102 	{
103 		logger.info( "Going to step [" + stepName + "]" );
104 	}
105 
106 	public void fail(String reason)
107 	{
108 		this.reason = reason;
109 		status = Status.FAILED;
110 		logger.error( "Failed with reason [" + reason + "]" );
111 	}
112 
113 	public long getStartTime()
114 	{
115 		return startTime;
116 	}
117 
118 	public String getReason()
119 	{
120 		return reason;
121 	}
122 }