001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl;
014:
015: import java.util.ArrayList;
016: import java.util.HashSet;
017: import java.util.List;
018: import java.util.Set;
019:
020: import com.eviware.soapui.config.LoadTestConfig;
021: import com.eviware.soapui.config.TestCaseConfig;
022: import com.eviware.soapui.config.TestSuiteConfig;
023: import com.eviware.soapui.config.TestSuiteRunTypesConfig;
024: import com.eviware.soapui.config.TestSuiteRunTypesConfig.Enum;
025: import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
026: import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
027: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
028: import com.eviware.soapui.model.testsuite.TestCase;
029: import com.eviware.soapui.model.testsuite.TestSuite;
030: import com.eviware.soapui.model.testsuite.TestSuiteListener;
031:
032: /**
033: * TestSuite implementation for WSDL projects.
034: *
035: * @author Ole.Matzura
036: */
037:
038: public class WsdlTestSuite extends
039: AbstractWsdlModelItem<TestSuiteConfig> implements TestSuite {
040: private final WsdlProject project;
041: private List<WsdlTestCase> testCases = new ArrayList<WsdlTestCase>();
042: private Set<TestSuiteListener> listeners = new HashSet<TestSuiteListener>();
043:
044: public WsdlTestSuite(WsdlProject project, TestSuiteConfig config) {
045: super (config, project, "/testSuite.gif");
046: this .project = project;
047:
048: List<TestCaseConfig> testCaseConfigs = config.getTestCaseList();
049: for (int i = 0; i < testCaseConfigs.size(); i++) {
050: testCases.add(new WsdlTestCase(this ,
051: testCaseConfigs.get(i), false));
052: }
053:
054: if (!config.isSetRunType())
055: config.setRunType(TestSuiteRunTypesConfig.SEQUENTIAL);
056: }
057:
058: public TestSuiteRunType getRunType() {
059: Enum runType = getConfig().getRunType();
060:
061: if (runType.equals(TestSuiteRunTypesConfig.PARALLELL))
062: return TestSuiteRunType.PARALLEL;
063: else
064: return TestSuiteRunType.SEQUENTIAL;
065: }
066:
067: public void setRunType(TestSuiteRunType runType) {
068: TestSuiteRunType oldRunType = getRunType();
069:
070: if (runType == TestSuiteRunType.PARALLEL
071: && oldRunType != TestSuiteRunType.PARALLEL) {
072: getConfig().setRunType(TestSuiteRunTypesConfig.PARALLELL);
073: notifyPropertyChanged(RUNTYPE_PROPERTY, oldRunType, runType);
074: } else if (runType == TestSuiteRunType.SEQUENTIAL
075: && oldRunType != TestSuiteRunType.SEQUENTIAL) {
076: getConfig().setRunType(TestSuiteRunTypesConfig.SEQUENTIAL);
077: notifyPropertyChanged(RUNTYPE_PROPERTY, oldRunType, runType);
078: }
079: }
080:
081: public WsdlProject getProject() {
082: return project;
083: }
084:
085: public int getTestCaseCount() {
086: return testCases.size();
087: }
088:
089: public WsdlTestCase getTestCaseAt(int index) {
090: return testCases.get(index);
091: }
092:
093: public WsdlTestCase getTestCaseByName(String testCaseName) {
094: return (WsdlTestCase) getWsdlModelItemByName(testCases,
095: testCaseName);
096: }
097:
098: public WsdlTestCase cloneTestCase(WsdlTestCase testCase, String name) {
099: testCase.onSave();
100: TestCaseConfig newTestCase = getConfig().addNewTestCase();
101: newTestCase.set(testCase.getConfig());
102: newTestCase.setName(name);
103: WsdlTestCase newWsdlTestCase = new WsdlTestCase(this ,
104: newTestCase, false);
105:
106: testCases.add(newWsdlTestCase);
107: fireTestCaseAdded(newWsdlTestCase);
108:
109: return newWsdlTestCase;
110: }
111:
112: public WsdlTestCase addNewTestCase(String name) {
113: WsdlTestCase testCase = new WsdlTestCase(this , getConfig()
114: .addNewTestCase(), false);
115: testCase.setName(name);
116: testCase.setFailOnError(true);
117: testCase.setSearchProperties(true);
118: testCases.add(testCase);
119: fireTestCaseAdded(testCase);
120:
121: return testCase;
122: }
123:
124: public WsdlTestCase importTestCase(WsdlTestCase testCase,
125: String name, int index, boolean includeLoadTests) {
126: testCase.onSave();
127:
128: if (index >= testCases.size())
129: index = -1; //testCases.size()-1;
130:
131: TestCaseConfig testCaseConfig = index == -1 ? (TestCaseConfig) getConfig()
132: .addNewTestCase().set(testCase.getConfig().copy())
133: : (TestCaseConfig) getConfig().insertNewTestCase(index)
134: .set(testCase.getConfig().copy());
135: testCaseConfig.setName(name);
136:
137: if (!includeLoadTests)
138: testCaseConfig.setLoadTestArray(new LoadTestConfig[0]);
139:
140: testCase = new WsdlTestCase(this , testCaseConfig, false);
141:
142: if (index == -1)
143: testCases.add(testCase);
144: else
145: testCases.add(index, testCase);
146:
147: fireTestCaseAdded(testCase);
148:
149: return testCase;
150: }
151:
152: public void removeTestCase(WsdlTestCase testCase) {
153: int ix = testCases.indexOf(testCase);
154:
155: testCases.remove(ix);
156: try {
157: fireTestCaseRemoved(testCase);
158: } finally {
159: testCase.release();
160: getConfig().removeTestCase(ix);
161: }
162: }
163:
164: public void fireTestCaseAdded(WsdlTestCase testCase) {
165: TestSuiteListener[] a = listeners
166: .toArray(new TestSuiteListener[listeners.size()]);
167:
168: for (int c = 0; c < a.length; c++) {
169: a[c].testCaseAdded(testCase);
170: }
171: }
172:
173: public void fireTestCaseRemoved(WsdlTestCase testCase) {
174: TestSuiteListener[] a = listeners
175: .toArray(new TestSuiteListener[listeners.size()]);
176:
177: for (int c = 0; c < a.length; c++) {
178: a[c].testCaseRemoved(testCase);
179: }
180: }
181:
182: private void fireTestCaseMoved(WsdlTestCase testCase, int ix,
183: int offset) {
184: TestSuiteListener[] a = listeners
185: .toArray(new TestSuiteListener[listeners.size()]);
186:
187: for (int c = 0; c < a.length; c++) {
188: a[c].testCaseMoved(testCase, ix, offset);
189: }
190: }
191:
192: public void fireTestStepAdded(WsdlTestStep testStep, int index) {
193: TestSuiteListener[] a = listeners
194: .toArray(new TestSuiteListener[listeners.size()]);
195:
196: for (int c = 0; c < a.length; c++) {
197: a[c].testStepAdded(testStep, index);
198: }
199: }
200:
201: public void fireTestStepRemoved(WsdlTestStep testStep, int ix) {
202: TestSuiteListener[] a = listeners
203: .toArray(new TestSuiteListener[listeners.size()]);
204:
205: for (int c = 0; c < a.length; c++) {
206: a[c].testStepRemoved(testStep, ix);
207: }
208: }
209:
210: public void fireTestStepMoved(WsdlTestStep testStep, int ix,
211: int offset) {
212: TestSuiteListener[] a = listeners
213: .toArray(new TestSuiteListener[listeners.size()]);
214:
215: for (int c = 0; c < a.length; c++) {
216: a[c].testStepMoved(testStep, ix, offset);
217: }
218: }
219:
220: public void fireLoadTestAdded(WsdlLoadTest loadTest) {
221: TestSuiteListener[] a = listeners
222: .toArray(new TestSuiteListener[listeners.size()]);
223:
224: for (int c = 0; c < a.length; c++) {
225: a[c].loadTestAdded(loadTest);
226: }
227: }
228:
229: public void fireLoadTestRemoved(WsdlLoadTest loadTest) {
230: TestSuiteListener[] a = listeners
231: .toArray(new TestSuiteListener[listeners.size()]);
232:
233: for (int c = 0; c < a.length; c++) {
234: a[c].loadTestRemoved(loadTest);
235: }
236: }
237:
238: public void addTestSuiteListener(TestSuiteListener listener) {
239: listeners.add(listener);
240: }
241:
242: public void removeTestSuiteListener(TestSuiteListener listener) {
243: listeners.remove(listener);
244: }
245:
246: public int getTestCaseIndex(TestCase testCase) {
247: return testCases.indexOf(testCase);
248: }
249:
250: public void release() {
251: super .release();
252:
253: for (WsdlTestCase testCase : testCases)
254: testCase.release();
255: }
256:
257: public List<TestCase> getTestCaseList() {
258: List<TestCase> result = new ArrayList<TestCase>();
259: for (WsdlTestCase testCase : testCases)
260: result.add(testCase);
261:
262: return result;
263: }
264:
265: /**
266: * Moves a testcase by the specified offset, a bit awkward since xmlbeans doesn't support reordering
267: * of arrays, we need to create copies of the contained XmlObjects
268: *
269: * @param ix
270: * @param offset
271: */
272:
273: public WsdlTestCase moveTestCase(int ix, int offset) {
274: WsdlTestCase testCase = testCases.get(ix);
275:
276: if (offset == 0)
277: return testCase;
278:
279: testCases.remove(ix);
280: testCases.add(ix + offset, testCase);
281:
282: TestCaseConfig[] configs = new TestCaseConfig[testCases.size()];
283:
284: for (int c = 0; c < testCases.size(); c++) {
285: if (offset > 0) {
286: if (c < ix)
287: configs[c] = (TestCaseConfig) getConfig()
288: .getTestCaseArray(c).copy();
289: else if (c < (ix + offset))
290: configs[c] = (TestCaseConfig) getConfig()
291: .getTestCaseArray(c + 1).copy();
292: else if (c == ix + offset)
293: configs[c] = (TestCaseConfig) getConfig()
294: .getTestCaseArray(ix).copy();
295: else
296: configs[c] = (TestCaseConfig) getConfig()
297: .getTestCaseArray(c).copy();
298: } else {
299: if (c < ix + offset)
300: configs[c] = (TestCaseConfig) getConfig()
301: .getTestCaseArray(c).copy();
302: else if (c == ix + offset)
303: configs[c] = (TestCaseConfig) getConfig()
304: .getTestCaseArray(ix).copy();
305: else if (c <= ix)
306: configs[c] = (TestCaseConfig) getConfig()
307: .getTestCaseArray(c - 1).copy();
308: else
309: configs[c] = (TestCaseConfig) getConfig()
310: .getTestCaseArray(c).copy();
311: }
312: }
313:
314: getConfig().setTestCaseArray(configs);
315: for (int c = 0; c < configs.length; c++) {
316: testCases.get(c).resetConfigOnMove(configs[c]);
317: }
318:
319: fireTestCaseMoved(testCase, ix, offset);
320: return testCase;
321: }
322:
323: public int getIndexOfTestCase(TestCase testCase) {
324: return testCases.indexOf(testCase);
325: }
326:
327: @Override
328: public void onSave() {
329: for (WsdlTestCase testCase : testCases)
330: testCase.onSave();
331: }
332: }
|