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.teststeps;
014:
015: import junit.framework.TestCase;
016:
017: import com.eviware.soapui.config.ValueTransferConfig;
018: import com.eviware.soapui.impl.wsdl.WsdlSubmitContext;
019: import com.eviware.soapui.model.support.DefaultTestStepProperty;
020:
021: public class PropertyTransferTestCase extends TestCase {
022: private PropertyTransfer transfer;
023: private DefaultTestStepProperty sourceProperty;
024: private DefaultTestStepProperty targetProperty;
025:
026: protected void setUp() throws Exception {
027: super .setUp();
028:
029: transfer = new PropertyTransfer(null,
030: ValueTransferConfig.Factory.newInstance());
031: sourceProperty = new DefaultTestStepProperty("source", null);
032: targetProperty = new DefaultTestStepProperty("target", null);
033: }
034:
035: public void testStringToStringTransfer() throws Exception {
036: PropertyTransfer transfer = new PropertyTransfer(null,
037: ValueTransferConfig.Factory.newInstance());
038: DefaultTestStepProperty sourceProperty = new DefaultTestStepProperty(
039: "source", null);
040: sourceProperty.setValue("Test");
041:
042: DefaultTestStepProperty targetProperty = new DefaultTestStepProperty(
043: "target", null);
044: transfer.transferStringToString(sourceProperty, targetProperty);
045:
046: assertEquals(sourceProperty.getValue(), targetProperty
047: .getValue());
048: }
049:
050: public void testStringToXmlTransfer() throws Exception {
051: sourceProperty.setValue("audi");
052: targetProperty.setValue("<bil><name>bmw</name></bil>");
053:
054: transfer.setTargetPath("//name/text()");
055:
056: transfer.transferStringToXml(sourceProperty, targetProperty,
057: new WsdlSubmitContext(null));
058: assertEquals("<bil><name>audi</name></bil>", targetProperty
059: .getValue());
060:
061: targetProperty
062: .setValue("<bil><name test=\"test\">bmw</name></bil>");
063: transfer.transferStringToXml(sourceProperty, targetProperty,
064: new WsdlSubmitContext(null));
065:
066: assertEquals("<bil><name test=\"test\">audi</name></bil>",
067: targetProperty.getValue());
068:
069: transfer.setTargetPath("//name/@test");
070:
071: transfer.transferStringToXml(sourceProperty, targetProperty,
072: new WsdlSubmitContext(null));
073: assertEquals("<bil><name test=\"audi\">audi</name></bil>",
074: targetProperty.getValue());
075: }
076:
077: public void testXmlToStringTransfer() throws Exception {
078: sourceProperty.setValue("<bil><name>audi</name></bil>");
079: targetProperty.setValue("");
080:
081: transfer.setSourcePath("//name/text()");
082:
083: transfer.transferXmlToString(sourceProperty, targetProperty,
084: new WsdlSubmitContext(null));
085: assertEquals("audi", targetProperty.getValue());
086: }
087:
088: public void testXmlToStringNullTransfer() throws Exception {
089: sourceProperty.setValue("<bil></bil>");
090: targetProperty.setValue("");
091:
092: transfer.setSourcePath("//name/text()");
093:
094: transfer.transferXmlToString(sourceProperty, targetProperty,
095: new WsdlSubmitContext(null));
096: assertEquals(null, targetProperty.getValue());
097: }
098:
099: public void testTextXmlToXmlTransfer() throws Exception {
100: sourceProperty.setValue("<bil><name>audi</name></bil>");
101: targetProperty.setValue("<bil><name>bmw</name></bil>");
102:
103: transfer.setSourcePath("//name/text()");
104: transfer.setTargetPath("//name/text()");
105:
106: transfer.transferXmlToXml(sourceProperty, targetProperty,
107: new WsdlSubmitContext(null));
108: assertEquals(sourceProperty.getValue(), targetProperty
109: .getValue());
110:
111: targetProperty
112: .setValue("<bil><name test=\"test\">bmw</name></bil>");
113: transfer.transferXmlToXml(sourceProperty, targetProperty,
114: new WsdlSubmitContext(null));
115:
116: assertEquals("<bil><name test=\"test\">audi</name></bil>",
117: targetProperty.getValue());
118: }
119:
120: public void testTextContentXmlToXmlTransfer() throws Exception {
121: sourceProperty.setValue("<bil><name>audi</name></bil>");
122: targetProperty.setValue("<bil><name2>bmw</name2></bil>");
123:
124: transfer.setTransferTextContent(true);
125: transfer.setSourcePath("//name");
126: transfer.setTargetPath("//name2");
127:
128: transfer.transferXmlToXml(sourceProperty, targetProperty,
129: new WsdlSubmitContext(null));
130:
131: assertEquals("<bil><name2>audi</name2></bil>", targetProperty
132: .getValue());
133: }
134:
135: public void testTextXmlToXmlNullTransfer() throws Exception {
136: sourceProperty.setValue("<bil><name/></bil>");
137: targetProperty.setValue("<bil><name>bmw</name></bil>");
138:
139: transfer.setSourcePath("//name/text()");
140: transfer.setTargetPath("//name/text()");
141:
142: transfer.transferXmlToXml(sourceProperty, targetProperty,
143: new WsdlSubmitContext(null));
144:
145: assertEquals("<bil><name/></bil>", targetProperty.getValue());
146: }
147:
148: public void testAttributeXmlToXmlTransfer() throws Exception {
149: sourceProperty
150: .setValue("<bil><name value=\"fiat\" value2=\"volvo\">alfa</name></bil>");
151: targetProperty
152: .setValue("<bil><name test=\"test\">bmw</name></bil>");
153:
154: transfer.setSourcePath("//name/@value");
155: transfer.setTargetPath("//name/text()");
156:
157: transfer.transferXmlToXml(sourceProperty, targetProperty,
158: new WsdlSubmitContext(null));
159:
160: assertEquals("<bil><name test=\"test\">fiat</name></bil>",
161: targetProperty.getValue());
162:
163: transfer.setSourcePath("//name/text()");
164: transfer.setTargetPath("//name/@test");
165:
166: transfer.transferXmlToXml(sourceProperty, targetProperty,
167: new WsdlSubmitContext(null));
168:
169: assertEquals("<bil><name test=\"alfa\">fiat</name></bil>",
170: targetProperty.getValue());
171:
172: transfer.setSourcePath("//name/@value2");
173: transfer.transferXmlToXml(sourceProperty, targetProperty,
174: new WsdlSubmitContext(null));
175: assertEquals("<bil><name test=\"volvo\">fiat</name></bil>",
176: targetProperty.getValue());
177: }
178:
179: public void testElementXmlToXmlTransfer() throws Exception {
180: sourceProperty.setValue("<bil><name>audi</name></bil>");
181: targetProperty.setValue("<bil><test/></bil>");
182:
183: transfer.setSourcePath("//bil");
184: transfer.setTargetPath("//bil");
185:
186: transfer.setTransferTextContent(false);
187: transfer.transferXmlToXml(sourceProperty, targetProperty,
188: new WsdlSubmitContext(null));
189: assertEquals(sourceProperty.getValue(), targetProperty
190: .getValue());
191:
192: targetProperty.setValue("<bil><name></name></bil>");
193:
194: transfer.setSourcePath("//bil/name/text()");
195: transfer.setTargetPath("//bil/name");
196:
197: transfer.transferXmlToXml(sourceProperty, targetProperty,
198: new WsdlSubmitContext(null));
199: assertEquals(sourceProperty.getValue(), targetProperty
200: .getValue());
201: }
202:
203: public void testElementWithNsXmlToXmlTransfer() throws Exception {
204: sourceProperty
205: .setValue("<ns1:bil xmlns:ns1=\"ns1\"><ns1:name>audi</ns1:name></ns1:bil>");
206: targetProperty.setValue("<bil><name/></bil>");
207:
208: transfer.setTransferTextContent(false);
209: transfer
210: .setSourcePath("declare namespace ns='ns1';//ns:bil/ns:name");
211: transfer.setTargetPath("//bil/name");
212:
213: transfer.transferXmlToXml(sourceProperty, targetProperty,
214: new WsdlSubmitContext(null));
215: assertEquals(
216: "<bil xmlns:ns1=\"ns1\"><ns1:name>audi</ns1:name></bil>",
217: targetProperty.getValue());
218: }
219:
220: }
|