1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.teststeps;
14
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.HashMap;
18 import java.util.HashSet;
19 import java.util.Map;
20 import java.util.Set;
21
22 import com.eviware.soapui.config.TestStepConfig;
23 import com.eviware.soapui.impl.wsdl.AbstractWsdlModelItem;
24 import com.eviware.soapui.impl.wsdl.WsdlInterface;
25 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
26 import com.eviware.soapui.model.PanelBuilder;
27 import com.eviware.soapui.model.testsuite.TestRunContext;
28 import com.eviware.soapui.model.testsuite.TestRunner;
29 import com.eviware.soapui.model.testsuite.TestStep;
30 import com.eviware.soapui.model.testsuite.TestStepProperty;
31
32 /***
33 * Base class for WSDL TestCase test steps.
34 *
35 * @author Ole.Matzura
36 */
37
38 abstract public class WsdlTestStep extends AbstractWsdlModelItem<TestStepConfig> implements TestStep
39 {
40 private final WsdlTestCase testCase;
41 private Map<String,TestStepProperty> properties;
42 private Set<WsdlTestStepListener> listeners = new HashSet<WsdlTestStepListener>();
43 private final boolean forLoadTest;
44 private final boolean hasEditor;
45
46 protected WsdlTestStep( WsdlTestCase testCase, TestStepConfig config, boolean hasEditor, boolean forLoadTest )
47 {
48 super( config, testCase, null );
49
50 this.testCase = testCase;
51 this.hasEditor = hasEditor;
52 this.forLoadTest = forLoadTest;
53 }
54
55 public boolean hasEditor()
56 {
57 return hasEditor;
58 }
59
60 public boolean isForLoadTest()
61 {
62 return forLoadTest;
63 }
64
65 /***
66 * Called after creation of all teststeps, should be used for inter-test-step initializations
67 * @param config
68 */
69
70 public void postInit(TestStepConfig config)
71 {}
72
73 protected PanelBuilder createPanelBuilder()
74 {
75 return null;
76 }
77
78 public WsdlTestCase getTestCase()
79 {
80 return testCase;
81 }
82
83 /***
84 * Called from WsdlTestCase when moving a teststep due to no move functionality
85 * in xmlbeans generated arrays.
86 *
87 * @param config the new config to use, will be a copy of the existing one. The current
88 * will be invalid
89 */
90
91 public void resetConfigOnMove( TestStepConfig config )
92 {
93 setConfig( config );
94 }
95
96 public boolean cancel()
97 {
98 return false;
99 }
100
101 public String getLabel()
102 {
103 String name = getName();
104 if( isDisabled() )
105 return name + " (disabled)";
106 else
107 return name;
108 }
109
110 @Override
111 public void setName( String name )
112 {
113 String oldLabel = getLabel();
114
115 super.setName( name );
116
117 String label = getLabel();
118 if( !oldLabel.equals( label ))
119 {
120 notifyPropertyChanged( LABEL_PROPERTY, oldLabel, label );
121 }
122 }
123
124 public String [] getPropertyNames()
125 {
126 if( properties == null )
127 return new String[0];
128
129 String [] result = new String[properties.size()];
130 int ix = 0;
131 for( TestStepProperty property : properties.values() )
132 result[ix++] = property.getName();
133
134 return result;
135 }
136
137 public TestStepProperty getProperty(String name)
138 {
139 return properties == null || name == null ? null : properties.get( name.toUpperCase() );
140 }
141
142 public String getPropertyValue(String name)
143 {
144 if( properties == null )
145 return null;
146
147 TestStepProperty testStepProperty = properties.get( name.toUpperCase());
148 return testStepProperty == null ? null : testStepProperty.getValue();
149 }
150
151 public void setPropertyValue(String name, String value)
152 {
153 if( properties == null )
154 return;
155
156 TestStepProperty testStepProperty = properties.get( name.toUpperCase());
157 if( testStepProperty != null )
158 {
159 testStepProperty.setValue( value );
160 }
161 }
162
163 protected void addProperty( TestStepProperty property )
164 {
165 if( properties == null )
166 properties = new HashMap<String,TestStepProperty>();
167
168 properties.put( property.getName().toUpperCase(), property );
169 }
170
171 protected void deleteProperty( String name )
172 {
173 if( properties != null )
174 properties.remove( name.toUpperCase() );
175 }
176
177 protected void propertyRenamed( String oldName )
178 {
179 if( properties == null )
180 return;
181
182 TestStepProperty testStepProperty = properties.get( oldName.toUpperCase() );
183 if( testStepProperty == null )
184 return;
185
186 properties.remove( oldName.toUpperCase() );
187 String newName = testStepProperty.getName();
188 properties.put( newName.toUpperCase(), testStepProperty );
189
190 firePropertyRenamed( oldName, newName );
191 }
192
193 public void addTestStepListener( WsdlTestStepListener listener )
194 {
195 listeners.add( listener );
196 }
197
198 public void removeTestStepListener( WsdlTestStepListener listener )
199 {
200 listeners.remove( listener );
201 }
202
203 protected void firePropertyAdded( String name )
204 {
205 WsdlTestStepListener[] array = listeners.toArray( new WsdlTestStepListener[listeners.size()]);
206 for( WsdlTestStepListener listener : array )
207 {
208 listener.propertyAdded( name );
209 }
210 }
211
212 protected void firePropertyRemoved( String name )
213 {
214 WsdlTestStepListener[] array = listeners.toArray( new WsdlTestStepListener[listeners.size()]);
215 for( WsdlTestStepListener listener : array )
216 {
217 listener.propertyRemoved( name );
218 }
219 }
220
221 protected void firePropertyRenamed( String oldName, String newName )
222 {
223 WsdlTestStepListener[] array = listeners.toArray( new WsdlTestStepListener[listeners.size()]);
224 for( WsdlTestStepListener listener : array )
225 {
226 listener.propertyRenamed( oldName, newName );
227 }
228 }
229
230 protected void firePropertyValueChanged( String name, String oldValue, String newValue )
231 {
232 if( oldValue == null && newValue == null )
233 return;
234
235 if( oldValue != null && oldValue.equals( newValue ))
236 return;
237
238 if( newValue != null && newValue.equals( oldValue ))
239 return;
240
241 WsdlTestStepListener[] array = listeners.toArray( new WsdlTestStepListener[listeners.size()]);
242 for( WsdlTestStepListener listener : array )
243 {
244 listener.propertyValueChanged( name, oldValue, newValue );
245 }
246 }
247
248 public boolean dependsOn( AbstractWsdlModelItem modelItem )
249 {
250 return false;
251 }
252
253 public String getTestStepTitle()
254 {
255 return getTestCase().getTestSuite().getName() + "#" + getTestCase().getName();
256 }
257
258 /***
259 * Called after cloning for custom behaviour
260 *
261 * @param sourceStep step we were cloned from
262 */
263
264 public WsdlTestStep clone( WsdlTestCase targetTestCase, String name)
265 {
266 onSave();
267 TestStepConfig newConfig = (TestStepConfig) getConfig().copy();
268 newConfig.setName( name );
269 return targetTestCase.addTestStep( newConfig );
270 }
271
272 public void finish( TestRunner testRunner, TestRunContext testRunContext )
273 {
274 }
275
276 public void prepare( TestRunner testRunner, TestRunContext testRunContext ) throws Exception
277 {
278 }
279
280 public Collection<WsdlInterface> getRequiredInterfaces()
281 {
282 return new ArrayList<WsdlInterface>();
283 }
284
285 public boolean isDisabled()
286 {
287 return getConfig().getDisabled();
288 }
289
290 public void setDisabled( boolean disabled )
291 {
292 String oldLabel = getLabel();
293
294 boolean oldDisabled = isDisabled();
295 if( oldDisabled == disabled )
296 return;
297
298 if( disabled )
299 getConfig().setDisabled( disabled );
300 else if( getConfig().isSetDisabled() )
301 getConfig().unsetDisabled();
302
303 notifyPropertyChanged( DISABLED_PROPERTY, oldDisabled, disabled );
304
305 String label = getLabel();
306 if( !oldLabel.equals( label ))
307 notifyPropertyChanged( LABEL_PROPERTY, oldLabel, label );
308 }
309 }