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.HashMap;
19  import java.util.HashSet;
20  import java.util.List;
21  import java.util.Map;
22  import java.util.Set;
23  
24  import com.eviware.soapui.config.TestStepConfig;
25  import com.eviware.soapui.impl.wsdl.AbstractWsdlModelItem;
26  import com.eviware.soapui.impl.wsdl.WsdlInterface;
27  import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
28  import com.eviware.soapui.model.ModelItem;
29  import com.eviware.soapui.model.PanelBuilder;
30  import com.eviware.soapui.model.propertyexpansion.MutablePropertyExpansion;
31  import com.eviware.soapui.model.propertyexpansion.PropertyExpansion;
32  import com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils;
33  import com.eviware.soapui.model.testsuite.TestProperty;
34  import com.eviware.soapui.model.testsuite.TestPropertyListener;
35  import com.eviware.soapui.model.testsuite.TestRunContext;
36  import com.eviware.soapui.model.testsuite.TestRunner;
37  import com.eviware.soapui.model.testsuite.TestStep;
38  import com.eviware.soapui.support.UISupport;
39  
40  /***
41   * Base class for WSDL TestCase test steps.
42   * 
43   * @author Ole.Matzura
44   */
45  
46  abstract public class WsdlTestStepWithProperties extends WsdlTestStep
47  {
48  	private Map<String, TestProperty> properties;
49  	private Set<TestPropertyListener> listeners = new HashSet<TestPropertyListener>();
50  
51  	protected WsdlTestStepWithProperties( WsdlTestCase testCase, TestStepConfig config, boolean hasEditor, boolean forLoadTest )
52  	{
53  		super( testCase, config, hasEditor, forLoadTest );
54  	}
55  
56  	public String[] getPropertyNames()
57  	{
58  		if( properties == null )
59  			return new String[0];
60  
61  		String[] result = new String[properties.size()];
62  		int ix = 0;
63  		for( TestProperty property : properties.values() )
64  			result[ix++] = property.getName();
65  
66  		return result;
67  	}
68  
69  	public TestProperty getProperty( String name )
70  	{
71  		return properties == null || name == null ? null : properties.get( name.toUpperCase() );
72  	}
73  
74  	public String getPropertyValue( String name )
75  	{
76  		if( properties == null )
77  			return null;
78  
79  		TestProperty testStepProperty = properties.get( name.toUpperCase() );
80  		return testStepProperty == null ? null : testStepProperty.getValue();
81  	}
82  
83  	public void setPropertyValue( String name, String value )
84  	{
85  		if( properties == null )
86  			return;
87  
88  		TestProperty testStepProperty = properties.get( name.toUpperCase() );
89  		if( testStepProperty != null )
90  		{
91  			testStepProperty.setValue( value );
92  		}
93  	}
94  
95  	protected void addProperty( TestProperty property )
96  	{
97  		if( properties == null )
98  			properties = new HashMap<String, TestProperty>();
99  
100 		properties.put( property.getName().toUpperCase(), property );
101 	}
102 
103 	protected void deleteProperty( String name )
104 	{
105 		if( properties != null )
106 			properties.remove( name.toUpperCase() );
107 	}
108 
109 	public void propertyRenamed( String oldName )
110 	{
111 		if( properties == null )
112 			return;
113 
114 		TestProperty testStepProperty = properties.get( oldName.toUpperCase() );
115 		if( testStepProperty == null )
116 			return;
117 
118 		properties.remove( oldName.toUpperCase() );
119 		String newName = testStepProperty.getName();
120 		properties.put( newName.toUpperCase(), testStepProperty );
121 
122 		firePropertyRenamed( oldName, newName );
123 	}
124 
125 	public void addTestPropertyListener( TestPropertyListener listener )
126 	{
127 		listeners.add( listener );
128 	}
129 
130 	public void removeTestPropertyListener( TestPropertyListener listener )
131 	{
132 		listeners.remove( listener );
133 	}
134 
135 	protected void firePropertyAdded( String name )
136 	{
137 		TestPropertyListener[] array = listeners.toArray( new TestPropertyListener[listeners.size()] );
138 		for( TestPropertyListener listener : array )
139 		{
140 			listener.propertyAdded( name );
141 		}
142 	}
143 
144 	protected void firePropertyRemoved( String name )
145 	{
146 		TestPropertyListener[] array = listeners.toArray( new TestPropertyListener[listeners.size()] );
147 		for( TestPropertyListener listener : array )
148 		{
149 			listener.propertyRemoved( name );
150 		}
151 	}
152 
153 	protected void firePropertyRenamed( String oldName, String newName )
154 	{
155 		TestPropertyListener[] array = listeners.toArray( new TestPropertyListener[listeners.size()] );
156 		for( TestPropertyListener listener : array )
157 		{
158 			listener.propertyRenamed( oldName, newName );
159 		}
160 	}
161 
162 	public void firePropertyValueChanged( String name, String oldValue, String newValue )
163 	{
164 		if( oldValue == null && newValue == null )
165 			return;
166 
167 		if( oldValue != null && oldValue.equals( newValue ) )
168 			return;
169 
170 		if( newValue != null && newValue.equals( oldValue ) )
171 			return;
172 
173 		TestPropertyListener[] array = listeners.toArray( new TestPropertyListener[listeners.size()] );
174 		for( TestPropertyListener listener : array )
175 		{
176 			listener.propertyValueChanged( name, oldValue, newValue );
177 		}
178 	}
179 
180 	public Map<String, TestProperty> getProperties()
181 	{
182 		Map<String, TestProperty> result = new HashMap<String, TestProperty>();
183 		for( String name : properties.keySet() )
184 			result.put( name, properties.get( name ) );
185 
186 		return result;
187 	}
188 
189 	public boolean hasProperty( String name )
190 	{
191 		return properties != null && properties.containsKey( name.toUpperCase() );
192 	}
193 
194 	public boolean hasProperties()
195 	{
196 		return true;
197 	}
198 }