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