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.teststeps;
014:
015: import java.util.ArrayList;
016: import java.util.Collection;
017: import java.util.HashMap;
018: import java.util.HashSet;
019: import java.util.Map;
020: import java.util.Set;
021:
022: import com.eviware.soapui.config.TestStepConfig;
023: import com.eviware.soapui.impl.wsdl.AbstractWsdlModelItem;
024: import com.eviware.soapui.impl.wsdl.WsdlInterface;
025: import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
026: import com.eviware.soapui.model.PanelBuilder;
027: import com.eviware.soapui.model.testsuite.TestRunContext;
028: import com.eviware.soapui.model.testsuite.TestRunner;
029: import com.eviware.soapui.model.testsuite.TestStep;
030: import com.eviware.soapui.model.testsuite.TestStepProperty;
031:
032: /**
033: * Base class for WSDL TestCase test steps.
034: *
035: * @author Ole.Matzura
036: */
037:
038: abstract public class WsdlTestStep extends
039: AbstractWsdlModelItem<TestStepConfig> implements TestStep {
040: private final WsdlTestCase testCase;
041: private Map<String, TestStepProperty> properties;
042: private Set<WsdlTestStepListener> listeners = new HashSet<WsdlTestStepListener>();
043: private final boolean forLoadTest;
044: private final boolean hasEditor;
045:
046: protected WsdlTestStep(WsdlTestCase testCase,
047: TestStepConfig config, boolean hasEditor,
048: boolean forLoadTest) {
049: super (config, testCase, null);
050:
051: this .testCase = testCase;
052: this .hasEditor = hasEditor;
053: this .forLoadTest = forLoadTest;
054: }
055:
056: public boolean hasEditor() {
057: return hasEditor;
058: }
059:
060: public boolean isForLoadTest() {
061: return forLoadTest;
062: }
063:
064: /**
065: * Called after creation of all teststeps, should be used for inter-test-step initializations
066: * @param config
067: */
068:
069: public void postInit(TestStepConfig config) {
070: }
071:
072: protected PanelBuilder createPanelBuilder() {
073: return null;
074: }
075:
076: public WsdlTestCase getTestCase() {
077: return testCase;
078: }
079:
080: /**
081: * Called from WsdlTestCase when moving a teststep due to no move functionality
082: * in xmlbeans generated arrays.
083: *
084: * @param config the new config to use, will be a copy of the existing one. The current
085: * will be invalid
086: */
087:
088: public void resetConfigOnMove(TestStepConfig config) {
089: setConfig(config);
090: }
091:
092: public boolean cancel() {
093: return false;
094: }
095:
096: public String[] getPropertyNames() {
097: if (properties == null)
098: return new String[0];
099:
100: String[] result = new String[properties.size()];
101: int ix = 0;
102: for (TestStepProperty property : properties.values())
103: result[ix++] = property.getName();
104:
105: return result;
106: }
107:
108: public TestStepProperty getProperty(String name) {
109: return properties == null || name == null ? null : properties
110: .get(name.toUpperCase());
111: }
112:
113: public String getPropertyValue(String name) {
114: if (properties == null)
115: return null;
116:
117: TestStepProperty testStepProperty = properties.get(name
118: .toUpperCase());
119: return testStepProperty == null ? null : testStepProperty
120: .getValue();
121: }
122:
123: public void setPropertyValue(String name, String value) {
124: if (properties == null)
125: return;
126:
127: TestStepProperty testStepProperty = properties.get(name
128: .toUpperCase());
129: if (testStepProperty != null) {
130: testStepProperty.setValue(value);
131: }
132: }
133:
134: protected void addProperty(TestStepProperty property) {
135: if (properties == null)
136: properties = new HashMap<String, TestStepProperty>();
137:
138: properties.put(property.getName().toUpperCase(), property);
139: }
140:
141: protected void deleteProperty(String name) {
142: if (properties != null)
143: properties.remove(name.toUpperCase());
144: }
145:
146: protected void propertyRenamed(String oldName) {
147: if (properties == null)
148: return;
149:
150: TestStepProperty testStepProperty = properties.get(oldName
151: .toUpperCase());
152: if (testStepProperty == null)
153: return;
154:
155: properties.remove(oldName.toUpperCase());
156: String newName = testStepProperty.getName();
157: properties.put(newName.toUpperCase(), testStepProperty);
158:
159: firePropertyRenamed(oldName, newName);
160: }
161:
162: public void addTestStepListener(WsdlTestStepListener listener) {
163: listeners.add(listener);
164: }
165:
166: public void removeTestStepListener(WsdlTestStepListener listener) {
167: listeners.remove(listener);
168: }
169:
170: protected void firePropertyAdded(String name) {
171: WsdlTestStepListener[] array = listeners
172: .toArray(new WsdlTestStepListener[listeners.size()]);
173: for (WsdlTestStepListener listener : array) {
174: listener.propertyAdded(name);
175: }
176: }
177:
178: protected void firePropertyRemoved(String name) {
179: WsdlTestStepListener[] array = listeners
180: .toArray(new WsdlTestStepListener[listeners.size()]);
181: for (WsdlTestStepListener listener : array) {
182: listener.propertyRemoved(name);
183: }
184: }
185:
186: protected void firePropertyRenamed(String oldName, String newName) {
187: WsdlTestStepListener[] array = listeners
188: .toArray(new WsdlTestStepListener[listeners.size()]);
189: for (WsdlTestStepListener listener : array) {
190: listener.propertyRenamed(oldName, newName);
191: }
192: }
193:
194: protected void firePropertyValueChanged(String name,
195: String oldValue, String newValue) {
196: if (oldValue == null && newValue == null)
197: return;
198:
199: if (oldValue != null && oldValue.equals(newValue))
200: return;
201:
202: if (newValue != null && newValue.equals(oldValue))
203: return;
204:
205: WsdlTestStepListener[] array = listeners
206: .toArray(new WsdlTestStepListener[listeners.size()]);
207: for (WsdlTestStepListener listener : array) {
208: listener.propertyValueChanged(name, oldValue, newValue);
209: }
210: }
211:
212: public boolean dependsOn(AbstractWsdlModelItem modelItem) {
213: return false;
214: }
215:
216: public String getTestStepTitle() {
217: return getTestCase().getTestSuite().getName() + "#"
218: + getTestCase().getName();
219: }
220:
221: /**
222: * Called after cloning for custom behaviour
223: *
224: * @param sourceStep step we were cloned from
225: */
226:
227: public WsdlTestStep clone(WsdlTestCase targetTestCase, String name) {
228: onSave();
229: TestStepConfig newConfig = (TestStepConfig) getConfig().copy();
230: newConfig.setName(name);
231: return targetTestCase.addTestStep(newConfig);
232: }
233:
234: public void finish(TestRunner testRunner,
235: TestRunContext testRunContext) {
236: }
237:
238: public void prepare(TestRunner testRunner,
239: TestRunContext testRunContext) throws Exception {
240: }
241:
242: public Collection<WsdlInterface> getRequiredInterfaces() {
243: return new ArrayList<WsdlInterface>();
244: }
245:
246: public boolean isDisabled() {
247: return getConfig().getDisabled();
248: }
249:
250: public void setDisabled(boolean disabled) {
251: boolean oldDisabled = isDisabled();
252:
253: if (disabled)
254: getConfig().setDisabled(disabled);
255: else
256: getConfig().unsetDisabled();
257:
258: notifyPropertyChanged(DISABLED_PROPERTY, oldDisabled, disabled);
259: }
260: }
|