1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl;
14
15 import java.util.ArrayList;
16 import java.util.HashSet;
17 import java.util.List;
18 import java.util.Set;
19
20 import com.eviware.soapui.config.TestCaseConfig;
21 import com.eviware.soapui.config.TestSuiteConfig;
22 import com.eviware.soapui.config.TestSuiteRunTypesConfig;
23 import com.eviware.soapui.config.TestSuiteRunTypesConfig.Enum;
24 import com.eviware.soapui.impl.actions.ShowDesktopPanelAction;
25 import com.eviware.soapui.impl.wsdl.actions.support.ShowOnlineHelpAction;
26 import com.eviware.soapui.impl.wsdl.actions.testsuite.AddNewTestCaseAction;
27 import com.eviware.soapui.impl.wsdl.actions.testsuite.CloneTestSuiteAction;
28 import com.eviware.soapui.impl.wsdl.actions.testsuite.RemoveTestSuiteAction;
29 import com.eviware.soapui.impl.wsdl.actions.testsuite.RenameTestSuiteAction;
30 import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
31 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
32 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
33 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
34 import com.eviware.soapui.model.testsuite.TestCase;
35 import com.eviware.soapui.model.testsuite.TestSuite;
36 import com.eviware.soapui.model.testsuite.TestSuiteListener;
37 import com.eviware.soapui.support.action.ActionSupport;
38
39 /***
40 * TestSuite implementation for WSDL projects.
41 *
42 * @author Ole.Matzura
43 */
44
45 public class WsdlTestSuite extends AbstractWsdlModelItem<TestSuiteConfig> implements TestSuite
46 {
47 private final WsdlProject project;
48 private List<WsdlTestCase> testCases = new ArrayList<WsdlTestCase>();
49 private Set<TestSuiteListener> listeners = new HashSet<TestSuiteListener>();
50
51 public WsdlTestSuite(WsdlProject project, TestSuiteConfig config)
52 {
53 super( config, project, "/testSuite.gif" );
54 this.project = project;
55
56 List<TestCaseConfig> testCaseConfigs = config.getTestCaseList();
57 for (int i = 0; i < testCaseConfigs.size(); i++)
58 {
59 testCases.add( new WsdlTestCase( this, testCaseConfigs.get(i) ));
60 }
61
62 addAction( new ShowDesktopPanelAction( "Open TestSuite Editor",
63 "Opens the TestSuite Editor for this TestSuite", this ));
64 addAction( ActionSupport.SEPARATOR_ACTION );
65 addAction( new AddNewTestCaseAction( this ) );
66 addAction( new CloneTestSuiteAction( this ));
67 addAction( ActionSupport.SEPARATOR_ACTION );
68 addAction( new RenameTestSuiteAction( this ) );
69 addAction( new RemoveTestSuiteAction( this ) );
70 addAction( ActionSupport.SEPARATOR_ACTION );
71 addAction( new ShowOnlineHelpAction( HelpUrls.TESTSUITE_HELP_URL ));
72
73 if( !config.isSetRunType() )
74 config.setRunType( TestSuiteRunTypesConfig.SEQUENTIAL );
75 }
76
77 public TestSuiteRunType getRunType()
78 {
79 Enum runType = getConfig().getRunType();
80
81 if( runType.equals( TestSuiteRunTypesConfig.PARALLELL ))
82 return TestSuiteRunType.PARALLEL;
83 else
84 return TestSuiteRunType.SEQUENTIAL;
85 }
86
87 public void setRunType( TestSuiteRunType runType )
88 {
89 TestSuiteRunType oldRunType = getRunType();
90
91 if( runType == TestSuiteRunType.PARALLEL && oldRunType != TestSuiteRunType.PARALLEL )
92 {
93 getConfig().setRunType( TestSuiteRunTypesConfig.PARALLELL );
94 notifyPropertyChanged( RUNTYPE_PROPERTY, oldRunType, runType );
95 }
96 else if( runType == TestSuiteRunType.SEQUENTIAL && oldRunType != TestSuiteRunType.SEQUENTIAL )
97 {
98 getConfig().setRunType( TestSuiteRunTypesConfig.SEQUENTIAL );
99 notifyPropertyChanged( RUNTYPE_PROPERTY, oldRunType, runType );
100 }
101 }
102
103 public WsdlProject getProject()
104 {
105 return project;
106 }
107
108 public int getTestCaseCount()
109 {
110 return testCases.size();
111 }
112
113 public WsdlTestCase getTestCaseAt(int index)
114 {
115 return testCases.get( index );
116 }
117
118 public WsdlTestCase getTestCaseByName(String testCaseName)
119 {
120 return ( WsdlTestCase ) getWsdlModelItemByName( testCases, testCaseName );
121 }
122
123 public WsdlTestCase cloneTestCase( WsdlTestCase testCase, String name )
124 {
125 TestCaseConfig newTestCase = getConfig().addNewTestCase();
126 newTestCase.set( testCase.getConfig() );
127 newTestCase.setName( name );
128 WsdlTestCase newWsdlTestCase = new WsdlTestCase( this, newTestCase );
129
130 testCases.add( newWsdlTestCase );
131 fireTestCaseAdded( newWsdlTestCase );
132
133 return newWsdlTestCase;
134 }
135
136 public WsdlTestCase addNewTestCase( String name )
137 {
138 WsdlTestCase testCase = new WsdlTestCase( this, getConfig().addNewTestCase());
139 testCase.setName( name );
140 testCase.setFailOnError( true );
141 testCase.setSearchProperties( true );
142 testCases.add( testCase );
143 fireTestCaseAdded( testCase );
144
145 return testCase;
146 }
147
148 public void removeTestCase(WsdlTestCase testCase )
149 {
150 int ix = testCases.indexOf( testCase );
151
152 testCases.remove( ix );
153 try
154 {
155 fireTestCaseRemoved( testCase );
156 }
157 finally
158 {
159 testCase.release();
160 getConfig().removeTestCase( ix );
161 }
162 }
163
164 public void fireTestCaseAdded( WsdlTestCase testCase )
165 {
166 TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
167
168 for (int c = 0; c < a.length; c++ )
169 {
170 a[c].testCaseAdded( testCase );
171 }
172 }
173
174 public void fireTestCaseRemoved( WsdlTestCase testCase )
175 {
176 TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
177
178 for (int c = 0; c < a.length; c++ )
179 {
180 a[c].testCaseRemoved( testCase );
181 }
182 }
183
184 public void fireTestStepAdded( WsdlTestStep testStep, int index )
185 {
186 TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
187
188 for (int c = 0; c < a.length; c++ )
189 {
190 a[c].testStepAdded( testStep, index );
191 }
192 }
193
194 public void fireTestStepRemoved( WsdlTestStep testStep, int ix )
195 {
196 TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
197
198 for (int c = 0; c < a.length; c++ )
199 {
200 a[c].testStepRemoved( testStep, ix );
201 }
202 }
203
204 public void fireTestStepMoved( WsdlTestStep testStep, int ix, int offset )
205 {
206 TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
207
208 for (int c = 0; c < a.length; c++ )
209 {
210 a[c].testStepMoved( testStep, ix, offset );
211 }
212 }
213
214 public void fireLoadTestAdded( WsdlLoadTest loadTest )
215 {
216 TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
217
218 for (int c = 0; c < a.length; c++ )
219 {
220 a[c].loadTestAdded( loadTest );
221 }
222 }
223
224 public void fireLoadTestRemoved( WsdlLoadTest loadTest )
225 {
226 TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
227
228 for (int c = 0; c < a.length; c++ )
229 {
230 a[c].loadTestRemoved( loadTest );
231 }
232 }
233
234 public void addTestSuiteListener(TestSuiteListener listener)
235 {
236 listeners.add( listener );
237 }
238
239 public void removeTestSuiteListener(TestSuiteListener listener)
240 {
241 listeners.remove( listener );
242 }
243
244 public int getTestCaseIndex(TestCase testCase)
245 {
246 return testCases.indexOf( testCase );
247 }
248
249 public void release()
250 {
251 super.release();
252
253 for( WsdlTestCase testCase : testCases )
254 testCase.release();
255 }
256
257
258 }