KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > encoding > TestHrefs


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 JavaDoc;
13
14 /**
15  * Test deserialization of SOAP messages with references, by putting the
16  * actual value in various places in the message.
17  *
18  * @author Glen Daniels (gdaniels@apache.org)
19  */

20 public class TestHrefs extends TestCase {
21
22     private String JavaDoc header;
23     private String JavaDoc [] messageParts;
24     
25     public TestHrefs(String JavaDoc name) {
26         this(name, Constants.URI_DEFAULT_SCHEMA_XSI,
27                    Constants.URI_DEFAULT_SCHEMA_XSD);
28     }
29
30     public TestHrefs(String JavaDoc name, String JavaDoc NS_XSI, String JavaDoc 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 JavaDoc [] {
46               "</soap:Body>\n",
47         
48              "</soap:Envelope>\n" };
49     }
50
51     private void deserialize(String JavaDoc data, Object JavaDoc expected, int pos)
52        throws Exception JavaDoc
53     {
54        String JavaDoc 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 JavaDoc 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 JavaDoc result = param.getObjectValue();
79        assertEquals("Expected result not received for case " + pos, expected, result);
80     }
81
82     public void testStringReference1() throws Exception JavaDoc {
83         String JavaDoc 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 JavaDoc {
89         String JavaDoc 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 JavaDoc {
95         String JavaDoc result =
96             "<result root=\"0\" id=\"1\" xsi:type=\"xsd:int\">567</result>";
97         deserialize(result, new Integer JavaDoc(567), 0);
98     }
99 }
100
Popular Tags