View Javadoc

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