KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > encoding > TestBeanDeser3


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
14 import javax.xml.namespace.QName JavaDoc;
15 import java.util.Vector JavaDoc;
16
17 /**
18  * Test deserialization of SOAP responses. Test case for Bug 25179
19  * (BeanDeserializer cannot deserialize child array unless xsi:type="SE:Array" provided)
20  */

21 public class TestBeanDeser3 extends TestCase {
22
23     private String JavaDoc header;
24     private String JavaDoc footer;
25     private AxisServer server = new AxisServer();
26
27     public TestBeanDeser3(String JavaDoc name) {
28         super(name);
29         header =
30                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
31                 "<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\n" +
32                 " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
33                 " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" +
34                 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
35                 " xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
36                 "<SOAP-ENV:Body>\n";
37         footer =
38                 "</SOAP-ENV:Body>\n" +
39                 "</SOAP-ENV:Envelope>\n";
40
41         TypeMappingRegistry tmr = server.getTypeMappingRegistry();
42         TypeMapping tm = (TypeMapping) tmr.createTypeMapping();
43         tm.setSupportedEncodings(new String JavaDoc[]{Constants.URI_DEFAULT_SOAP_ENC});
44         tmr.register(Constants.URI_DEFAULT_SOAP_ENC, tm);
45         tm.register(test.encoding.beans.SbTravelRequest.class,
46                 new QName JavaDoc("http://www.sidestep.com/sbws", "SbTravelRequest"),
47                 new org.apache.axis.encoding.ser.BeanSerializerFactory(
48                         test.encoding.beans.SbTravelRequest.class,
49                         new QName JavaDoc("http://www.sidestep.com/sbws", "SbTravelRequest")),
50                 new org.apache.axis.encoding.ser.BeanDeserializerFactory(
51                         test.encoding.beans.SbTravelRequest.class,
52                         new QName JavaDoc("http://www.sidestep.com/sbws", "SbTravelRequest")));
53         tm.register(test.encoding.beans.SbSupplier.class,
54                 new QName JavaDoc("http://www.sidestep.com/sbws", "SbSupplier"),
55                 new org.apache.axis.encoding.ser.BeanSerializerFactory(
56                         test.encoding.beans.SbSupplier.class,
57                         new QName JavaDoc("http://www.sidestep.com/sbws", "SbSupplier")),
58                 new org.apache.axis.encoding.ser.BeanDeserializerFactory(
59                         test.encoding.beans.SbSupplier.class,
60                         new QName JavaDoc("http://www.sidestep.com/sbws", "SbSupplier")));
61     }
62
63     protected Object JavaDoc deserialize(String JavaDoc data)
64             throws Exception JavaDoc {
65         Message message = new Message(header + data + footer);
66         message.setMessageContext(new MessageContext(server));
67
68         SOAPEnvelope envelope = (SOAPEnvelope) message.getSOAPEnvelope();
69         assertNotNull("SOAP envelope should not be null", envelope);
70
71         RPCElement body = (RPCElement) envelope.getFirstBody();
72         assertNotNull("SOAP body should not be null", body);
73
74         Vector JavaDoc arglist = body.getParams();
75         assertNotNull("arglist", arglist);
76         assertTrue("param.size()<=0 {Should be > 0}", arglist.size() > 0);
77
78         RPCParam param = (RPCParam) arglist.get(0);
79         assertNotNull("SOAP param should not be null", param);
80
81         return param.getObjectValue();
82     }
83
84     public void testTravelRequest() throws Exception JavaDoc {
85         String JavaDoc response =
86                 "<startSearch>\n" +
87                 " <arg0 HREF=\"#id0\"/>\n" +
88                 "</startSearch>\n" +
89                 "<multiRef id=\"id0\" SOAP-ENC:root=\"0\"\n" +
90                 " encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\n" +
91                 " xsi:type=\"ns2:SbTravelRequest\"\n" +
92                 " xmlns:ns1=\"http://schemas.xmlsoap.org/soap/envelope/:encodingStyle\"\n" +
93                 " xmlns:ns2=\"http://www.sidestep.com/sbws\">\n" +
94                 "<requestOr xsi:type=\"xsd:string\">SOAP test 1</requestOr>\n" +
95                 "<homeCountry xsi:type=\"xsd:string\">US</homeCountry>\n" +
96                 "<departureLocation xsi:type=\"xsd:string\">SJC</departureLocation>\n" +
97                 "<destinationLocation xsi:type=\"xsd:string\">ATL</destinationLocation>\n" +
98                 "<startDate xsi:type=\"xsd:dateTime\">2002-08-10T13:42:24.024Z</startDate>\n" +
99                 "<endDate xsi:type=\"xsd:dateTime\">2002-06-27T13:42:24.024Z</endDate>\n" +
100                 "<searchTypes xsi:type=\"xsd:string\">AIR:RTACR</searchTypes>\n" +
101                 "<searchParams xsi:nil=\"true\"/>\n" +
102                 "<searchHints xsi:nil=\"true\"/>\n" +
103                 "<supPliers xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"ns2:SbSupplier[1]\">\n" +
104                 " <item HREF=\"#id1\"/>\n" +
105                 "</supPliers>\n" +
106                 "</multiRef>" +
107                 "<multiRef id=\"id1\" SOAP-ENC:root=\"0\"" +
108                 " encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"" +
109                 " xsi:type=\"ns3:SbSupplier\"" +
110                 " xmlns:ns3=\"http://www.sidestep.com/sbws\">" +
111                 " <searchType xsi:type=\"xsd:int\">0</searchType>" +
112                 " <supplierCode xsi:type=\"xsd:string\">SC**</supplierCode>" +
113                 " <chanNel xsi:type=\"xsd:string\">CN**</chanNel>" +
114                 "<listOfStrings " +
115                 "SOAP-ENC:arrayType=\"xsd:string[3]\"> " +
116                 "<item xsi:type=\"xsd:string\">abc</item>" +
117                 "<item xsi:nil=\"true\"/>" +
118                 "<item xsi:type=\"xsd:string\">def</item>" +
119                 "</listOfStrings>" +
120                 "</multiRef>";
121
122         test.encoding.beans.SbTravelRequest travelRequest = (test.encoding.beans.SbTravelRequest) deserialize(response);
123         assertNotNull("supPliers array missing", travelRequest.supPliers);
124         assertTrue(travelRequest.supPliers.length == 1);
125         assertTrue(travelRequest.supPliers[0].searchType.intValue() == 0);
126         assertTrue(travelRequest.supPliers[0].supplierCode.equals("SC**"));
127         assertTrue(travelRequest.supPliers[0].chanNel.equals("CN**"));
128     }
129
130     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
131         TestBeanDeser3 tester = new TestBeanDeser3("test");
132         tester.testTravelRequest();
133     }
134 }
135
Popular Tags