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.List;
18
19 import com.eviware.soapui.config.TestStepConfig;
20 import com.eviware.soapui.impl.wsdl.AbstractWsdlModelItem;
21 import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
22 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
23 import com.eviware.soapui.model.ModelItem;
24 import com.eviware.soapui.model.PanelBuilder;
25 import com.eviware.soapui.model.iface.Interface;
26 import com.eviware.soapui.model.propertyexpansion.MutablePropertyExpansion;
27 import com.eviware.soapui.model.propertyexpansion.PropertyExpansion;
28 import com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils;
29 import com.eviware.soapui.model.support.ModelSupport;
30 import com.eviware.soapui.model.testsuite.TestCaseRunContext;
31 import com.eviware.soapui.model.testsuite.TestCaseRunner;
32 import com.eviware.soapui.model.testsuite.TestStep;
33 import com.eviware.soapui.support.UISupport;
34
35 /***
36 * Base class for WSDL TestCase test steps.
37 *
38 * @author Ole.Matzura
39 */
40
41 abstract public class WsdlTestStep extends AbstractWsdlModelItem<TestStepConfig> implements TestStep
42 {
43 private final WsdlTestCase testCase;
44 private final boolean forLoadTest;
45 private final boolean hasEditor;
46
47 protected WsdlTestStep( WsdlTestCase testCase, TestStepConfig config, boolean hasEditor, boolean forLoadTest )
48 {
49 super( config, testCase, null );
50
51 this.testCase = testCase;
52 this.hasEditor = hasEditor;
53 this.forLoadTest = forLoadTest;
54 }
55
56 public boolean hasEditor()
57 {
58 return hasEditor;
59 }
60
61 public boolean isForLoadTest()
62 {
63 return forLoadTest;
64 }
65
66 protected PanelBuilder<?> createPanelBuilder()
67 {
68 return null;
69 }
70
71 public WsdlTestCase getTestCase()
72 {
73 return testCase;
74 }
75
76 /***
77 * Called from WsdlTestCase when moving a teststep due to no move
78 * functionality in xmlbeans generated arrays.
79 *
80 * @param config
81 * the new config to use, will be a copy of the existing one. The
82 * current will be invalid
83 */
84
85 public void resetConfigOnMove( TestStepConfig config )
86 {
87 setConfig( config );
88 }
89
90 public boolean cancel()
91 {
92 return false;
93 }
94
95 public String getLabel()
96 {
97 String name = getName();
98 if( isDisabled() )
99 return name + " (disabled)";
100 else
101 return name;
102 }
103
104 @Override
105 public void setName( String name )
106 {
107 UISupport.setHourglassCursor();
108
109 try
110 {
111 List<MutablePropertyExpansion> result = new ArrayList<MutablePropertyExpansion>();
112 List<MutablePropertyExpansion> properties = new ArrayList<MutablePropertyExpansion>();
113
114 PropertyExpansion[] propertyExpansions = PropertyExpansionUtils.getPropertyExpansions( getTestCase(), true,
115 true );
116 for( PropertyExpansion pe : propertyExpansions )
117 {
118 MutablePropertyExpansion mpe = ( MutablePropertyExpansion )pe;
119 ModelItem modelItem = mpe.getProperty().getModelItem();
120 if( modelItem == this
121 || ( ( modelItem instanceof WsdlTestRequest && ( ( WsdlTestRequest )modelItem ).getTestStep() == this ) ) )
122 {
123 properties.add( mpe );
124 }
125 }
126
127 String oldLabel = getLabel();
128 super.setName( name );
129
130 String label = getLabel();
131 if( !oldLabel.equals( label ) )
132 {
133 notifyPropertyChanged( LABEL_PROPERTY, oldLabel, label );
134 }
135
136 for( MutablePropertyExpansion mpe : properties )
137 {
138 try
139 {
140 mpe.update();
141 result.add( mpe );
142 }
143 catch( Exception e )
144 {
145 e.printStackTrace();
146 }
147 }
148 }
149 finally
150 {
151 UISupport.resetCursor();
152 }
153 }
154
155 public boolean dependsOn( AbstractWsdlModelItem<?> modelItem )
156 {
157 return false;
158 }
159
160 public String getTestStepTitle()
161 {
162 return getTestCase().getTestSuite().getName() + "#" + getTestCase().getName();
163 }
164
165 /***
166 * Called after cloning for custom behaviour
167 *
168 * @param targetTestCase
169 * step we were cloned from
170 */
171
172 public WsdlTestStep clone( WsdlTestCase targetTestCase, String name )
173 {
174 beforeSave();
175 TestStepConfig newConfig = ( TestStepConfig )getConfig().copy();
176 newConfig.setName( name );
177 WsdlTestStep result = targetTestCase.addTestStep( newConfig );
178 ModelSupport.unsetIds( result );
179 return result;
180 }
181
182 public void finish( TestCaseRunner testRunner, TestCaseRunContext testRunContext )
183 {
184 }
185
186 public void prepare( TestCaseRunner testRunner, TestCaseRunContext testRunContext ) throws Exception
187 {
188 }
189
190 public Collection<Interface> getRequiredInterfaces()
191 {
192 return new ArrayList<Interface>();
193 }
194
195 public boolean isDisabled()
196 {
197 return getConfig().getDisabled();
198 }
199
200 public void setDisabled( boolean disabled )
201 {
202 String oldLabel = getLabel();
203
204 boolean oldDisabled = isDisabled();
205 if( oldDisabled == disabled )
206 return;
207
208 if( disabled )
209 getConfig().setDisabled( disabled );
210 else if( getConfig().isSetDisabled() )
211 getConfig().unsetDisabled();
212
213 notifyPropertyChanged( DISABLED_PROPERTY, oldDisabled, disabled );
214
215 String label = getLabel();
216 notifyPropertyChanged( LABEL_PROPERTY, oldLabel, label );
217 }
218
219 public ModelItem getModelItem()
220 {
221 return this;
222 }
223
224 public String getPropertiesLabel()
225 {
226 return "Test Properties";
227 }
228
229 /***
230 * Default property to use when creating property-transfers where this step
231 * is source
232 */
233
234 public String getDefaultSourcePropertyName()
235 {
236 return null;
237 }
238
239 /***
240 * Default property to use when creating property-transfers where this step
241 * is target
242 */
243
244 public String getDefaultTargetPropertyName()
245 {
246 return null;
247 }
248
249 public void afterCopy( WsdlTestSuite oldTestSuite, WsdlTestCase oldTestCase )
250 {
251 }
252 }