View Javadoc

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