001: package org.objectweb.celtix.systest.type_test.soap;
002:
003: import java.net.URL;
004: import java.util.List;
005:
006: import javax.xml.namespace.QName;
007: import javax.xml.soap.SOAPElement;
008: import javax.xml.soap.SOAPFactory;
009: import javax.xml.ws.Holder;
010:
011: import junit.framework.Test;
012: import junit.framework.TestSuite;
013:
014: import org.objectweb.celtix.systest.common.ClientServerSetupBase;
015: import org.objectweb.celtix.systest.type_test.AbstractTypeTestClient4;
016: import org.objectweb.type_test.types2.StructWithAnyArrayLax;
017: import org.objectweb.type_test.types2.StructWithAnyStrict;
018:
019: public class SOAPDocLitClientTypeTest extends AbstractTypeTestClient4 {
020: static final String WSDL_PATH = "/wsdl/type_test/type_test_doclit_soap.wsdl";
021: static final QName SERVICE_NAME = new QName(
022: "http://objectweb.org/type_test/doc", "SOAPService");
023: static final QName PORT_NAME = new QName(
024: "http://objectweb.org/type_test/doc", "SOAPPort");
025:
026: public SOAPDocLitClientTypeTest(String name) {
027: super (name, SERVICE_NAME, PORT_NAME, WSDL_PATH);
028: }
029:
030: public static Test suite() throws Exception {
031: TestSuite suite = new TestSuite(SOAPDocLitClientTypeTest.class);
032: return new ClientServerSetupBase(suite) {
033: public void startServers() throws Exception {
034: boolean ok = launchServer(SOAPDocLitServerImpl.class);
035: assertTrue("failed to launch server", ok);
036: }
037:
038: public void setUp() throws Exception {
039: // set up configuration to enable schema validation
040: URL url = getClass()
041: .getResource("../celtix-config.xml");
042: assertNotNull("cannot find test resource", url);
043: configFileName = url.toString();
044: super .setUp();
045: }
046: };
047: }
048:
049: public void testStructWithAnyStrict() throws Exception {
050: SOAPFactory factory = SOAPFactory.newInstance();
051: SOAPElement elem = factory.createElement(
052: "StringElementQualified", "x1",
053: "http://objectweb.org/type_test/types1");
054: elem.addNamespaceDeclaration("x1",
055: "http://objectweb.org/type_test/types1");
056: elem.addTextNode("This is the text of the node");
057:
058: StructWithAnyStrict x = new StructWithAnyStrict();
059: x.setName("Name x");
060: x.setAddress("Some Address x");
061: x.setAny(elem);
062:
063: elem = factory.createElement("StringElementQualified", "x1",
064: "http://objectweb.org/type_test/types1");
065: elem.addNamespaceDeclaration("x1",
066: "http://objectweb.org/type_test/types1");
067: elem.addTextNode("This is the text of the second node");
068:
069: StructWithAnyStrict yOrig = new StructWithAnyStrict();
070: yOrig.setName("Name y");
071: yOrig.setAddress("Some Address y");
072: yOrig.setAny(elem);
073:
074: Holder<StructWithAnyStrict> y = new Holder<StructWithAnyStrict>(
075: yOrig);
076: Holder<StructWithAnyStrict> z = new Holder<StructWithAnyStrict>();
077: StructWithAnyStrict ret = docClient.testStructWithAnyStrict(x,
078: y, z);
079: if (!perfTestOnly) {
080: assertEqualsStructWithAnyStrict(x, y.value);
081: assertEqualsStructWithAnyStrict(yOrig, z.value);
082: assertEqualsStructWithAnyStrict(x, ret);
083: }
084: }
085:
086: public void testStructWithAnyStrictComplex() throws Exception {
087: SOAPFactory factory = SOAPFactory.newInstance();
088: SOAPElement elem = factory.createElement(
089: "AnonTypeElementQualified", "x1",
090: "http://objectweb.org/type_test/types1");
091: elem.addNamespaceDeclaration("x1",
092: "http://objectweb.org/type_test/types1");
093: SOAPElement floatElem = factory.createElement("varFloat", "x1",
094: "http://objectweb.org/type_test/types1");
095: floatElem.addTextNode("12.5");
096: elem.addChildElement(floatElem);
097: SOAPElement intElem = factory.createElement("varInt", "x1",
098: "http://objectweb.org/type_test/types1");
099: intElem.addTextNode("34");
100: elem.addChildElement(intElem);
101: SOAPElement stringElem = factory.createElement("varString",
102: "x1", "http://objectweb.org/type_test/types1");
103: stringElem.addTextNode("test string within any");
104: elem.addChildElement(stringElem);
105:
106: StructWithAnyStrict x = new StructWithAnyStrict();
107: x.setName("Name x");
108: x.setAddress("Some Address x");
109: x.setAny(elem);
110:
111: elem = factory.createElement("AnonTypeElementQualified", "x1",
112: "http://objectweb.org/type_test/types1");
113: elem.addNamespaceDeclaration("x1",
114: "http://objectweb.org/type_test/types1");
115: floatElem = factory.createElement("varFloat", "x1",
116: "http://objectweb.org/type_test/types1");
117: floatElem.addTextNode("12.76");
118: elem.addChildElement(floatElem);
119: intElem = factory.createElement("varInt", "x1",
120: "http://objectweb.org/type_test/types1");
121: intElem.addTextNode("56");
122: elem.addChildElement(intElem);
123: stringElem = factory.createElement("varString", "x1",
124: "http://objectweb.org/type_test/types1");
125: stringElem.addTextNode("test string");
126: elem.addChildElement(stringElem);
127:
128: StructWithAnyStrict yOrig = new StructWithAnyStrict();
129: yOrig.setName("Name y");
130: yOrig.setAddress("Some Address y");
131: yOrig.setAny(elem);
132:
133: Holder<StructWithAnyStrict> y = new Holder<StructWithAnyStrict>(
134: yOrig);
135: Holder<StructWithAnyStrict> z = new Holder<StructWithAnyStrict>();
136: StructWithAnyStrict ret = docClient.testStructWithAnyStrict(x,
137: y, z);
138: if (!perfTestOnly) {
139: assertEqualsStructWithAnyStrict(x, y.value);
140: assertEqualsStructWithAnyStrict(yOrig, z.value);
141: assertEqualsStructWithAnyStrict(x, ret);
142: }
143: }
144:
145: public void testStructWithAnyArrayLax() throws Exception {
146: SOAPFactory factory = SOAPFactory.newInstance();
147: SOAPElement elem = factory.createElement(
148: "StringElementQualified", "x1",
149: "http://objectweb.org/type_test/types1");
150: elem.addNamespaceDeclaration("x1",
151: "http://objectweb.org/type_test/types1");
152: elem.addTextNode("This is the text of the node");
153:
154: StructWithAnyArrayLax x = new StructWithAnyArrayLax();
155: x.setName("Name x");
156: x.setAddress("Some Address x");
157: x.getAny().add(elem);
158:
159: elem = factory.createElement("StringElementQualified", "x1",
160: "http://objectweb.org/type_test/types1");
161: elem.addNamespaceDeclaration("x1",
162: "http://objectweb.org/type_test/types1");
163: elem
164: .addTextNode("This is the text of the node for the second struct");
165:
166: StructWithAnyArrayLax yOrig = new StructWithAnyArrayLax();
167: yOrig.setName("Name y");
168: yOrig.setAddress("Some Other Address y");
169: yOrig.getAny().add(elem);
170:
171: Holder<StructWithAnyArrayLax> y = new Holder<StructWithAnyArrayLax>(
172: yOrig);
173: Holder<StructWithAnyArrayLax> z = new Holder<StructWithAnyArrayLax>();
174: StructWithAnyArrayLax ret = docClient
175: .testStructWithAnyArrayLax(x, y, z);
176: if (!perfTestOnly) {
177: assertEqualsStructWithAnyArrayLax(x, y.value);
178: assertEqualsStructWithAnyArrayLax(yOrig, z.value);
179: assertEqualsStructWithAnyArrayLax(x, ret);
180: }
181: }
182:
183: public void testStructWithAnyArrayLaxComplex() throws Exception {
184: SOAPFactory factory = SOAPFactory.newInstance();
185: SOAPElement elem = factory.createElement(
186: "AnonTypeElementQualified", "x1",
187: "http://objectweb.org/type_test/types1");
188: elem.addNamespaceDeclaration("x1",
189: "http://objectweb.org/type_test/types1");
190: SOAPElement floatElem = factory.createElement("varFloat", "x1",
191: "http://objectweb.org/type_test/types1");
192: floatElem.addTextNode("12.76");
193: elem.addChildElement(floatElem);
194: SOAPElement intElem = factory.createElement("varInt", "x1",
195: "http://objectweb.org/type_test/types1");
196: intElem.addTextNode("56");
197: elem.addChildElement(intElem);
198: SOAPElement stringElem = factory.createElement("varString",
199: "x1", "http://objectweb.org/type_test/types1");
200: stringElem.addTextNode("test string");
201: elem.addChildElement(stringElem);
202:
203: StructWithAnyArrayLax x = new StructWithAnyArrayLax();
204: x.setName("Name x");
205: x.setAddress("Some Address x");
206: x.getAny().add(elem);
207: StructWithAnyArrayLax yOrig = new StructWithAnyArrayLax();
208: yOrig.setName("Name y");
209: yOrig.setAddress("Some Other Address y");
210: yOrig.getAny().add(elem);
211:
212: Holder<StructWithAnyArrayLax> y = new Holder<StructWithAnyArrayLax>(
213: yOrig);
214: Holder<StructWithAnyArrayLax> z = new Holder<StructWithAnyArrayLax>();
215: StructWithAnyArrayLax ret = docClient
216: .testStructWithAnyArrayLax(x, y, z);
217: if (!perfTestOnly) {
218: assertEqualsStructWithAnyArrayLax(x, y.value);
219: assertEqualsStructWithAnyArrayLax(yOrig, z.value);
220: assertEqualsStructWithAnyArrayLax(x, ret);
221: }
222: }
223:
224: public void assertEqualsStructWithAnyStrict(StructWithAnyStrict a,
225: StructWithAnyStrict b) throws Exception {
226: assertEquals("StructWithAnyStrict names don't match", a
227: .getName(), b.getName());
228: assertEquals("StructWithAnyStrict addresses don't match", a
229: .getAddress(), b.getAddress());
230: if (a.getAny() instanceof SOAPElement
231: && b.getAny() instanceof SOAPElement) {
232: assertEquals((SOAPElement) a.getAny(), (SOAPElement) b
233: .getAny());
234: }
235: }
236:
237: public void assertEqualsStructWithAnyArrayLax(
238: StructWithAnyArrayLax a, StructWithAnyArrayLax b)
239: throws Exception {
240: assertEquals("StructWithAnyArrayLax names don't match", a
241: .getName(), b.getName());
242: assertEquals("StructWithAnyArrayLax addresses don't match", a
243: .getAddress(), b.getAddress());
244:
245: List<Object> ae = a.getAny();
246: List<Object> be = b.getAny();
247: assertEquals(
248: "StructWithAnyArrayLax soap element lengths don't match",
249: ae.size(), be.size());
250: for (int i = 0; i < ae.size(); i++) {
251: if (ae.get(i) instanceof SOAPElement
252: && be.get(i) instanceof SOAPElement) {
253: assertEquals(ae.get(i), be.get(i));
254: }
255: }
256: }
257: }
|