1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import com.eviware.soapui.model.testsuite.TestCase;
19 import com.eviware.soapui.model.testsuite.TestRunListener;
20 import com.eviware.soapui.model.testsuite.TestRunner;
21 import com.eviware.soapui.model.testsuite.TestStep;
22
23 /***
24 * WSDL Test Runner
25 *
26 * @author Ole.Matzura
27 */
28
29 public class WsdlTestRunner implements Runnable, TestRunner
30 {
31 private TestRunListener [] listeners;
32 private List<Long> timestamps = new ArrayList<Long>();
33 private final WsdlTestCase testCase;
34 private Status status;
35 private WsdlTestStep currentStep;
36 private Exception error;
37 private int currentStepIndex;
38 private Thread thread;
39
40
41 public WsdlTestRunner( WsdlTestCase testCase )
42 {
43 this.testCase = testCase;
44 listeners = testCase.getTestRunListeners();
45 status = Status.INITIALIZED;
46 }
47
48 public void start()
49 {
50 thread = new Thread( this );
51 thread.start();
52 status = Status.RUNNING;
53 }
54
55 public void cancel()
56 {
57 if( status == Status.CANCELED ) return;
58 currentStep.cancel();
59 status = Status.CANCELED;
60 notifyAfterRun();
61 }
62
63 public Status getStatus()
64 {
65 return status;
66 }
67
68 public void run()
69 {
70 timestamps.add( System.currentTimeMillis() );
71 for (int i = 0; i < listeners.length; i++)
72 {
73 if( !listeners[i].beforeRun( this ))
74 return;
75 }
76
77 try {
78 WsdlTestStep[] testSteps = testCase.getTestSteps();
79
80 for ( currentStepIndex = 0; status != Status.CANCELED && currentStepIndex < testSteps.length; currentStepIndex++) {
81 currentStep = testSteps[currentStepIndex];
82 for (int i = 0; i < listeners.length; i++) {
83 if (!listeners[i].beforeStep(this ))
84 return;
85 }
86 timestamps.add(System.currentTimeMillis());
87 currentStep.run( this );
88 timestamps.add(System.currentTimeMillis());
89
90 if( status == Status.CANCELED )
91 break;
92
93 for (int i = 0; i < listeners.length; i++) {
94 if (!listeners[i].afterStep( this ))
95 return;
96 }
97 }
98 }
99 catch (Exception e)
100 {
101 e.printStackTrace();
102 status = Status.ERROR;
103 error = e;
104 }
105 finally
106 {
107 if( status != Status.CANCELED )
108 {
109 notifyAfterRun();
110 }
111 timestamps.add( System.currentTimeMillis() );
112 }
113
114 }
115
116 private void notifyAfterRun()
117 {
118 for (int i = 0; i < listeners.length; i++)
119 {
120 listeners[i].afterRun( this );
121 }
122 }
123
124 public TestStep getCurrentStep() {
125 return currentStep;
126 }
127
128 public int getCurrentStepIndex() {
129 return currentStepIndex;
130 }
131
132 public TestCase getTestCase() {
133 return testCase;
134 }
135
136 public Thread getThread()
137 {
138 return thread;
139 }
140
141 public void waitUntilFinished()
142 {
143 synchronized( thread )
144 {
145 try
146 {
147 thread.wait();
148 }
149 catch (InterruptedException e)
150 {
151 throw new RuntimeException( e );
152 }
153 }
154 }
155
156 }