1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.model.tree.nodes;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import com.eviware.soapui.impl.wsdl.actions.testcase.AddNewLoadTestAction;
19 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
20 import com.eviware.soapui.model.support.TestSuiteListenerAdapter;
21 import com.eviware.soapui.model.testsuite.LoadTest;
22 import com.eviware.soapui.model.testsuite.TestCase;
23 import com.eviware.soapui.model.testsuite.TestStep;
24 import com.eviware.soapui.model.testsuite.TestSuiteListener;
25 import com.eviware.soapui.model.tree.AbstractModelItemTreeNode;
26 import com.eviware.soapui.model.tree.AbstractTreeNode;
27 import com.eviware.soapui.model.tree.SoapUITreeModel;
28 import com.eviware.soapui.model.tree.SoapUITreeNode;
29 import com.eviware.soapui.support.UISupport;
30 import com.eviware.soapui.support.action.ActionSupport;
31
32 /***
33 * SoapUITreeNode for TestCase implementations
34 *
35 * @author Ole.Matzura
36 */
37
38 public class TestCaseTreeNode extends AbstractModelItemTreeNode<TestCase>
39 {
40 private TestStepsTreeNode testStepsNode;
41 private LoadTestsTreeNode loadTestsNode;
42 private InternalTestSuiteListener internalTestSuiteListener;
43
44 public TestCaseTreeNode( TestCase testCase, SoapUITreeModel treeModel )
45 {
46 super( testCase, testCase.getTestSuite(), treeModel );
47
48 testStepsNode = new TestStepsTreeNode();
49 loadTestsNode = new LoadTestsTreeNode();
50
51 getTreeModel().mapModelItem( testStepsNode );
52 getTreeModel().mapModelItem( loadTestsNode );
53
54 internalTestSuiteListener = new InternalTestSuiteListener();
55 testCase.getTestSuite().addTestSuiteListener( internalTestSuiteListener );
56 }
57
58 public void release()
59 {
60 super.release();
61
62 getTestCase().getTestSuite().removeTestSuiteListener( internalTestSuiteListener );
63
64 testStepsNode.release();
65 loadTestsNode.release();
66 }
67
68 public int getChildCount()
69 {
70 return 2;
71 }
72
73 public SoapUITreeNode getChildNode(int index)
74 {
75 if( index == 0 )
76 return testStepsNode;
77
78 if( index == 1 )
79 return loadTestsNode;
80
81 return null;
82 }
83
84 public int getIndexOfChild(Object child)
85 {
86 if( child == testStepsNode ) return 0;
87 if( child == loadTestsNode ) return 1;
88
89 return -1;
90 }
91
92 public LoadTestsTreeNode getLoadTestsNode()
93 {
94 return loadTestsNode;
95 }
96
97 public TestStepsTreeNode getTestStepsNode()
98 {
99 return testStepsNode;
100 }
101
102 public TestCase getTestCase()
103 {
104 return (TestCase) getModelItem();
105 }
106
107 public class TestStepsTreeNode extends AbstractTreeNode
108 {
109 private List<TestStepTreeNode> testStepNodes = new ArrayList<TestStepTreeNode>();
110
111
112 protected TestStepsTreeNode()
113 {
114 super( "Test Steps (" + getTestCase().getTestStepCount() + ")", UISupport.createImageIcon("/teststeps.gif"));
115
116 for( int c = 0; c < getTestCase().getTestStepCount(); c++ )
117 {
118 testStepNodes.add( new TestStepTreeNode( getTestCase().getTestStepAt( c ),
119 getModelItem(), getTreeModel() ));
120 }
121
122 getTreeModel().mapModelItems( testStepNodes );
123
124 addAction( getTestCase().getActions().getDefaultAction(), true );
125 addAction( new ActionSupport.ActionListAction( ((WsdlTestCase)getTestCase()).getCreateActions() ), false);
126 }
127
128 public void updateLabel()
129 {
130 setLabel( "Test Steps (" + getTestCase().getTestStepCount() + ")" );
131 }
132
133 public int getChildCount()
134 {
135 return testStepNodes.size();
136 }
137
138 public int getIndexOfChild(Object child)
139 {
140 return testStepNodes.indexOf( child );
141 }
142
143 public SoapUITreeNode getChildNode(int index)
144 {
145 return testStepNodes.get( index );
146 }
147
148 public SoapUITreeNode getParentTreeNode()
149 {
150 return TestCaseTreeNode.this;
151 }
152
153 public void testStepInserted(TestStep testStep, int index)
154 {
155 TestStepTreeNode testStepTreeNode = new TestStepTreeNode( testStep,
156 getModelItem(), getTreeModel() );
157 testStepNodes.add( index, testStepTreeNode);
158 getTreeModel().notifyNodeInserted( testStepTreeNode );
159 }
160
161 public void testStepRemoved(TestStep testStep, int index)
162 {
163 SoapUITreeNode treeNode = getTreeModel().getTreeNode( testStep );
164 if( testStepNodes.contains( treeNode ))
165 {
166 getTreeModel().notifyNodeRemoved( treeNode );
167 testStepNodes.remove( treeNode );
168 }
169 else throw new RuntimeException( "Removing unkown testStep" );
170 }
171
172 public void testStepMoved(TestStep testStep, int fromIndex, int offset)
173 {
174 testStepRemoved( testStep, fromIndex );
175 testStepInserted( testStep, fromIndex+offset );
176 }
177
178 public void release()
179 {
180 for( TestStepTreeNode testStepNode : testStepNodes )
181 testStepNode.release();
182 }
183 }
184
185 public class LoadTestsTreeNode extends AbstractTreeNode
186 {
187 private List<LoadTestTreeNode> loadTestNodes = new ArrayList<LoadTestTreeNode>();
188
189 protected LoadTestsTreeNode()
190 {
191 super( "Load Tests (" + getTestCase().getLoadTestCount() + ")", UISupport.createImageIcon( "/loadtests.gif") );
192
193 for( int c = 0; c < getTestCase().getLoadTestCount(); c++ )
194 {
195 loadTestNodes.add( new LoadTestTreeNode( getTestCase().getLoadTestAt( c ),
196 getModelItem(), getTreeModel() ));
197 }
198
199 getTreeModel().mapModelItems( loadTestNodes );
200
201 addAction( new AddNewLoadTestAction( (WsdlTestCase) getTestCase() ), false );
202 }
203
204 public int getChildCount()
205 {
206 return loadTestNodes.size();
207 }
208
209 public int getIndexOfChild(Object child)
210 {
211 return loadTestNodes.indexOf( child );
212 }
213
214 public SoapUITreeNode getChildNode(int index)
215 {
216 return loadTestNodes.get( index );
217 }
218
219 public SoapUITreeNode getParentTreeNode()
220 {
221 return TestCaseTreeNode.this;
222 }
223
224 public void loadTestInserted(LoadTest loadTest)
225 {
226 LoadTestTreeNode loadTestTreeNode = new LoadTestTreeNode( loadTest,
227 getModelItem(), getTreeModel() );
228 loadTestNodes.add( loadTestTreeNode);
229 getTreeModel().notifyNodeInserted( loadTestTreeNode );
230 }
231
232 public void loadTestRemoved(LoadTest loadTest)
233 {
234 SoapUITreeNode treeNode = getTreeModel().getTreeNode( loadTest );
235 if( loadTestNodes.contains( treeNode ))
236 {
237 getTreeModel().notifyNodeRemoved( treeNode );
238 loadTestNodes.remove( treeNode);
239 }
240 else throw new RuntimeException( "Removing unkown loadTest" );
241 }
242
243 public void release()
244 {
245 for( LoadTestTreeNode loadTestNode : loadTestNodes )
246 loadTestNode.release();
247 }
248
249 public void updateLabel()
250 {
251 setLabel( "Load Tests (" + getTestCase().getLoadTestCount() + ")" );
252 }
253 }
254
255 public void testStepInserted(TestStep testStep, int index)
256 {
257 testStepsNode.testStepInserted( testStep, index );
258 }
259
260 public void testStepRemoved(TestStep testStep, int index)
261 {
262 testStepsNode.testStepRemoved( testStep, index );
263 }
264
265 public void loadTestInserted(LoadTest loadTest)
266 {
267 loadTestsNode.loadTestInserted( loadTest );
268 }
269
270 public void loadTestRemoved(LoadTest loadTest)
271 {
272 loadTestsNode.loadTestRemoved( loadTest );
273 }
274
275 public void testStepMoved(TestStep testStep, int fromIndex, int offset)
276 {
277 testStepsNode.testStepMoved( testStep, fromIndex, offset );
278 }
279
280 public class InternalTestSuiteListener extends TestSuiteListenerAdapter implements TestSuiteListener
281 {
282 @Override
283 public void testStepAdded( TestStep testStep, int index )
284 {
285 testStepsNode.updateLabel();
286 }
287
288 @Override
289 public void testStepRemoved( TestStep testStep, int index )
290 {
291 testStepsNode.updateLabel();
292 }
293
294 @Override
295 public void loadTestAdded( LoadTest loadTest )
296 {
297 loadTestsNode.updateLabel();
298 }
299
300 @Override
301 public void loadTestRemoved( LoadTest loadTest )
302 {
303 loadTestsNode.updateLabel();
304 }
305
306
307 }
308 }