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.message.RPCElement; 8 import org.apache.axis.message.RPCParam; 9 import org.apache.axis.message.SOAPEnvelope; 10 import org.apache.axis.server.AxisServer; 11 12 import java.util.Vector ; 13 14 20 public class TestHrefs extends TestCase { 21 22 private String header; 23 private String [] messageParts; 24 25 public TestHrefs(String name) { 26 this(name, Constants.URI_DEFAULT_SCHEMA_XSI, 27 Constants.URI_DEFAULT_SCHEMA_XSD); 28 } 29 30 public TestHrefs(String name, String NS_XSI, String NS_XSD) { 31 super(name); 32 33 header = 34 "<?xml version=\"1.0\"?>\n" + 35 "<soap:Envelope " + 36 "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " + 37 "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" " + 38 "xmlns:xsi=\"" + NS_XSI + "\" " + 39 "xmlns:xsd=\"" + NS_XSD + "\">\n" + 40 "<soap:Body>\n" + 41 "<methodResult xmlns=\"http://tempuri.org/\">\n" + 42 "<reference HREF=\"#1\"/>\n" + 43 "</methodResult>\n"; 44 45 messageParts = new String [] { 46 "</soap:Body>\n", 47 48 "</soap:Envelope>\n" }; 49 } 50 51 private void deserialize(String data, Object expected, int pos) 52 throws Exception 53 { 54 String msgString = header; 55 56 for (int i = 0; i < messageParts.length; i++) { 57 if (pos == i) 58 msgString += data; 59 msgString += messageParts[i]; 60 } 61 62 Message message = new Message(msgString); 63 message.setMessageContext(new MessageContext(new AxisServer())); 64 65 SOAPEnvelope envelope = (SOAPEnvelope)message.getSOAPEnvelope(); 66 assertNotNull("SOAP envelope should not be null", envelope); 67 68 RPCElement body = (RPCElement)envelope.getFirstBody(); 69 assertNotNull("SOAP body should not be null", body); 70 71 Vector arglist = body.getParams(); 72 assertNotNull("arglist", arglist); 73 assertTrue("SOAP param.size()<=0 {Should be > 0}", arglist.size()>0); 74 75 RPCParam param = (RPCParam) arglist.get(0); 76 assertNotNull("SOAP param should not be null", param); 77 78 Object result = param.getObjectValue(); 79 assertEquals("Expected result not received for case " + pos, expected, result); 80 } 81 82 public void testStringReference1() throws Exception { 83 String result = 84 "<result root=\"0\" id=\"1\" xsi:type=\"xsd:string\">abc</result>"; 85 deserialize(result, "abc", 0); 86 } 87 88 public void testStringReference2() throws Exception { 89 String result = 90 "<result root=\"0\" id=\"1\" xsi:type=\"xsd:string\">abc</result>"; 91 deserialize(result, "abc", 1); 92 } 93 94 public void testIntReference1() throws Exception { 95 String result = 96 "<result root=\"0\" id=\"1\" xsi:type=\"xsd:int\">567</result>"; 97 deserialize(result, new Integer (567), 0); 98 } 99 } 100 | Popular Tags |