001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.mock;
014:
015: import java.util.Collection;
016: import java.util.Map;
017: import java.util.Set;
018:
019: import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext;
020: import com.eviware.soapui.model.mock.MockRunContext;
021: import com.eviware.soapui.model.testsuite.TestCase;
022: import com.eviware.soapui.model.testsuite.TestRunContext;
023: import com.eviware.soapui.model.testsuite.TestRunner;
024: import com.eviware.soapui.model.testsuite.TestStep;
025: import com.eviware.soapui.model.testsuite.TestStepProperty;
026: import com.eviware.soapui.support.types.StringToObjectMap;
027: import com.eviware.soapui.support.types.StringToStringMap;
028:
029: /**
030: * MockRunContext available during dispatching of a WsdlMockRequest
031: *
032: * @author ole.matzura
033: */
034:
035: public class WsdlMockRunContext implements MockRunContext,
036: Map<String, Object>, TestRunContext {
037: private StringToObjectMap properties;
038: private final WsdlMockService mockService;
039: private final WsdlTestRunContext context;
040:
041: public WsdlMockRunContext(WsdlMockService mockService,
042: WsdlTestRunContext context) {
043: this .mockService = mockService;
044: this .context = context;
045:
046: properties = context == null ? new StringToObjectMap()
047: : context.getProperties();
048: }
049:
050: public WsdlMockService getMockService() {
051: return mockService;
052: }
053:
054: public Object getProperty(String name) {
055: return properties.get(name);
056: }
057:
058: public boolean hasProperty(String name) {
059: return properties.containsKey(name);
060: }
061:
062: public Object removeProperty(String name) {
063: return properties.remove(name);
064: }
065:
066: public void setProperty(String name, Object value) {
067: if (context != null) {
068: int ix = name.indexOf(PROPERTY_SEPARATOR);
069: if (ix > 0) {
070: String teststepname = name.substring(0, ix);
071: TestStep refTestStep = context.getTestCase()
072: .getTestStepByName(teststepname);
073: if (refTestStep != null) {
074: TestStepProperty property = refTestStep
075: .getProperty(name.substring(ix + 1));
076: if (property != null && !property.isReadOnly()) {
077: property.setValue(value.toString());
078: return;
079: }
080: }
081: }
082: }
083:
084: properties.put(name, value);
085: }
086:
087: public StringToStringMap toStringToStringMap() {
088: StringToStringMap result = new StringToStringMap();
089:
090: for (String key : properties.keySet()) {
091: Object value = properties.get(key);
092: if (value != null)
093: result.put(key, value.toString());
094: }
095:
096: return result;
097: }
098:
099: public void clear() {
100: properties.clear();
101: }
102:
103: public Object clone() {
104: return properties.clone();
105: }
106:
107: public boolean containsKey(Object arg0) {
108: return properties.containsKey(arg0);
109: }
110:
111: public boolean containsValue(Object arg0) {
112: return properties.containsValue(arg0);
113: }
114:
115: public Set<Entry<String, Object>> entrySet() {
116: return properties.entrySet();
117: }
118:
119: public boolean equals(Object arg0) {
120: return properties.equals(arg0);
121: }
122:
123: public Object get(Object arg0) {
124: return properties.get(arg0);
125: }
126:
127: public int hashCode() {
128: return properties.hashCode();
129: }
130:
131: public boolean isEmpty() {
132: return properties.isEmpty();
133: }
134:
135: public Set<String> keySet() {
136: return properties.keySet();
137: }
138:
139: public Object put(String arg0, Object arg1) {
140: return properties.put(arg0, arg1);
141: }
142:
143: public void putAll(Map<? extends String, ? extends Object> arg0) {
144: properties.putAll(arg0);
145: }
146:
147: public Object remove(Object arg0) {
148: return properties.remove(arg0);
149: }
150:
151: public int size() {
152: return properties.size();
153: }
154:
155: public String toString() {
156: return properties.toString();
157: }
158:
159: public Collection<Object> values() {
160: return properties.values();
161: }
162:
163: public TestStep getCurrentStep() {
164: return context == null ? null : context.getCurrentStep();
165: }
166:
167: public int getCurrentStepIndex() {
168: return context == null ? -1 : context.getCurrentStepIndex();
169: }
170:
171: public Object getProperty(String testStep, String propertyName) {
172: return context == null ? null : context.getProperty(testStep,
173: propertyName);
174: }
175:
176: public TestRunner getTestRunner() {
177: return context == null ? null : context.getTestRunner();
178: }
179:
180: public TestCase getTestCase() {
181: // TODO Auto-generated method stub
182: return null;
183: }
184: }
|