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