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