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     private MockTestRunContext mockRunContext;
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 TestStepResult runTestStepByName( String name )
78     {
79        return testCase.getTestStepByName( name ).run(  this, mockRunContext );
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 
128    public void setMockRunContext( MockTestRunContext mockRunContext )
129    {
130       this.mockRunContext = mockRunContext;
131    }
132 }