KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > om > impl > serializer > NoNamespaceSerializerTest


1 package org.apache.axis2.om.impl.serializer;
2
3 import junit.framework.TestCase;
4 import org.apache.axis2.om.OMAbstractFactory;
5 import org.apache.axis2.om.OMElement;
6 import org.apache.axis2.om.OMOutput;
7 import org.apache.axis2.om.OMXMLParserWrapper;
8 import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;
9 import org.apache.axis2.soap.SOAPEnvelope;
10 import org.apache.axis2.soap.SOAPFactory;
11
12 import javax.xml.stream.XMLInputFactory;
13 import javax.xml.stream.XMLOutputFactory;
14 import javax.xml.stream.XMLStreamReader;
15 import java.io.ByteArrayInputStream JavaDoc;
16 import java.io.InputStreamReader JavaDoc;
17
18 /*
19 * Copyright 2004,2005 The Apache Software Foundation.
20 *
21 * Licensed under the Apache License, Version 2.0 (the "License");
22 * you may not use this file except in compliance with the License.
23 * You may obtain a copy of the License at
24 *
25 * http://www.apache.org/licenses/LICENSE-2.0
26 *
27 * Unless required by applicable law or agreed to in writing, software
28 * distributed under the License is distributed on an "AS IS" BASIS,
29 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 * See the License for the specific language governing permissions and
31 * limitations under the License.
32 *
33 *
34 */

35
36 public class NoNamespaceSerializerTest extends TestCase {
37
38     private String JavaDoc xmlTextOne = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
39             "<soapenv:Body>\n" +
40             " <ns1:getBalance xmlns:ns1=\"http://localhost:8081/axis/services/BankPort/\">\n" +
41             " <accountNo HREF=\"#id0\"/>\n" +
42             " </ns1:getBalance>\n" +
43             " </soapenv:Body></soapenv:Envelope>";
44                                                                      
45     private String JavaDoc xmlText2 = "<purchase-order xmlns=\"http://openuri.org/easypo\">\n" +
46             " <customer>\n" +
47             " <name>Gladys Kravitz</name>\n" +
48             " <address>Anytown, PA</address>\n" +
49             " </customer>\n" +
50             " <date>2005-03-06T14:06:12.697+06:00</date>\n" +
51             "</purchase-order>";
52
53     private String JavaDoc xmlTextTwo = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
54             "<soapenv:Body>\n" +
55             " <getBalance xmlns=\"http://localhost:8081/axis/services/BankPort/\">\n" +
56             " <accountNo HREF=\"#id0\"/>\n" +
57             " </getBalance>\n" +
58             " </soapenv:Body></soapenv:Envelope>";
59
60     private XMLStreamReader readerOne;
61     private XMLStreamReader readerTwo;
62     private OMOutput omOutput;
63
64    // private OMXMLParserWrapper builder;
65
// private File tempFile;
66

67     private OMXMLParserWrapper builderOne;
68     private OMXMLParserWrapper builderTwo;
69     // private File tempFile;
70

71
72
73     protected void setUp() throws Exception JavaDoc {
74         readerOne = XMLInputFactory.newInstance().
75                 createXMLStreamReader(new InputStreamReader JavaDoc(new ByteArrayInputStream JavaDoc(xmlTextOne.getBytes())));
76         readerTwo = XMLInputFactory.newInstance().
77                 createXMLStreamReader(new InputStreamReader JavaDoc(new ByteArrayInputStream JavaDoc(xmlTextTwo.getBytes())));
78         omOutput = new OMOutput(XMLOutputFactory.newInstance().
79                 createXMLStreamWriter(System.out));
80         builderOne = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getSOAP11Factory(), readerOne);
81         builderTwo = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getSOAP11Factory(), readerTwo);
82     }
83
84
85 // public void testSerilizationWithCacheOff() throws Exception {
86
// SOAPEnvelope env = (SOAPEnvelope) builderOne.getDocumentElement();
87
// env.serializeWithCache(writer, false);
88
// writer.flush();
89
//
90
//
91
// }
92
//
93
// public void testSerilizationWithCacheOn() throws Exception {
94
// SOAPEnvelope env = (SOAPEnvelope) builderOne.getDocumentElement();
95
// env.serializeWithCache(writer, true);
96
// writer.flush();
97
// }
98

99
100     public void testSerilizationWithDefaultNamespaces() throws Exception JavaDoc {
101         SOAPEnvelope env = (SOAPEnvelope) builderTwo.getDocumentElement();
102         env.serializeWithCache(omOutput);
103         OMElement balanceElement = env.getBody().getFirstElement();
104         assertEquals("Deafualt namespace has not been set properly", balanceElement.getNamespace().getName(), "http://localhost:8081/axis/services/BankPort/");
105
106         OMElement accountNo = balanceElement.getFirstElement();
107         assertEquals("Deafualt namespace of children has not been set properly", accountNo.getNamespace().getName(), "http://localhost:8081/axis/services/BankPort/");
108
109     }
110
111     public void submitPurchaseOrderTest()
112             throws Exception JavaDoc {
113         SOAPFactory omFactory = OMAbstractFactory.getSOAP11Factory();
114         SOAPEnvelope env = omFactory.getDefaultEnvelope();
115         OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(omFactory,XMLInputFactory.newInstance().
116                 createXMLStreamReader(new InputStreamReader JavaDoc(new ByteArrayInputStream JavaDoc(xmlText2.getBytes()))));
117         env.getBody().addChild(builder.getDocumentElement());
118
119         OMOutput omOutput = new OMOutput(System.out,false);
120         //env.getBody().addChild(builder.getDocumentElement());
121

122         env.serializeWithCache(omOutput);
123        // env.serializeWithCache(xmlStreamWriter, true);
124

125         omOutput.flush();
126
127     }
128     public void testSerilizationWithCacheOn() throws Exception JavaDoc{
129        SOAPEnvelope env = (SOAPEnvelope) builderOne.getDocumentElement();
130        env.serializeWithCache(omOutput);
131        omOutput.flush();
132     }
133
134      public void testSerilizationWithCacheOff() throws Exception JavaDoc{
135        SOAPEnvelope env = (SOAPEnvelope) builderOne.getDocumentElement();
136        env.serializeWithCache(omOutput);
137        omOutput.flush();
138     }
139     }
140
Popular Tags