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 [] getPropertyNames()
102 {
103 if( properties == null )
104 return new String[0];
105
106 String [] result = new String[properties.size()];
107 int ix = 0;
108 for( TestStepProperty property : properties.values() )
109 result[ix++] = property.getName();
110
111 return result;
112 }
113
114 public TestStepProperty getProperty(String name)
115 {
116 return properties == null || name == null ? null : properties.get( name.toUpperCase() );
117 }
118
119 public String getPropertyValue(String name)
120 {
121 if( properties == null )
122 return null;
123
124 TestStepProperty testStepProperty = properties.get( name.toUpperCase());
125 return testStepProperty == null ? null : testStepProperty.getValue();
126 }
127
128 public void setPropertyValue(String name, String value)
129 {
130 if( properties == null )
131 return;
132
133 TestStepProperty testStepProperty = properties.get( name.toUpperCase());
134 if( testStepProperty != null )
135 {
136 testStepProperty.setValue( value );
137 }
138 }
139
140 protected void addProperty( TestStepProperty property )
141 {
142 if( properties == null )
143 properties = new HashMap<String,TestStepProperty>();
144
145 properties.put( property.getName().toUpperCase(), property );
146 }
147
148 protected void deleteProperty( String name )
149 {
150 if( properties != null )
151 properties.remove( name.toUpperCase() );
152 }
153
154 protected void propertyRenamed( String oldName )
155 {
156 if( properties == null )
157 return;
158
159 TestStepProperty testStepProperty = properties.get( oldName.toUpperCase() );
160 if( testStepProperty == null )
161 return;
162
163 properties.remove( oldName.toUpperCase() );
164 String newName = testStepProperty.getName();
165 properties.put( newName.toUpperCase(), testStepProperty );
166
167 firePropertyRenamed( oldName, newName );
168 }
169
170 public void addTestStepListener( WsdlTestStepListener listener )
171 {
172 listeners.add( listener );
173 }
174
175 public void removeTestStepListener( WsdlTestStepListener listener )
176 {
177 listeners.remove( listener );
178 }
179
180 protected void firePropertyAdded( String name )
181 {
182 WsdlTestStepListener[] array = listeners.toArray( new WsdlTestStepListener[listeners.size()]);
183 for( WsdlTestStepListener listener : array )
184 {
185 listener.propertyAdded( name );
186 }
187 }
188
189 protected void firePropertyRemoved( String name )
190 {
191 WsdlTestStepListener[] array = listeners.toArray( new WsdlTestStepListener[listeners.size()]);
192 for( WsdlTestStepListener listener : array )
193 {
194 listener.propertyRemoved( name );
195 }
196 }
197
198 protected void firePropertyRenamed( String oldName, String newName )
199 {
200 WsdlTestStepListener[] array = listeners.toArray( new WsdlTestStepListener[listeners.size()]);
201 for( WsdlTestStepListener listener : array )
202 {
203 listener.propertyRenamed( oldName, newName );
204 }
205 }
206
207 protected void firePropertyValueChanged( String name, String oldValue, String newValue )
208 {
209 if( oldValue == null && newValue == null )
210 return;
211
212 if( oldValue != null && oldValue.equals( newValue ))
213 return;
214
215 if( newValue != null && newValue.equals( oldValue ))
216 return;
217
218 WsdlTestStepListener[] array = listeners.toArray( new WsdlTestStepListener[listeners.size()]);
219 for( WsdlTestStepListener listener : array )
220 {
221 listener.propertyValueChanged( name, oldValue, newValue );
222 }
223 }
224
225 public boolean dependsOn( AbstractWsdlModelItem modelItem )
226 {
227 return false;
228 }
229
230 public String getTestStepTitle()
231 {
232 return getTestCase().getTestSuite().getName() + "#" + getTestCase().getName();
233 }
234
235 /***
236 * Called after cloning for custom behaviour
237 *
238 * @param sourceStep step we were cloned from
239 */
240
241 public WsdlTestStep clone( WsdlTestCase targetTestCase, String name)
242 {
243 onSave();
244 TestStepConfig newConfig = (TestStepConfig) getConfig().copy();
245 newConfig.setName( name );
246 return targetTestCase.addTestStep( newConfig );
247 }
248
249 public void finish( TestRunner testRunner, TestRunContext testRunContext )
250 {
251 }
252
253 public void prepare( TestRunner testRunner, TestRunContext testRunContext ) throws Exception
254 {
255 }
256
257 public Collection<WsdlInterface> getRequiredInterfaces()
258 {
259 return new ArrayList<WsdlInterface>();
260 }
261
262 public boolean isDisabled()
263 {
264 return getConfig().getDisabled();
265 }
266
267 public void setDisabled( boolean disabled )
268 {
269 boolean oldDisabled = isDisabled();
270
271 if( disabled )
272 getConfig().setDisabled( disabled );
273 else
274 getConfig().unsetDisabled();
275
276 notifyPropertyChanged( DISABLED_PROPERTY, oldDisabled, disabled );
277 }
278 }