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