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.model.testsuite.LoadTest;
19 import com.eviware.soapui.model.testsuite.TestCase;
20 import com.eviware.soapui.model.testsuite.TestStep;
21 import com.eviware.soapui.model.tree.AbstractModelItemTreeNode;
22 import com.eviware.soapui.model.tree.AbstractTreeNode;
23 import com.eviware.soapui.model.tree.SoapUITreeModel;
24 import com.eviware.soapui.model.tree.SoapUITreeNode;
25 import com.eviware.soapui.model.tree.nodes.support.WsdlLoadTestsModelItem;
26 import com.eviware.soapui.model.tree.nodes.support.WsdlTestStepsModelItem;
27 import com.eviware.soapui.support.action.swing.ActionList;
28 import com.eviware.soapui.support.action.swing.ActionListBuilder;
29
30 /***
31 * SoapUITreeNode for TestCase implementations
32 *
33 * @author Ole.Matzura
34 */
35
36 public class TestCaseTreeNode extends AbstractModelItemTreeNode<TestCase>
37 {
38 private TestStepsTreeNode testStepsNode;
39 private LoadTestsTreeNode loadTestsNode;
40
41 public TestCaseTreeNode( TestCase testCase, SoapUITreeModel treeModel )
42 {
43 super( testCase, testCase.getTestSuite(), treeModel );
44
45 testStepsNode = new TestStepsTreeNode();
46 loadTestsNode = new LoadTestsTreeNode();
47
48 getTreeModel().mapModelItem( testStepsNode );
49 getTreeModel().mapModelItem( loadTestsNode );
50 }
51
52 public void release()
53 {
54 super.release();
55
56 getTreeModel().unmapModelItem( testStepsNode.getModelItem() );
57 getTreeModel().unmapModelItem( loadTestsNode.getModelItem() );
58
59 testStepsNode.release();
60 loadTestsNode.release();
61 }
62
63 public int getChildCount()
64 {
65 return 2;
66 }
67
68 public SoapUITreeNode getChildNode(int index)
69 {
70 if( index == 0 )
71 return testStepsNode;
72
73 if( index == 1 )
74 return loadTestsNode;
75
76 return null;
77 }
78
79 public int getIndexOfChild(Object child)
80 {
81 if( child == testStepsNode ) return 0;
82 if( child == loadTestsNode ) return 1;
83
84 return -1;
85 }
86
87 public LoadTestsTreeNode getLoadTestsNode()
88 {
89 return loadTestsNode;
90 }
91
92 public TestStepsTreeNode getTestStepsNode()
93 {
94 return testStepsNode;
95 }
96
97 public TestCase getTestCase()
98 {
99 return getModelItem();
100 }
101
102 public class TestStepsTreeNode extends AbstractTreeNode<WsdlTestStepsModelItem>
103 {
104 private List<TestStepTreeNode> testStepNodes = new ArrayList<TestStepTreeNode>();
105
106 protected TestStepsTreeNode()
107 {
108 super( new WsdlTestStepsModelItem( getTestCase() ) );
109
110 for( int c = 0; c < getTestCase().getTestStepCount(); c++ )
111 {
112 testStepNodes.add( new TestStepTreeNode( getTestCase().getTestStepAt( c ),
113 getModelItem(), getTreeModel() ));
114 }
115
116 getTreeModel().mapModelItems( testStepNodes );
117 }
118
119 public int getChildCount()
120 {
121 return testStepNodes.size();
122 }
123
124 public int getIndexOfChild(Object child)
125 {
126 return testStepNodes.indexOf( child );
127 }
128
129 public SoapUITreeNode getChildNode(int index)
130 {
131 return testStepNodes.get( index );
132 }
133
134 public SoapUITreeNode getParentTreeNode()
135 {
136 return TestCaseTreeNode.this;
137 }
138
139 public void testStepInserted(TestStep testStep, int index)
140 {
141 TestStepTreeNode testStepTreeNode = new TestStepTreeNode( testStep,
142 getModelItem(), getTreeModel() );
143 testStepNodes.add( index, testStepTreeNode);
144 getTreeModel().notifyNodeInserted( testStepTreeNode );
145 getTreeModel().notifyNodeChanged( this );
146 }
147
148 public void testStepRemoved(TestStep testStep, int index)
149 {
150 SoapUITreeNode treeNode = getTreeModel().getTreeNode( testStep );
151 if( testStepNodes.contains( treeNode ))
152 {
153 getTreeModel().notifyNodeRemoved( treeNode );
154 testStepNodes.remove( treeNode );
155 }
156 else throw new RuntimeException( "Removing unkown testStep" );
157 }
158
159 public void testStepMoved(TestStep testStep, int fromIndex, int offset)
160 {
161 testStepRemoved( testStep, fromIndex );
162 testStepInserted( testStep, fromIndex+offset );
163 }
164
165 public ActionList getActions()
166 {
167 return ActionListBuilder.buildActions( "TestStepsTreeNodeActions", TestCaseTreeNode.this.getModelItem() );
168 }
169
170 public void release()
171 {
172 for( TestStepTreeNode testStepNode : testStepNodes )
173 testStepNode.release();
174
175 getModelItem().release();
176 }
177 }
178
179 public class LoadTestsTreeNode extends AbstractTreeNode<WsdlLoadTestsModelItem>
180 {
181 private List<LoadTestTreeNode> loadTestNodes = new ArrayList<LoadTestTreeNode>();
182
183 protected LoadTestsTreeNode()
184 {
185 super( new WsdlLoadTestsModelItem( getTestCase() ) );
186
187 for( int c = 0; c < getTestCase().getLoadTestCount(); c++ )
188 {
189 loadTestNodes.add( new LoadTestTreeNode( getTestCase().getLoadTestAt( c ),
190 getModelItem(), getTreeModel() ));
191 }
192
193 getTreeModel().mapModelItems( loadTestNodes );
194 }
195
196 public int getChildCount()
197 {
198 return loadTestNodes.size();
199 }
200
201 public int getIndexOfChild(Object child)
202 {
203 return loadTestNodes.indexOf( child );
204 }
205
206 public SoapUITreeNode getChildNode(int index)
207 {
208 return loadTestNodes.get( index );
209 }
210
211 public SoapUITreeNode getParentTreeNode()
212 {
213 return TestCaseTreeNode.this;
214 }
215
216 public void loadTestInserted(LoadTest loadTest)
217 {
218 LoadTestTreeNode loadTestTreeNode = new LoadTestTreeNode( loadTest,
219 getModelItem(), getTreeModel() );
220 loadTestNodes.add( loadTestTreeNode);
221 getTreeModel().notifyNodeInserted( loadTestTreeNode );
222 getTreeModel().notifyNodeChanged( this );
223 }
224
225 public void loadTestRemoved(LoadTest loadTest)
226 {
227 SoapUITreeNode treeNode = getTreeModel().getTreeNode( loadTest );
228 if( loadTestNodes.contains( treeNode ))
229 {
230 getTreeModel().notifyNodeRemoved( treeNode );
231 loadTestNodes.remove( treeNode);
232 }
233 else throw new RuntimeException( "Removing unkown loadTest" );
234 }
235
236 public void release()
237 {
238 for( LoadTestTreeNode loadTestNode : loadTestNodes )
239 loadTestNode.release();
240 }
241
242 public ActionList getActions()
243 {
244 return ActionListBuilder.buildActions( "LoadTestsTreeNodeActions", TestCaseTreeNode.this.getModelItem() );
245 }
246 }
247
248 public void testStepInserted(TestStep testStep, int index)
249 {
250 testStepsNode.testStepInserted( testStep, index );
251 }
252
253 public void testStepRemoved(TestStep testStep, int index)
254 {
255 testStepsNode.testStepRemoved( testStep, index );
256 }
257
258 public void loadTestInserted(LoadTest loadTest)
259 {
260 loadTestsNode.loadTestInserted( loadTest );
261 }
262
263 public void loadTestRemoved(LoadTest loadTest)
264 {
265 loadTestsNode.loadTestRemoved( loadTest );
266 }
267
268 public void testStepMoved(TestStep testStep, int fromIndex, int offset)
269 {
270 testStepsNode.testStepMoved( testStep, fromIndex, offset );
271 }
272 }