KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > encoding > TestDeser


1 package test.encoding;
2
3 import junit.framework.TestCase;
4 import org.apache.axis.Constants;
5 import org.apache.axis.Message;
6 import org.apache.axis.MessageContext;
7 import org.apache.axis.encoding.TypeMapping;
8 import org.apache.axis.encoding.TypeMappingRegistry;
9 import org.apache.axis.message.RPCElement;
10 import org.apache.axis.message.RPCParam;
11 import org.apache.axis.message.SOAPEnvelope;
12 import org.apache.axis.server.AxisServer;
13 import org.apache.axis.utils.JavaUtils;
14 import samples.echo.SOAPStruct;
15 import samples.echo.SOAPStructStruct;
16
17 import javax.xml.namespace.QName JavaDoc;
18 import java.lang.reflect.Array JavaDoc;
19 import java.util.ArrayList JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Hashtable JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.Set JavaDoc;
26 import java.util.Vector JavaDoc;
27 /**
28  * Test deserialization of SOAP responses
29  */

30 public class TestDeser extends TestCase {
31
32     private String JavaDoc header;
33     private String JavaDoc footer;
34     private AxisServer server = new AxisServer();
35
36     public TestDeser(String JavaDoc name) {
37         this(name, Constants.URI_DEFAULT_SCHEMA_XSI,
38                    Constants.URI_DEFAULT_SCHEMA_XSD);
39     }
40
41     public TestDeser(String JavaDoc name, String JavaDoc NS_XSI, String JavaDoc NS_XSD) {
42         super(name);
43
44         header =
45             "<?xml version=\"1.0\"?>\n" +
46             "<soap:Envelope " +
47               "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
48               "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
49               "xmlns:me=\"http://soapinterop.org/xsd\" " +
50               "xmlns:this=\"http://encoding.test\" " +
51               "xmlns:xsi=\"" + NS_XSI + "\" " +
52               "xmlns:xsd=\"" + NS_XSD + "\">\n" +
53               "<soap:Body>\n" +
54                 "<methodResult xmlns=\"http://tempuri.org/\">\n";
55
56         footer =
57                 "</methodResult>\n" +
58               "</soap:Body>\n" +
59             "</soap:Envelope>\n";
60
61         TypeMappingRegistry tmr = server.getTypeMappingRegistry();
62         TypeMapping tm = (TypeMapping) tmr.createTypeMapping();
63         tm.setSupportedEncodings(new String JavaDoc[] {Constants.URI_DEFAULT_SOAP_ENC});
64         tmr.register(Constants.URI_DEFAULT_SOAP_ENC, tm);
65         tm.register(java.lang.String JavaDoc[].class,
66                     new QName JavaDoc("http://soapinterop.org/xsd", "ArrayOfString"),
67                     new org.apache.axis.encoding.ser.ArraySerializerFactory(),
68                     new org.apache.axis.encoding.ser.ArrayDeserializerFactory());
69         tm.register(java.lang.Object JavaDoc[].class,
70                     new QName JavaDoc("http://soapinterop.org/xsd", "ArrayOfObject"),
71                     new org.apache.axis.encoding.ser.ArraySerializerFactory(),
72                     new org.apache.axis.encoding.ser.ArrayDeserializerFactory());
73         tm.register(samples.echo.SOAPStruct.class,
74                     new QName JavaDoc("http://soapinterop.org/xsd", "SOAPStruct"),
75                     new org.apache.axis.encoding.ser.BeanSerializerFactory(
76                           samples.echo.SOAPStruct.class,
77                           new QName JavaDoc("http://soapinterop.org/xsd", "SOAPStruct")),
78                     new org.apache.axis.encoding.ser.BeanDeserializerFactory(
79                           samples.echo.SOAPStruct.class,
80                           new QName JavaDoc("http://soapinterop.org/xsd", "SOAPStruct")));
81         tm.register(samples.echo.SOAPStruct[].class,
82                     new QName JavaDoc("http://soapinterop.org/xsd", "ArrayOfSOAPStruct"),
83                     new org.apache.axis.encoding.ser.ArraySerializerFactory(),
84                     new org.apache.axis.encoding.ser.ArrayDeserializerFactory());
85         tm.register(samples.echo.SOAPStructStruct.class,
86                     new QName JavaDoc("http://soapinterop.org/xsd", "SOAPStructStruct"),
87                     new org.apache.axis.encoding.ser.BeanSerializerFactory(
88                           samples.echo.SOAPStructStruct.class,
89                           new QName JavaDoc("http://soapinterop.org/xsd", "SOAPStructStruct")),
90                     new org.apache.axis.encoding.ser.BeanDeserializerFactory(
91                           samples.echo.SOAPStructStruct.class,
92                           new QName JavaDoc("http://soapinterop.org/xsd", "SOAPStructStruct")));
93         tm.register(test.encoding.IndexPropBean.class,
94                     new QName JavaDoc("http://encoding.test", "IndexPropBean"),
95                     new org.apache.axis.encoding.ser.BeanSerializerFactory(
96                           test.encoding.IndexPropBean.class,
97                           new QName JavaDoc("http://encoding.test", "IndexPropBean")),
98                     new org.apache.axis.encoding.ser.BeanDeserializerFactory(
99                           test.encoding.IndexPropBean.class,
100                           new QName JavaDoc("http://encoding.test", "IndexPropBean")));
101     }
102
103     /**
104      * Verify that two objects have the same value, handling arrays...
105      */

106     private static boolean equals(Object JavaDoc obj1, Object JavaDoc obj2) {
107        if ( (obj1 == null) || (obj2 == null) ) return (obj1 == obj2);
108        if (obj1.equals(obj2)) return true;
109        if (obj2.getClass().isArray() && obj1.getClass().isArray()) {
110            if (Array.getLength(obj1) != Array.getLength(obj2)) return false;
111            for (int i=0; i<Array.getLength(obj1); i++)
112                if (!equals(Array.get(obj1,i),Array.get(obj2,i))) return false;
113            return true;
114        }
115        if ((obj1 instanceof List JavaDoc) && (obj2 instanceof List JavaDoc)) {
116            List JavaDoc list1 = (List JavaDoc)obj1;
117            List JavaDoc list2 = (List JavaDoc)obj2;
118            if (list1.size() != list2.size()) return false;
119            for (int i=0; i < list1.size(); i++) {
120                if (!equals(list1.get(i), list2.get(i))) return false;
121            }
122            return true;
123        }
124        if ((obj1 instanceof Map JavaDoc) && (obj2 instanceof Map JavaDoc)) {
125            Map JavaDoc map1 = (Map JavaDoc)obj1;
126            Map JavaDoc map2 = (Map JavaDoc)obj2;
127            Set JavaDoc keys1 = map1.keySet();
128            Set JavaDoc keys2 = map2.keySet();
129            if (!(keys1.equals(keys2))) return false;
130            Iterator JavaDoc i = keys1.iterator();
131            while (i.hasNext()) {
132                Object JavaDoc key = i.next();
133                if (!map1.get(key).equals(map2.get(key)))
134                    return false;
135            }
136            return true;
137        }
138        
139        return false;
140     }
141
142     /**
143      * Verify that a given XML deserialized produces the expected result
144      */

145     protected void deserialize(String JavaDoc data, Object JavaDoc expected)
146         throws Exception JavaDoc {
147         deserialize(data, expected, false);
148     }
149
150     protected void deserialize(String JavaDoc data, Object JavaDoc expected, boolean tryConvert)
151             throws Exception JavaDoc {
152         deserialize(data, expected,tryConvert,"");
153     }
154
155
156     /**
157      * Verify that a given XML deserialized produces the expected result
158      * @param data
159      * @param expected
160      * @param tryConvert
161      * @param comment extra text to add
162      * @throws Exception
163      */

164     protected void deserialize(String JavaDoc data, Object JavaDoc expected, boolean tryConvert, String JavaDoc comment)
165        throws Exception JavaDoc
166     {
167        Message message = new Message(header + data + footer);
168        message.setMessageContext(new MessageContext(server));
169        String JavaDoc postfix="";
170        if(comment!=null) {
171            postfix=" "+comment;
172        }
173
174        SOAPEnvelope envelope = (SOAPEnvelope)message.getSOAPEnvelope();
175        assertNotNull("SOAP envelope should not be null"+ postfix, envelope);
176
177        RPCElement body = (RPCElement)envelope.getFirstBody();
178        assertNotNull("SOAP body should not be null" + postfix, body);
179
180        Vector JavaDoc arglist = body.getParams();
181        assertNotNull("arglist", arglist);
182        assertTrue("param.size()<=0 {Should be > 0}" + postfix, arglist.size()>0);
183
184        RPCParam param = (RPCParam) arglist.get(0);
185        assertNotNull("SOAP param should not be null" + postfix, param);
186
187        Object JavaDoc result = param.getObjectValue();
188        if (!equals(result, expected)) {
189            String JavaDoc errorText = "Failed to decode " + data + postfix+" : ";
190            // Try to convert to the expected class
191
if (tryConvert) {
192                Object JavaDoc result2 = JavaUtils.convert(result, expected.getClass());
193                if (!equals(result2, expected)) {
194
195                    assertEquals(errorText, expected, result);
196                }
197            } else {
198                assertEquals(errorText, expected, result);
199            }
200        }
201     }
202
203     public void testString() throws Exception JavaDoc {
204         deserialize("<result xsi:type=\"xsd:string\">abc</result>",
205                     "abc");
206     }
207
208     public void testBoolean() throws Exception JavaDoc {
209         deserialize("<result xsi:type=\"xsd:boolean\">false</result>",
210                     new Boolean JavaDoc(false));
211         deserialize("<result xsi:type=\"xsd:boolean\">true</result>",
212                     new Boolean JavaDoc(true));
213         deserialize("<result xsi:type=\"xsd:boolean\">0</result>",
214                     new Boolean JavaDoc(false));
215         deserialize("<result xsi:type=\"xsd:boolean\">1</result>",
216                     new Boolean JavaDoc(true));
217     }
218
219     public void testDouble() throws Exception JavaDoc {
220         deserialize("<result xsi:type=\"xsd:double\">3.14</result>",
221                     new Double JavaDoc(3.14));
222     }
223
224     public void testDoubleNaN() throws Exception JavaDoc {
225         deserialize("<result xsi:type=\"xsd:double\">NaN</result>",
226                     new Double JavaDoc(Double.NaN));
227     }
228
229     public void testDoubleINF() throws Exception JavaDoc {
230         deserialize("<result xsi:type=\"xsd:double\">INF</result>",
231                     new Double JavaDoc(Double.POSITIVE_INFINITY));
232     }
233
234     public void testDoubleNINF() throws Exception JavaDoc {
235         deserialize("<result xsi:type=\"xsd:double\">-INF</result>",
236                     new Double JavaDoc(Double.NEGATIVE_INFINITY));
237     }
238
239     public void testFloat() throws Exception JavaDoc {
240         deserialize("<result xsi:type=\"xsd:float\">3.14</result>",
241                     new Float JavaDoc(3.14F));
242     }
243
244     public void testFloatNaN() throws Exception JavaDoc {
245         deserialize("<result xsi:type=\"xsd:float\">NaN</result>",
246                     new Float JavaDoc(Float.NaN));
247     }
248
249     public void testFloatINF() throws Exception JavaDoc {
250         deserialize("<result xsi:type=\"xsd:float\">INF</result>",
251                     new Float JavaDoc(Float.POSITIVE_INFINITY));
252     }
253
254     public void testFloatNINF() throws Exception JavaDoc {
255         deserialize("<result xsi:type=\"xsd:float\">-INF</result>",
256                     new Float JavaDoc(Float.NEGATIVE_INFINITY));
257     }
258
259     public void testInt() throws Exception JavaDoc {
260         deserialize("<result xsi:type=\"xsd:int\">10</result>",
261                     new Integer JavaDoc(10));
262     }
263
264     public void testLong() throws Exception JavaDoc {
265         deserialize("<result xsi:type=\"xsd:long\">17</result>",
266                     new Long JavaDoc(17));
267     }
268
269     public void testShort() throws Exception JavaDoc {
270         deserialize("<result xsi:type=\"xsd:short\">3</result>",
271                     new Short JavaDoc((short)3));
272     }
273
274     public void testArray() throws Exception JavaDoc {
275         Vector JavaDoc v = new Vector JavaDoc();
276         v.addElement("abc");
277         v.addElement("def");
278         deserialize("<result xsi:type=\"soapenc:Array\" " +
279                             "soapenc:arrayType=\"xsd:string[2]\"> " +
280                        "<item xsi:type=\"xsd:string\">abc</item>" +
281                        "<item xsi:type=\"xsd:string\">def</item>" +
282                     "</result>",
283                     v, true);
284     }
285     
286     public void testSparseArray1() throws Exception JavaDoc {
287         ArrayList JavaDoc list = new ArrayList JavaDoc(4);
288         list.add(null);
289         list.add(null);
290         list.add("abc");
291         list.add("def");
292         deserialize("<result xsi:type=\"soapenc:Array\" " +
293                             "soapenc:arrayType=\"xsd:string[4]\" " +
294                             "soapenc:offset=\"[2]\"> " +
295                        "<item xsi:type=\"xsd:string\">abc</item>" +
296                        "<item xsi:type=\"xsd:string\">def</item>" +
297                     "</result>",
298                     list, true);
299     }
300     
301     public void testSparseArray2() throws Exception JavaDoc {
302         ArrayList JavaDoc list = new ArrayList JavaDoc(4);
303         list.add("abc");
304         list.add(null);
305         list.add("def");
306         deserialize("<result xsi:type=\"soapenc:Array\" " +
307                             "soapenc:arrayType=\"xsd:string[4]\"> " +
308       "<item soapenc:position=\"[0]\" xsi:type=\"xsd:string\">abc</item>" +
309       "<item soapenc:position=\"[2]\" xsi:type=\"xsd:string\">def</item>" +
310                     "</result>",
311                     list, true);
312     }
313
314     public void testHugeSparseArray() throws Exception JavaDoc {
315         ArrayList JavaDoc list = new ArrayList JavaDoc(4);
316         list.add("abc");
317         list.add(null);
318         list.add("def");
319         deserialize("<result xsi:type=\"soapenc:Array\" " +
320                             "soapenc:arrayType=\"xsd:string[50000000]\"> " +
321       "<item soapenc:position=\"[0]\" xsi:type=\"xsd:string\">abc</item>" +
322       "<item soapenc:position=\"[2]\" xsi:type=\"xsd:string\">def</item>" +
323                     "</result>",
324                     list, true);
325     }
326     public void testMap() throws Exception JavaDoc {
327         HashMap JavaDoc m = new HashMap JavaDoc();
328         m.put("abcKey", "abcVal");
329         m.put("defKey", "defVal");
330         deserialize("<result xsi:type=\"xmlsoap:Map\" " +
331                     "xmlns:xmlsoap=\"http://xml.apache.org/xml-soap\"> " +
332                       "<item>" +
333                        "<key xsi:type=\"xsd:string\">abcKey</key>" +
334                        "<value xsi:type=\"xsd:string\">abcVal</value>" +
335                       "</item><item>" +
336                        "<key xsi:type=\"xsd:string\">defKey</key>" +
337                        "<value xsi:type=\"xsd:string\">defVal</value>" +
338                       "</item>" +
339                     "</result>",
340                     m);
341     }
342
343     public void testHashtable() throws Exception JavaDoc {
344         Hashtable JavaDoc ht = new Hashtable JavaDoc();
345         ht.put("abcKey", "abcVal");
346         ht.put("defKey", "defVal");
347         deserialize("<result xsi:type=\"xmlsoap:Map\" " +
348                     "xmlns:xmlsoap=\"http://xml.apache.org/xml-soap\"> " +
349                       "<item>" +
350                        "<key xsi:type=\"xsd:string\">abcKey</key>" +
351                        "<value xsi:type=\"xsd:string\">abcVal</value>" +
352                       "</item><item>" +
353                        "<key xsi:type=\"xsd:string\">defKey</key>" +
354                        "<value xsi:type=\"xsd:string\">defVal</value>" +
355                       "</item>" +
356                     "</result>",
357                     ht, true);
358     }
359
360     public void testUntyped() throws Exception JavaDoc {
361          deserialize("<result>10</result>", "10");
362     }
363
364     public void testSOAPString() throws Exception JavaDoc {
365         deserialize("<result xsi:type=\"soapenc:string\">abc</result>",
366                     "abc");
367     }
368
369     // Complicated array tests
370

371     // type=soapenc:Array
372
public void testArrayA() throws Exception JavaDoc {
373         String JavaDoc[] s = new String JavaDoc[] {"abc", "def"};
374         deserialize("<result xsi:type=\"soapenc:Array\" " +
375                             "soapenc:arrayType=\"xsd:string[2]\"> " +
376                        "<item xsi:type=\"xsd:string\">abc</item>" +
377                        "<item xsi:type=\"xsd:string\">def</item>" +
378                     "</result>",
379                     s, true);
380     }
381
382     // Like above but missing [2] dimension
383
public void testArrayB() throws Exception JavaDoc {
384         String JavaDoc[] s = new String JavaDoc[] {"abc", "def"};
385         deserialize("<result xsi:type=\"soapenc:Array\" " +
386                             "soapenc:arrayType=\"xsd:string[]\"> " +
387                        "<item xsi:type=\"xsd:string\">abc</item>" +
388                        "<item xsi:type=\"xsd:string\">def</item>" +
389                     "</result>",
390                     s, true);
391     }
392
393
394     // Like above but no xsi:type on elements
395
public void testArrayC() throws Exception JavaDoc {
396         String JavaDoc[] s = new String JavaDoc[] {"abc", "def"};
397         deserialize("<result xsi:type=\"soapenc:Array\" " +
398                             "soapenc:arrayType=\"xsd:string[]\"> " +
399                        "<item>abc</item>" +
400                        "<item>def</item>" +
401                     "</result>",
402                     s, true);
403     }
404
405     // Now try with arrayType=xsd:anyType
406
public void testArrayD() throws Exception JavaDoc {
407         String JavaDoc[] s = new String JavaDoc[] {"abc", "def"};
408         deserialize("<result xsi:type=\"soapenc:Array\" " +
409                        "soapenc:arrayType=\"xsd:anyType[]\"> " +
410                        "<item xsi:type=\"xsd:string\">abc</item>" +
411                        "<item xsi:type=\"xsd:string\">def</item>" +
412                     "</result>",
413                     s, true);
414     }
415
416     // Now try without arrayType
417
public void testArrayE() throws Exception JavaDoc {
418         String JavaDoc[] s = new String JavaDoc[] {"abc", "def"};
419         deserialize("<result xsi:type=\"soapenc:Array\" " +
420                        "> " +
421                        "<item xsi:type=\"xsd:string\">abc</item>" +
422                        "<item xsi:type=\"xsd:string\">def</item>" +
423                     "</result>",
424                     s, true);
425     }
426
427     // Use a specific array type, not soapenc:Array
428
public void testArrayF() throws Exception JavaDoc {
429         String JavaDoc[] s = new String JavaDoc[] {"abc", "def"};
430         deserialize("<result xsi:type=\"me:ArrayOfString\" " +
431                        "> " +
432                        "<item xsi:type=\"xsd:string\">abc</item>" +
433                        "<item xsi:type=\"xsd:string\">def</item>" +
434                     "</result>",
435                     s, true);
436     }
437
438     // Same as above without individual item types
439
public void testArrayG() throws Exception JavaDoc {
440         String JavaDoc[] s = new String JavaDoc[] {"abc", "def"};
441         deserialize("<result xsi:type=\"me:ArrayOfString\" " +
442                        "> " +
443                        "<item>abc</item>" +
444                        "<item>def</item>" +
445                     "</result>",
446                     s, true);
447     }
448
449     // Same as above except result is an Object[]
450
public void testArrayH() throws Exception JavaDoc {
451         Object JavaDoc[] s = new Object JavaDoc[] {new String JavaDoc("abc"), new String JavaDoc("def")};
452         deserialize("<result xsi:type=\"me:ArrayOfString\" " +
453                        "> " +
454                        "<item>abc</item>" +
455                        "<item>def</item>" +
456                     "</result>",
457                     s, true);
458     }
459
460     // Ooh La La
461
// Array of Object containing a String and an Integer
462
public void testArrayI() throws Exception JavaDoc {
463         Object JavaDoc[] s = new Object JavaDoc[] {new String JavaDoc("abc"), new Integer JavaDoc(123)};
464         deserialize("<result xsi:type=\"me:ArrayOfObject\" " +
465                        "> " +
466                        "<item xsi:type=\"xsd:string\">abc</item>" +
467                        "<item xsi:type=\"soapenc:int\">123</item>" +
468                     "</result>",
469                     s, true);
470     }
471
472     // Same as above using arrayType=xsd:anyType
473
public void testArrayJ() throws Exception JavaDoc {
474         Object JavaDoc[] s = new Object JavaDoc[] {new String JavaDoc("abc"), new Integer JavaDoc(123)};
475         deserialize("<result xsi:type=\"me:ArrayOfObject\" " +
476                        "soapenc:arrayType=\"xsd:anyType[]\"> " +
477                        "<item xsi:type=\"xsd:string\">abc</item>" +
478                        "<item xsi:type=\"soapenc:int\">123</item>" +
479                     "</result>",
480                     s, true);
481     }
482
483     // Same as above using type=soapenc:Array and no arrayType...bare bones
484
public void testArrayK() throws Exception JavaDoc {
485         Object JavaDoc[] s = new Object JavaDoc[] {new String JavaDoc("abc"), new Integer JavaDoc(123)};
486         deserialize("<result xsi:type=\"soapenc:Array\" " +
487                        "> " +
488                        "<item xsi:type=\"xsd:string\">abc</item>" +
489                        "<item xsi:type=\"soapenc:int\">123</item>" +
490                     "</result>",
491                     s, true);
492     }
493
494     // This was created from a return received from a .NET service
495
public void testArrayL() throws Exception JavaDoc {
496         SOAPStruct[] s = new SOAPStruct[] {
497                 new SOAPStruct(),
498                 new SOAPStruct(),
499                 new SOAPStruct()};
500             s[0].setVarInt(1);
501             s[0].setVarString("one");
502             s[0].setVarFloat(1.1F);
503             s[1].setVarInt(2);
504             s[1].setVarString("two");
505             s[1].setVarFloat(2.2F);
506             s[2].setVarInt(3);
507             s[2].setVarString("three");
508             s[2].setVarFloat(3.3F);
509
510         deserialize("<soapenc:Array id=\"ref-7\" soapenc:arrayType=\"me:SOAPStruct[3]\">" +
511                     "<item HREF=\"#ref-8\"/>" +
512                     "<item HREF=\"#ref-9\"/>" +
513                     "<item HREF=\"#ref-10\"/>" +
514                     "</soapenc:Array>" +
515
516                     "<me:SOAPStruct id=\"ref-8\">" +
517                     "<varString xsi:type=\"xsd:string\">one</varString>" +
518                     "<varInt xsi:type=\"xsd:int\">1</varInt>" +
519                     "<varFloat xsi:type=\"xsd:float\">1.1</varFloat>" +
520                     "</me:SOAPStruct>" +
521
522                     "<me:SOAPStruct id=\"ref-9\">" +
523                     "<varString xsi:type=\"xsd:string\">two</varString>" +
524                     "<varInt xsi:type=\"xsd:int\">2</varInt>" +
525                     "<varFloat xsi:type=\"xsd:float\">2.2</varFloat>" +
526                     "</me:SOAPStruct>" +
527
528                     "<me:SOAPStruct id=\"ref-10\">" +
529                     "<varString xsi:type=\"xsd:string\">three</varString>" +
530                     "<varInt xsi:type=\"xsd:int\">3</varInt>" +
531                     "<varFloat xsi:type=\"xsd:float\">3.3</varFloat>" +
532                     "</me:SOAPStruct>",
533                     s, true);
534     }
535
536     // Like above without multiref
537
public void testArrayM() throws Exception JavaDoc {
538         SOAPStruct[] s = new SOAPStruct[] {
539                 new SOAPStruct(),
540                 new SOAPStruct(),
541                 new SOAPStruct()};
542             s[0].setVarInt(1);
543             s[0].setVarString("one");
544             s[0].setVarFloat(1.1F);
545             s[1].setVarInt(2);
546             s[1].setVarString("two");
547             s[1].setVarFloat(2.2F);
548             s[2].setVarInt(3);
549             s[2].setVarString("three");
550             s[2].setVarFloat(3.3F);
551         deserialize("<soapenc:Array id=\"ref-7\" soapenc:arrayType=\"me:SOAPStruct[3]\">" +
552                     "<me:SOAPStruct>" +
553                     "<varString xsi:type=\"xsd:string\">one</varString>" +
554                     "<varInt xsi:type=\"xsd:int\">1</varInt>" +
555                     "<varFloat xsi:type=\"xsd:float\">1.1</varFloat>" +
556                     "</me:SOAPStruct>" +
557
558                     "<me:SOAPStruct>" +
559                     "<varString xsi:type=\"xsd:string\">two</varString>" +
560                     "<varInt xsi:type=\"xsd:int\">2</varInt>" +
561                     "<varFloat xsi:type=\"xsd:float\">2.2</varFloat>" +
562                     "</me:SOAPStruct>" +
563
564                     "<me:SOAPStruct>" +
565                     "<varString xsi:type=\"xsd:string\">three</varString>" +
566                     "<varInt xsi:type=\"xsd:int\">3</varInt>" +
567                     "<varFloat xsi:type=\"xsd:float\">3.3</varFloat>" +
568                     "</me:SOAPStruct>" +
569
570                     "</soapenc:Array>",
571                     s, true);
572     }
573     // Deserialize Bean with discreet names
574
public void testBeanWithIndexedPropA() throws Exception JavaDoc {
575         IndexPropBean s = new IndexPropBean();
576         s.setName(new String JavaDoc[] {"hello", "goodbye"});
577         deserialize("<result xsi:type=\"this:IndexPropBean\" " + "> " +
578                     "<name HREF=\"#ref-1\"/>" +
579                     "<name HREF=\"#ref-2\"/>" +
580                     "</result>" +
581                     "<item id=\"ref-1\" xsi:type=\"xsd:string\">hello</item>" +
582                     "<item id=\"ref-2\" xsi:type=\"xsd:string\">goodbye</item>",
583                     s, true);
584     }
585     // Deserialize Bean with names in an array
586
public void testBeanWithIndexedPropB() throws Exception JavaDoc {
587         IndexPropBean s = new IndexPropBean();
588         s.setName(new String JavaDoc[] {"hello", "goodbye"});
589         deserialize("<result xsi:type=\"this:IndexPropBean\" " + "> " +
590                     "<name HREF=\"#ref-0\" /> " +
591                     "</result>" +
592                     "<soapenc:Array id=\"ref-0\" soapenc:arrayType=\"xsd:string[2]\"> " +
593                     "<item xsi:type=\"xsd:string\">hello</item>" +
594                     "<item xsi:type=\"xsd:string\">goodbye</item>" +
595                     "</soapenc:Array>",
596                     s, true);
597     }
598     // Struct within Struct
599
public void testStructStruct() throws Exception JavaDoc {
600
601         SOAPStruct s = new samples.echo.SOAPStruct();
602         s.setVarInt(1);
603         s.setVarString("one");
604         s.setVarFloat(1.1F);
605         SOAPStructStruct ss = new SOAPStructStruct();
606         ss.setVarString("hello");
607         ss.setVarInt(2);
608         ss.setVarFloat(2.2F);
609         ss.setVarStruct(s);
610
611         deserialize("<whatever xsi:type=\"me:SOAPStructStruct\">" +
612                     "<varString xsi:type=\"xsd:string\">hello</varString>" +
613                     "<varInt xsi:type=\"xsd:int\">2</varInt>" +
614                     "<varFloat xsi:type=\"xsd:float\">2.2</varFloat>" +
615                     "<varStruct xsi:type=\"me:SOAPStruct\">" +
616                     "<varString xsi:type=\"xsd:string\">one</varString>" +
617                     "<varInt xsi:type=\"xsd:int\">1</varInt>" +
618                     "<varFloat xsi:type=\"xsd:float\">1.1</varFloat>" +
619                     "</varStruct>" +
620                     "</whatever>" , ss, true);
621     }
622     
623 /*
624     public void testBug18390() throws Exception {
625         String[] s = new String[] {"GW671055X"};
626         deserialize("<molNames soapenc:arrayType=\"xsd:string[1]\"> " +
627                        "<xsd:string xsi:type=\"xsd:string\">GW671055X</xsd:string>" +
628                     "</molNames>",
629                     s, true);
630     }
631     
632     public void testBug25536() throws Exception {
633         int[] array = new int[]{3,4};
634         deserialize("<myFavoriteNumbers soapenc:arrayType=\"xsd:int[2]\">\n" +
635                 " <number>3</number> \n" +
636                 " <number>4</number> \n" +
637                 "</myFavoriteNumbers>",array,true);
638     }
639 */

640
641     // Struct within Struct
642
public void testStructStruct2() throws Exception JavaDoc {
643         SOAPStruct s = new samples.echo.SOAPStruct();
644         s.setVarInt(1);
645         s.setVarString("one");
646         s.setVarFloat(1.1F);
647         SOAPStructStruct ss = new SOAPStructStruct();
648         ss.setVarString("hello");
649         ss.setVarInt(2);
650         ss.setVarFloat(2.2F);
651         ss.setVarStruct(s);
652
653         deserialize("<whatever xsi:type=\"me:SOAPStructStruct\">" +
654                     "<varString>hello</varString>" +
655                     "<varInt>2</varInt>" +
656                     "<varFloat>2.2</varFloat>" +
657                     "<varStruct>" +
658                     "<varString>one</varString>" +
659                     "<varInt>1</varInt>" +
660                     "<varFloat>1.1</varFloat>" +
661                     "</varStruct>" +
662                     "</whatever>" , ss, true);
663     }
664 }
665
Popular Tags