KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > util > xml > idefix > test > DynamoInteropTest


1 package org.sapia.util.xml.idefix.test;
2
3 import junit.framework.TestCase;
4 import junit.textui.TestRunner;
5 import org.sapia.util.xml.idefix.XmlBuffer;
6
7
8 /**
9  *
10  *
11  * @author Jean-Cedric Desrochers
12  *
13  * <dl>
14  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
15  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
16  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
17  * </dl>
18  */

19 public class DynamoInteropTest extends TestCase {
20
21   public static final String JavaDoc SOAP_NAMESPACE_URI = "http://schemas.xmlsoap.org/soap/envelope/";
22   public static final String JavaDoc SOAP_NAMESPACE_PREFIX = "SOAP-ENV";
23   public static final String JavaDoc DYNAMO_NAMESPACE_URI = "http://schemas.sapia.org/dynamo/interoperability/";
24   public static final String JavaDoc DYNAMO_NAMESPACE_PREFIX = "DYN-IOP";
25
26   public static void main(String JavaDoc[] args) {
27     TestRunner.run(DynamoInteropTest.class);
28   }
29
30   public DynamoInteropTest(String JavaDoc aName) {
31     super(aName);
32   }
33
34
35   public void testPollRequest() throws Exception JavaDoc {
36     XmlBuffer aBuffer = createXmlBufferForRequest();
37     aBuffer.startElement(SOAP_NAMESPACE_URI, "Body").
38               startElement(DYNAMO_NAMESPACE_URI, "Poll").
39                 startElement(DYNAMO_NAMESPACE_URI, "commandId").addContent("675432").endElement(DYNAMO_NAMESPACE_URI, "commandId").
40               endElement(DYNAMO_NAMESPACE_URI, "Poll").
41             endElement(SOAP_NAMESPACE_URI, "Body").
42           endElement(SOAP_NAMESPACE_URI, "Envelope");
43
44     String JavaDoc aBody =
45         "<DYN-IOP:Poll xmlns:DYN-IOP=\"http://schemas.sapia.org/dynamo/interoperability/\">" +
46           "<DYN-IOP:commandId>675432</DYN-IOP:commandId>" +
47         "</DYN-IOP:Poll>" ;
48     assertRequestXmlBuffer(aBuffer, aBody);
49   }
50
51
52   public void testStatusRequest() throws Exception JavaDoc {
53     XmlBuffer aBuffer = createXmlBufferForRequest();
54     aBuffer.startElement(SOAP_NAMESPACE_URI, "Body").
55               startElement(DYNAMO_NAMESPACE_URI, "Status").
56               addAttribute(SOAP_NAMESPACE_URI, "encodingStyle", "http://schemas.sapia.org/dynamo/encoding/").
57                 startElement(DYNAMO_NAMESPACE_URI, "commandId").addContent("675433").endElement(DYNAMO_NAMESPACE_URI, "commandId").
58                 startElement(DYNAMO_NAMESPACE_URI, "topic").
59                   addAttribute("name", "someTopic").
60                   startElement(DYNAMO_NAMESPACE_URI, "item").
61                     addAttribute("name", "item1").addAttribute("value", "item1_value").
62                   endElement(DYNAMO_NAMESPACE_URI, "item").
63                   startElement(DYNAMO_NAMESPACE_URI, "item").
64                     addAttribute("name", "item2").addAttribute("value", "item2_value").
65                   endElement(DYNAMO_NAMESPACE_URI, "item").
66                 endElement(DYNAMO_NAMESPACE_URI, "topic").
67                 startElement(DYNAMO_NAMESPACE_URI, "topic").
68                   addAttribute("name", "someOtherTopic").
69                   startElement(DYNAMO_NAMESPACE_URI, "item").
70                     addAttribute("name", "item1").addAttribute("value", "item1_value").
71                   endElement(DYNAMO_NAMESPACE_URI, "item").
72                   startElement(DYNAMO_NAMESPACE_URI, "item").
73                     addAttribute("name", "item2").addAttribute("value", "item2_value").
74                   endElement(DYNAMO_NAMESPACE_URI, "item").
75                 endElement(DYNAMO_NAMESPACE_URI, "topic").
76               endElement(DYNAMO_NAMESPACE_URI, "Status").
77             endElement(SOAP_NAMESPACE_URI, "Body").
78           endElement(SOAP_NAMESPACE_URI, "Envelope");
79
80     String JavaDoc aBody =
81         "<DYN-IOP:Status xmlns:DYN-IOP=\"http://schemas.sapia.org/dynamo/interoperability/\"" +
82         " SOAP-ENV:encodingStyle=\"http://schemas.sapia.org/dynamo/encoding/\">" +
83           "<DYN-IOP:commandId>675433</DYN-IOP:commandId>" +
84               "<DYN-IOP:topic name=\"someTopic\">" +
85                 "<DYN-IOP:item name=\"item1\" value=\"item1_value\" />" +
86                 "<DYN-IOP:item name=\"item2\" value=\"item2_value\" />" +
87             "</DYN-IOP:topic>" +
88             "<DYN-IOP:topic name=\"someOtherTopic\">" +
89                 "<DYN-IOP:item name=\"item1\" value=\"item1_value\" />" +
90                 "<DYN-IOP:item name=\"item2\" value=\"item2_value\" />" +
91             "</DYN-IOP:topic>" +
92       "</DYN-IOP:Status>" ;
93     assertRequestXmlBuffer(aBuffer, aBody);
94   }
95
96
97   public void testConfirmShutdownRequest() throws Exception JavaDoc {
98     XmlBuffer aBuffer = createXmlBufferForRequest();
99     aBuffer.startElement(SOAP_NAMESPACE_URI, "Body").
100               startElement(DYNAMO_NAMESPACE_URI, "ConfirmShutdown").
101                 startElement(DYNAMO_NAMESPACE_URI, "commandId").addContent("675434").endElement(DYNAMO_NAMESPACE_URI, "commandId").
102               endElement(DYNAMO_NAMESPACE_URI, "ConfirmShutdown").
103             endElement(SOAP_NAMESPACE_URI, "Body").
104           endElement(SOAP_NAMESPACE_URI, "Envelope");
105
106     String JavaDoc aBody =
107         "<DYN-IOP:ConfirmShutdown xmlns:DYN-IOP=\"http://schemas.sapia.org/dynamo/interoperability/\">" +
108           "<DYN-IOP:commandId>675434</DYN-IOP:commandId>" +
109         "</DYN-IOP:ConfirmShutdown>" ;
110     assertRequestXmlBuffer(aBuffer, aBody);
111   }
112
113
114   public void testAckResponse() throws Exception JavaDoc {
115     XmlBuffer aBuffer = createXmlBufferForResponse();
116     aBuffer.startElement(SOAP_NAMESPACE_URI, "Body").
117               startElement(DYNAMO_NAMESPACE_URI, "Ack").endElement(DYNAMO_NAMESPACE_URI, "Ack").
118             endElement(SOAP_NAMESPACE_URI, "Body").
119           endElement(SOAP_NAMESPACE_URI, "Envelope");
120
121     String JavaDoc aBody =
122         "<DYN-IOP:Ack xmlns:DYN-IOP=\"http://schemas.sapia.org/dynamo/interoperability/\" />";
123     assertResponseXmlBuffer(aBuffer, aBody);
124   }
125
126
127   public void testShutdownResponse() throws Exception JavaDoc {
128     XmlBuffer aBuffer = createXmlBufferForResponse();
129     aBuffer.startElement(SOAP_NAMESPACE_URI, "Body").
130               startElement(DYNAMO_NAMESPACE_URI, "Shutdown").
131                 startElement(DYNAMO_NAMESPACE_URI, "commandId").addContent("1234").endElement(DYNAMO_NAMESPACE_URI, "commandId").
132               endElement(DYNAMO_NAMESPACE_URI, "Shutdown").
133             endElement(SOAP_NAMESPACE_URI, "Body").
134           endElement(SOAP_NAMESPACE_URI, "Envelope");
135
136     String JavaDoc aBody =
137         "<DYN-IOP:Shutdown xmlns:DYN-IOP=\"http://schemas.sapia.org/dynamo/interoperability/\">" +
138           "<DYN-IOP:commandId>1234</DYN-IOP:commandId>" +
139         "</DYN-IOP:Shutdown>";
140     assertResponseXmlBuffer(aBuffer, aBody);
141   }
142
143
144   public void testSOAPFaultResponse() throws Exception JavaDoc {
145     XmlBuffer aBuffer = createXmlBufferForResponse();
146     aBuffer.startElement(SOAP_NAMESPACE_URI, "Body").
147               startElement(SOAP_NAMESPACE_URI, "Fault").
148                 startElement("faultcode").addContent("... some code ...").endElement("faultcode").
149                 startElement("faultactor").addContent("... some actor ...").endElement("faultactor").
150                 startElement("faultstring").addContent("... some message ...").endElement("faultstring").
151                 startElement("detail").addContent("... some details ...").endElement("detail").
152               endElement(SOAP_NAMESPACE_URI, "Fault").
153             endElement(SOAP_NAMESPACE_URI, "Body").
154           endElement(SOAP_NAMESPACE_URI, "Envelope");
155
156     String JavaDoc aBody =
157         "<SOAP-ENV:Fault>" +
158           "<faultcode>... some code ...</faultcode>" +
159           "<faultactor>... some actor ...</faultactor>" +
160           "<faultstring>... some message ...</faultstring>" +
161           "<detail>... some details ...</detail>" +
162         "</SOAP-ENV:Fault>";
163     assertResponseXmlBuffer(aBuffer, aBody);
164   }
165
166
167   private XmlBuffer createXmlBufferForRequest() {
168     XmlBuffer aBuffer = new XmlBuffer(true).
169             addNamespace(SOAP_NAMESPACE_URI, SOAP_NAMESPACE_PREFIX).
170             addNamespace(DYNAMO_NAMESPACE_URI, DYNAMO_NAMESPACE_PREFIX);
171
172     aBuffer.startElement(SOAP_NAMESPACE_URI, "Envelope").
173               addAttribute(SOAP_NAMESPACE_URI, "encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/").
174               startElement(SOAP_NAMESPACE_URI, "Header").
175                 startElement(DYNAMO_NAMESPACE_URI, "Process").
176                   startElement(DYNAMO_NAMESPACE_URI, "dynPid").addContent("2045").endElement(DYNAMO_NAMESPACE_URI, "dynPid").
177                   startElement(DYNAMO_NAMESPACE_URI, "requestId").addContent("134").endElement(DYNAMO_NAMESPACE_URI, "requestId").
178                 endElement(DYNAMO_NAMESPACE_URI, "Process").
179               endElement(SOAP_NAMESPACE_URI, "Header");
180     return aBuffer;
181   }
182
183   private void assertRequestXmlBuffer(XmlBuffer aBuffer, String JavaDoc aBody) {
184     String JavaDoc anExpectedValue =
185         "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
186         "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"" +
187         " SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
188           "<SOAP-ENV:Header>" +
189             "<DYN-IOP:Process xmlns:DYN-IOP=\"http://schemas.sapia.org/dynamo/interoperability/\">" +
190               "<DYN-IOP:dynPid>2045</DYN-IOP:dynPid>" +
191               "<DYN-IOP:requestId>134</DYN-IOP:requestId>" +
192             "</DYN-IOP:Process>" +
193           "</SOAP-ENV:Header>" +
194           "<SOAP-ENV:Body>" + aBody + "</SOAP-ENV:Body>" +
195         "</SOAP-ENV:Envelope>";
196
197     assertEquals("The request xml buffer is not valid", anExpectedValue, aBuffer.toString());
198   }
199
200   private XmlBuffer createXmlBufferForResponse() {
201     XmlBuffer aBuffer = new XmlBuffer(true).
202             addNamespace(SOAP_NAMESPACE_URI, SOAP_NAMESPACE_PREFIX).
203             addNamespace(DYNAMO_NAMESPACE_URI, DYNAMO_NAMESPACE_PREFIX);
204
205     aBuffer.startElement(SOAP_NAMESPACE_URI, "Envelope").
206               addAttribute(SOAP_NAMESPACE_URI, "encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/").
207               startElement(SOAP_NAMESPACE_URI, "Header").
208                 startElement(DYNAMO_NAMESPACE_URI, "Server").
209                   startElement(DYNAMO_NAMESPACE_URI, "requestId").addContent("134").endElement(DYNAMO_NAMESPACE_URI, "requestId").
210                   startElement(DYNAMO_NAMESPACE_URI, "processingTime").addContent("250").endElement(DYNAMO_NAMESPACE_URI, "processingTime").
211                 endElement(DYNAMO_NAMESPACE_URI, "Server").
212               endElement(SOAP_NAMESPACE_URI, "Header");
213     return aBuffer;
214   }
215
216   private void assertResponseXmlBuffer(XmlBuffer aBuffer, String JavaDoc aBody) {
217     String JavaDoc anExpectedValue =
218         "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
219         "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"" +
220         " SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
221           "<SOAP-ENV:Header>" +
222             "<DYN-IOP:Server xmlns:DYN-IOP=\"http://schemas.sapia.org/dynamo/interoperability/\">" +
223               "<DYN-IOP:requestId>134</DYN-IOP:requestId>" +
224               "<DYN-IOP:processingTime>250</DYN-IOP:processingTime>" +
225             "</DYN-IOP:Server>" +
226           "</SOAP-ENV:Header>" +
227           "<SOAP-ENV:Body>" + aBody + "</SOAP-ENV:Body>" +
228         "</SOAP-ENV:Envelope>";
229
230     assertEquals("The response xml buffer is not valid", anExpectedValue, aBuffer.toString());
231   }
232
233 }
234
235
Popular Tags