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.mock;
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.WsdlTestRunContext;
20  import com.eviware.soapui.model.mock.MockRunContext;
21  import com.eviware.soapui.model.mock.MockService;
22  import com.eviware.soapui.model.testsuite.TestCase;
23  import com.eviware.soapui.model.testsuite.TestRunContext;
24  import com.eviware.soapui.model.testsuite.TestRunner;
25  import com.eviware.soapui.model.testsuite.TestStep;
26  import com.eviware.soapui.support.types.StringToObjectMap;
27  import com.eviware.soapui.support.types.StringToStringMap;
28  
29  public class WsdlMockRunContext implements MockRunContext, Map<String,Object>, TestRunContext
30  {
31  	private StringToObjectMap properties;
32  	private final WsdlMockService mockService;
33  	private final WsdlTestRunContext context; 
34  	
35  	public WsdlMockRunContext( WsdlMockService mockService, WsdlTestRunContext context )
36  	{
37  		this.mockService = mockService;
38  		this.context = context;
39  		
40  		properties = context == null ? new StringToObjectMap() : context.getProperties(); 
41  	}
42  
43  	public MockService getMockService()
44  	{
45  		return mockService;
46  	}
47  
48  	public Object getProperty( String name )
49  	{
50  		return properties.get( name );
51  	}
52  
53  	public boolean hasProperty( String name )
54  	{
55  		return properties.containsKey( name );
56  	}
57  
58  	public Object removeProperty( String name )
59  	{
60  		return properties.remove( name );
61  	}
62  
63  	public void setProperty( String name, Object value )
64  	{
65  		properties.put( name, value );
66  	}
67  
68  	public StringToStringMap toStringToStringMap()
69  	{
70  		StringToStringMap result = new StringToStringMap();
71  		
72  		for( String key : properties.keySet() )
73  		{
74  			Object value = properties.get( key );
75  			if( value != null )
76  				result.put( key, value.toString() );
77  		}
78  		
79  		return result;
80  	}
81  
82  	public void clear()
83  	{
84  		properties.clear();
85  	}
86  
87  	public Object clone()
88  	{
89  		return properties.clone();
90  	}
91  
92  	public boolean containsKey( Object arg0 )
93  	{
94  		return properties.containsKey( arg0 );
95  	}
96  
97  	public boolean containsValue( Object arg0 )
98  	{
99  		return properties.containsValue( arg0 );
100 	}
101 
102 	public Set<Entry<String, Object>> entrySet()
103 	{
104 		return properties.entrySet();
105 	}
106 
107 	public boolean equals( Object arg0 )
108 	{
109 		return properties.equals( arg0 );
110 	}
111 
112 	public Object get( Object arg0 )
113 	{
114 		return properties.get( arg0 );
115 	}
116 
117 	public int hashCode()
118 	{
119 		return properties.hashCode();
120 	}
121 
122 	public boolean isEmpty()
123 	{
124 		return properties.isEmpty();
125 	}
126 
127 	public Set<String> keySet()
128 	{
129 		return properties.keySet();
130 	}
131 
132 	public Object put( String arg0, Object arg1 )
133 	{
134 		return properties.put( arg0, arg1 );
135 	}
136 
137 	public void putAll( Map<? extends String, ? extends Object> arg0 )
138 	{
139 		properties.putAll( arg0 );
140 	}
141 
142 	public Object remove( Object arg0 )
143 	{
144 		return properties.remove( arg0 );
145 	}
146 
147 	public int size()
148 	{
149 		return properties.size();
150 	}
151 
152 	public String toString()
153 	{
154 		return properties.toString();
155 	}
156 
157 	public Collection<Object> values()
158 	{
159 		return properties.values();
160 	}
161 
162 	public TestStep getCurrentStep()
163 	{
164 		return context == null ? null : context.getCurrentStep();
165 	}
166 
167 	public int getCurrentStepIndex()
168 	{
169 		return context == null ? -1 : context.getCurrentStepIndex();
170 	}
171 
172 	public Object getProperty( String testStep, String propertyName )
173 	{
174 		return context == null ? null : context.getProperty( testStep, propertyName );
175 	}
176 
177 	public TestRunner getTestRunner()
178 	{
179 		return context == null ? null : context.getTestRunner();
180 	}
181 
182 	public TestCase getTestCase()
183 	{
184 		// TODO Auto-generated method stub
185 		return null;
186 	}
187 }