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.model.support;
14  
15  import java.util.Collection;
16  import java.util.Map;
17  import java.util.Set;
18  
19  import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
20  import com.eviware.soapui.model.iface.SubmitContext;
21  import com.eviware.soapui.model.testsuite.TestRunContext;
22  import com.eviware.soapui.model.testsuite.TestStep;
23  import com.eviware.soapui.model.testsuite.TestStepProperty;
24  import com.eviware.soapui.support.types.StringToObjectMap;
25  
26  public abstract class AbstractSubmitContext implements SubmitContext, Map<String,Object>
27  {
28  	private StringToObjectMap properties;
29  	
30  	public AbstractSubmitContext()
31  	{
32  		setProperty( TestRunContext.RUN_COUNT, 0 );
33  		setProperty( TestRunContext.THREAD_INDEX, 0 );
34  	}
35  	
36  	public AbstractSubmitContext(PropertiesMap properties)
37  	{
38  		this();
39  		
40  		if( properties != null && properties.size() > 0 )
41  			this.properties.putAll( properties );
42  	}
43  
44  	public Object getProperty(String name, TestStep testStep, WsdlTestCase testCase )
45  	{
46  		if( properties != null && properties.containsKey( name ))
47  			return properties.get( name );
48  
49  		if( testCase != null )
50  		{
51  			int ix = name.indexOf( PROPERTY_SEPARATOR );
52  			if( ix > 0 )
53  			{
54  				String teststepname = name.substring(0, ix);
55  				TestStep refTestStep = testCase.getTestStepByName( teststepname );
56  				if( refTestStep != null )
57  				{
58  					TestStepProperty property = refTestStep.getProperty( name.substring(ix+1));
59  					return property == null ? null : property.getValue();
60  				}
61  			}
62  			
63  			if( testCase.getSearchProperties() )
64  			{
65  				ix = testStep == null ? testCase.getTestStepCount()-1 : testCase.getIndexOfTestStep( testStep );
66  				if( ix >= testCase.getTestStepCount() )
67  					ix = testCase.getTestStepCount()-1;
68  				
69  				while( ix >= 0 )
70  				{
71  					TestStepProperty property = testCase.getTestStepAt( ix ).getProperty( name );
72  					if( property != null )
73  						return property.getValue();
74  					
75  					ix--;
76  				}
77  			}
78  		}
79  		
80  		return null;
81  	}
82  	
83  	public Object removeProperty(String name)
84  	{
85  		return properties == null ? null : properties.remove( name );
86  	}
87  
88  	public void setProperty(String name, Object value)
89  	{
90  		if( properties == null )
91  			properties = new StringToObjectMap();
92  		
93  		properties.put( name, value );
94  	}
95  
96  	public boolean hasProperty(String name)
97  	{
98  		return properties == null ? false : properties.containsKey( name );
99  	}
100 	
101 	public void resetProperties()
102 	{
103 		if( properties != null )
104 			properties.clear();
105 	}
106 
107 	public void clear()
108 	{
109 		properties.clear();
110 	}
111 
112 	public Object clone()
113 	{
114 		return properties.clone();
115 	}
116 
117 	public boolean containsKey( Object key )
118 	{
119 		return properties.containsKey( key );
120 	}
121 
122 	public boolean containsValue( Object value )
123 	{
124 		return properties.containsValue( value );
125 	}
126 
127 	public Set<Entry<String, Object>> entrySet()
128 	{
129 		return properties.entrySet();
130 	}
131 
132 	public boolean equals( Object o )
133 	{
134 		return properties.equals( o );
135 	}
136 
137 	public Object get( Object key )
138 	{
139 		return properties.get( key );
140 	}
141 
142 	public int hashCode()
143 	{
144 		return properties.hashCode();
145 	}
146 
147 	public boolean isEmpty()
148 	{
149 		return properties.isEmpty();
150 	}
151 
152 	public Set<String> keySet()
153 	{
154 		return properties.keySet();
155 	}
156 
157 	public Object put( String key, Object value )
158 	{
159 		return properties.put( key, value );
160 	}
161 
162 	public void putAll( Map<? extends String, ? extends Object> m )
163 	{
164 		properties.putAll( m );
165 	}
166 
167 	public Object remove( Object key )
168 	{
169 		return properties.remove( key );
170 	}
171 
172 	public int size()
173 	{
174 		return properties.size();
175 	}
176 
177 	public String toString()
178 	{
179 		return properties.toString();
180 	}
181 
182 	public Collection<Object> values()
183 	{
184 		return properties.values();
185 	}
186 	
187 	public StringToObjectMap getProperties()
188 	{
189 		return properties;
190 	}
191 }