View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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  
25  public abstract class AbstractSubmitContext implements SubmitContext, Map<String,Object>
26  {
27  	private PropertiesMap properties;
28  	
29  	public AbstractSubmitContext()
30  	{
31  		setProperty( TestRunContext.RUN_COUNT, 0 );
32  		setProperty( TestRunContext.THREAD_INDEX, 0 );
33  	}
34  	
35  	public AbstractSubmitContext(PropertiesMap properties)
36  	{
37  		this();
38  		
39  		if( properties != null && properties.size() > 0 )
40  			this.properties.putAll( properties );
41  	}
42  
43  	public Object getProperty(String name, TestStep testStep, WsdlTestCase testCase )
44  	{
45  		if( properties != null && properties.containsKey( name ))
46  			return properties.get( name );
47  
48  		if( testCase != null )
49  		{
50  			int ix = name.indexOf( PROPERTY_SEPARATOR );
51  			if( ix > 0 )
52  			{
53  				String teststepname = name.substring(0, ix);
54  				TestStep refTestStep = testCase.getTestStepByName( teststepname );
55  				if( refTestStep != null )
56  				{
57  					TestStepProperty property = refTestStep.getProperty( name.substring(ix+1));
58  					return property == null ? null : property.getValue();
59  				}
60  			}
61  			
62  			if( testCase.getSearchProperties() )
63  			{
64  				ix = testStep == null ? testCase.getTestStepCount()-1 : testCase.getIndexOfTestStep( testStep );
65  				if( ix >= testCase.getTestStepCount() )
66  					ix = testCase.getTestStepCount()-1;
67  				
68  				while( ix >= 0 )
69  				{
70  					TestStepProperty property = testCase.getTestStepAt( ix ).getProperty( name );
71  					if( property != null )
72  						return property.getValue();
73  					
74  					ix--;
75  				}
76  			}
77  		}
78  		
79  		return null;
80  	}
81  	
82  	public Object removeProperty(String name)
83  	{
84  		return properties == null ? null : properties.remove( name );
85  	}
86  
87  	public void setProperty(String name, Object value)
88  	{
89  		if( properties == null )
90  			properties = new PropertiesMap();
91  		
92  		properties.put( name, value );
93  	}
94  
95  	public boolean hasProperty(String name)
96  	{
97  		return properties == null ? false : properties.containsKey( name );
98  	}
99  	
100 	public void resetProperties()
101 	{
102 		if( properties != null )
103 			properties.clear();
104 	}
105 
106 	public void clear()
107 	{
108 		properties.clear();
109 	}
110 
111 	public Object clone()
112 	{
113 		return properties.clone();
114 	}
115 
116 	public boolean containsKey( Object key )
117 	{
118 		return properties.containsKey( key );
119 	}
120 
121 	public boolean containsValue( Object value )
122 	{
123 		return properties.containsValue( value );
124 	}
125 
126 	public Set<Entry<String, Object>> entrySet()
127 	{
128 		return properties.entrySet();
129 	}
130 
131 	public boolean equals( Object o )
132 	{
133 		return properties.equals( o );
134 	}
135 
136 	public Object get( Object key )
137 	{
138 		return properties.get( key );
139 	}
140 
141 	public int hashCode()
142 	{
143 		return properties.hashCode();
144 	}
145 
146 	public boolean isEmpty()
147 	{
148 		return properties.isEmpty();
149 	}
150 
151 	public Set<String> keySet()
152 	{
153 		return properties.keySet();
154 	}
155 
156 	public Object put( String key, Object value )
157 	{
158 		return properties.put( key, value );
159 	}
160 
161 	public void putAll( Map<? extends String, ? extends Object> m )
162 	{
163 		properties.putAll( m );
164 	}
165 
166 	public Object remove( Object key )
167 	{
168 		return properties.remove( key );
169 	}
170 
171 	public int size()
172 	{
173 		return properties.size();
174 	}
175 
176 	public String toString()
177 	{
178 		return properties.toString();
179 	}
180 
181 	public Collection<Object> values()
182 	{
183 		return properties.values();
184 	}
185 	
186 	
187 }