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