KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > soap12 > TestHrefs


1 package test.soap12;
2
3 import junit.framework.TestCase;
4 import org.apache.axis.AxisFault;
5 import org.apache.axis.Constants;
6 import org.apache.axis.Message;
7 import org.apache.axis.MessageContext;
8 import org.apache.axis.message.RPCElement;
9 import org.apache.axis.message.RPCParam;
10 import org.apache.axis.message.SOAPEnvelope;
11 import org.apache.axis.server.AxisServer;
12 import org.apache.axis.utils.Messages;
13
14 import java.util.Vector JavaDoc;
15
16 /**
17  * Test deserialization of SOAP 1.2 messages with references, by putting the
18  * actual value in various places in the message.
19  */

20 public class TestHrefs extends TestCase {
21
22     private String JavaDoc HEAD;
23     private String JavaDoc HEADERT;
24     private String JavaDoc BODYT;
25
26     public TestHrefs(String JavaDoc name) {
27         this(name, Constants.URI_DEFAULT_SCHEMA_XSI,
28              Constants.URI_DEFAULT_SCHEMA_XSD);
29     }
30
31     public TestHrefs(String JavaDoc name, String JavaDoc NS_XSI, String JavaDoc NS_XSD) {
32         super(name);
33
34         HEAD =
35                 "<?xml version=\"1.0\"?>\n" +
36                 "<soap:Envelope " +
37                 "xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" " +
38                 "xmlns:soapenc=\"http://www.w3.org/2003/05/soap-encoding\" " +
39                 "xmlns:xsi=\"" + NS_XSI + "\" " +
40                 "xmlns:xsd=\"" + NS_XSD + "\">\n" +
41                 "<soap:Header>\n";
42
43         HEADERT = "</soap:Header>\n" +
44                   "<soap:Body>\n" +
45                   "<methodResult xmlns=\"http://tempuri.org/\">\n";
46
47         BODYT = "</methodResult>\n" +
48                  "</soap:Body>\n" +
49                  "</soap:Envelope>\n";
50     }
51
52     private void deserialize(String JavaDoc data, Object JavaDoc expected, int pos)
53             throws Exception JavaDoc
54     {
55         Message message = new Message(data);
56         MessageContext context = new MessageContext(new AxisServer());
57         message.setMessageContext(context);
58         context.setProperty(Constants.MC_NO_OPERATION_OK, Boolean.TRUE);
59
60         SOAPEnvelope envelope = (SOAPEnvelope)message.getSOAPEnvelope();
61         assertNotNull("SOAP envelope should not be null", envelope);
62
63         RPCElement body = (RPCElement)envelope.getFirstBody();
64         assertNotNull("SOAP body should not be null", body);
65
66         Vector JavaDoc arglist = body.getParams();
67         assertNotNull("arglist", arglist);
68         assertTrue("SOAP param.size()<=0 {Should be > 0}", arglist.size()>0);
69
70         RPCParam param = (RPCParam) arglist.get(pos);
71         assertNotNull("SOAP param should not be null", param);
72
73         Object JavaDoc result = param.getObjectValue();
74         assertEquals("Expected result not received", expected, result);
75     }
76
77     public void testStringReference1() throws Exception JavaDoc {
78         String JavaDoc result = HEAD + HEADERT +
79                         "<result root=\"0\" id=\"1\" xsi:type=\"xsd:string\">abc</result>" +
80                         "<reference ref=\"#1\"/>\n" +
81                         BODYT;
82         deserialize(result, "abc", 1);
83     }
84
85     public void testIntReference1() throws Exception JavaDoc {
86         String JavaDoc result = HEAD + HEADERT +
87                         "<result root=\"0\" id=\"1\" xsi:type=\"xsd:int\">567</result>" +
88                         "<reference ref=\"#1\"/>\n" +
89                         BODYT;
90         deserialize(result, new Integer JavaDoc(567), 1);
91     }
92
93     public void testStringReferenceInHeader() throws Exception JavaDoc {
94         String JavaDoc result = HEAD +
95                         "<result root=\"0\" id=\"1\" xsi:type=\"xsd:string\">abc</result>" +
96                         HEADERT +
97                         "<reference ref=\"#1\"/>\n" +
98                         BODYT;
99         deserialize(result, "abc", 0);
100     }
101
102     public void testIDANDHREF() throws Exception JavaDoc {
103         String JavaDoc result = HEAD +
104                         HEADERT +
105                         "<result root=\"0\" ref=\"#1\" id=\"1\" xsi:type=\"xsd:string\">abc</result>" +
106                         BODYT;
107         try {
108             deserialize(result, "abc", 0);
109         } catch (AxisFault af) {
110             assertTrue(af.getFaultString().indexOf(Messages.getMessage("noIDandHREFonSameElement")) != -1 &&
111                                Constants.FAULT_SOAP12_SENDER.equals(af.getFaultCode()));
112             return;
113         }
114         fail("Didn't got the expected fault");
115
116     }
117
118
119 }
Popular Tags