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 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
169 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 ActionList getActions()
179 {
180 return ActionListBuilder.buildActions( "TestStepsTreeNodeActions", TestCaseTreeNode.this.getModelItem() );
181 }
182
183 public void release()
184 {
185 for( TestStepTreeNode testStepNode : testStepNodes )
186 testStepNode.release();
187
188 getModelItem().release();
189 }
190 }
191
192 public class LoadTestsTreeNode extends AbstractTreeNode<WsdlLoadTestsModelItem>
193 {
194 private List<LoadTestTreeNode> loadTestNodes = new ArrayList<LoadTestTreeNode>();
195
196 protected LoadTestsTreeNode()
197 {
198 super( new WsdlLoadTestsModelItem( getTestCase() ) );
199
200 for( int c = 0; c < getTestCase().getLoadTestCount(); c++ )
201 {
202 loadTestNodes
203 .add( new LoadTestTreeNode( getTestCase().getLoadTestAt( c ), getModelItem(), getTreeModel() ) );
204 }
205
206 getTreeModel().mapModelItems( loadTestNodes );
207 }
208
209 public int getChildCount()
210 {
211 return loadTestNodes.size();
212 }
213
214 public int getIndexOfChild( Object child )
215 {
216 return loadTestNodes.indexOf( child );
217 }
218
219 public SoapUITreeNode getChildNode( int index )
220 {
221 return loadTestNodes.get( index );
222 }
223
224 public SoapUITreeNode getParentTreeNode()
225 {
226 return TestCaseTreeNode.this;
227 }
228
229 public void loadTestInserted( LoadTest loadTest )
230 {
231 LoadTestTreeNode loadTestTreeNode = new LoadTestTreeNode( loadTest, 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
246 throw new RuntimeException( "Removing unkown loadTest" );
247 }
248
249 public void release()
250 {
251 for( LoadTestTreeNode loadTestNode : loadTestNodes )
252 loadTestNode.release();
253 }
254
255 public ActionList getActions()
256 {
257 return ActionListBuilder.buildActions( "LoadTestsTreeNodeActions", TestCaseTreeNode.this.getModelItem() );
258 }
259 }
260
261 public void testStepInserted( TestStep testStep, int index )
262 {
263 testStepsNode.testStepInserted( testStep, index );
264 }
265
266 public void testStepRemoved( TestStep testStep, int index )
267 {
268 testStepsNode.testStepRemoved( testStep, index );
269 }
270
271 public void loadTestInserted( LoadTest loadTest )
272 {
273 loadTestsNode.loadTestInserted( loadTest );
274 }
275
276 public void loadTestRemoved( LoadTest loadTest )
277 {
278 loadTestsNode.loadTestRemoved( loadTest );
279 }
280
281 public void testStepMoved( TestStep testStep, int fromIndex, int offset )
282 {
283 testStepsNode.testStepMoved( testStep, fromIndex, offset );
284 }
285 }