View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
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 		if( getName().equals( name ) )
108 			return;
109 
110 		UISupport.setHourglassCursor();
111 
112 		try
113 		{
114 			List<MutablePropertyExpansion> result = new ArrayList<MutablePropertyExpansion>();
115 			List<MutablePropertyExpansion> properties = new ArrayList<MutablePropertyExpansion>();
116 
117 			PropertyExpansion[] propertyExpansions = PropertyExpansionUtils.getPropertyExpansions( getTestCase(), true,
118 					true );
119 			for( PropertyExpansion pe : propertyExpansions )
120 			{
121 				MutablePropertyExpansion mpe = ( MutablePropertyExpansion )pe;
122 				ModelItem modelItem = mpe.getProperty().getModelItem();
123 				if( modelItem == this
124 						|| ( ( modelItem instanceof WsdlTestRequest && ( ( WsdlTestRequest )modelItem ).getTestStep() == this ) ) )
125 				{
126 					properties.add( mpe );
127 				}
128 			}
129 
130 			String oldLabel = getLabel();
131 			super.setName( name );
132 
133 			String label = getLabel();
134 			if( !oldLabel.equals( label ) )
135 			{
136 				notifyPropertyChanged( LABEL_PROPERTY, oldLabel, label );
137 			}
138 
139 			for( MutablePropertyExpansion mpe : properties )
140 			{
141 				try
142 				{
143 					mpe.update();
144 					result.add( mpe );
145 				}
146 				catch( Exception e )
147 				{
148 					e.printStackTrace();
149 				}
150 			}
151 		}
152 		finally
153 		{
154 			UISupport.resetCursor();
155 		}
156 	}
157 
158 	public boolean dependsOn( AbstractWsdlModelItem<?> modelItem )
159 	{
160 		return false;
161 	}
162 
163 	public String getTestStepTitle()
164 	{
165 		return getTestCase().getTestSuite().getName() + "#" + getTestCase().getName();
166 	}
167 
168 	/***
169 	 * Called after cloning for custom behaviour
170 	 * 
171 	 * @param targetTestCase
172 	 *           step we were cloned from
173 	 */
174 
175 	public WsdlTestStep clone( WsdlTestCase targetTestCase, String name )
176 	{
177 		beforeSave();
178 		TestStepConfig newConfig = ( TestStepConfig )getConfig().copy();
179 		newConfig.setName( name );
180 		WsdlTestStep result = targetTestCase.addTestStep( newConfig );
181 		ModelSupport.unsetIds( result );
182 		return result;
183 	}
184 
185 	public void finish( TestCaseRunner testRunner, TestCaseRunContext testRunContext )
186 	{
187 	}
188 
189 	public void prepare( TestCaseRunner testRunner, TestCaseRunContext testRunContext ) throws Exception
190 	{
191 	}
192 
193 	public Collection<Interface> getRequiredInterfaces()
194 	{
195 		return new ArrayList<Interface>();
196 	}
197 
198 	public boolean isDisabled()
199 	{
200 		return getConfig().getDisabled();
201 	}
202 
203 	public void setDisabled( boolean disabled )
204 	{
205 		String oldLabel = getLabel();
206 
207 		boolean oldDisabled = isDisabled();
208 		if( oldDisabled == disabled )
209 			return;
210 
211 		if( disabled )
212 			getConfig().setDisabled( disabled );
213 		else if( getConfig().isSetDisabled() )
214 			getConfig().unsetDisabled();
215 
216 		notifyPropertyChanged( DISABLED_PROPERTY, oldDisabled, disabled );
217 
218 		String label = getLabel();
219 		notifyPropertyChanged( LABEL_PROPERTY, oldLabel, label );
220 	}
221 
222 	public ModelItem getModelItem()
223 	{
224 		return this;
225 	}
226 
227 	public String getPropertiesLabel()
228 	{
229 		return "Test Properties";
230 	}
231 
232 	/***
233 	 * Default property to use when creating property-transfers where this step
234 	 * is source
235 	 */
236 
237 	public String getDefaultSourcePropertyName()
238 	{
239 		return null;
240 	}
241 
242 	/***
243 	 * Default property to use when creating property-transfers where this step
244 	 * is target
245 	 */
246 
247 	public String getDefaultTargetPropertyName()
248 	{
249 		return null;
250 	}
251 
252 	public void afterCopy( WsdlTestSuite oldTestSuite, WsdlTestCase oldTestCase )
253 	{
254 	}
255 }