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