KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > saaj > SOAPBodyTest


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis2.saaj;
17
18 import junit.framework.TestCase;
19
20 import javax.xml.soap.*;
21 import java.util.Iterator JavaDoc;
22
23 /**
24  * @author Ashutosh Shahi ashutosh.shahi@gmail.com
25  *
26  */

27 public class SOAPBodyTest extends TestCase {
28
29     /**
30      * Method suite
31      *
32      * @return
33      */

34   /* public static Test suite() {
35         return new TestSuite(test.message.TestSOAPBody.class);
36     }
37   */

38     /**
39      * Method main
40      *
41      * @param argv
42      */

43     public static void main(String JavaDoc[] argv) throws Exception JavaDoc {
44         SOAPBodyTest tester = new SOAPBodyTest("TestSOAPBody");
45         tester.testSoapBodyBUG();
46     }
47
48     /**
49      * Constructor TestSOAPBody
50      *
51      * @param name
52      */

53     public SOAPBodyTest(String JavaDoc name) {
54         super(name);
55     }
56     
57     /**
58      * Method testSoapBodyBUG
59      *
60      * @throws Exception
61      */

62     public void testSoapBodyBUG() throws Exception JavaDoc {
63         
64         MessageFactory fact = MessageFactory.newInstance();
65         SOAPMessage message = fact.createMessage();
66         SOAPPart soapPart = message.getSOAPPart();
67         SOAPEnvelopeImpl env = (SOAPEnvelopeImpl)soapPart.getEnvelope();
68         SOAPHeader header = env.getHeader();
69         Name hns = env.createName("Hello","shw", "http://www.jcommerce.net/soap/ns/SOAPHelloWorld");
70         SOAPElement headElmnt = header.addHeaderElement(hns);
71         Name hns1 = env.createName("Myname","shw", "http://www.jcommerce.net/soap/ns/SOAPHelloWorld");
72         SOAPElement myName = headElmnt.addChildElement(hns1);
73         myName.addTextNode("Tony");
74         Name ns = env.createName("Address", "shw", "http://www.jcommerce.net/soap/ns/SOAPHelloWorld");
75         SOAPBody body = env.getBody();
76         SOAPElement bodyElmnt = body.addBodyElement(ns);
77         Name ns1 = env.createName("City", "shw", "http://www.jcommerce.net/soap/ns/SOAPHelloWorld");
78         SOAPElement city = bodyElmnt.addChildElement(ns1);
79         city.addTextNode("GENT");
80         
81         Iterator JavaDoc it = body.getChildElements();
82         int count = 0;
83         
84         while (it.hasNext()) {
85             SOAPElement el = (SOAPElement) it.next();
86             count++;
87             Name name = el.getElementName();
88             System.out.println("Element:" + el);
89             System.out.println("BODY ELEMENT NAME:" + name.getPrefix() + ":"
90                     + name.getLocalName() + " " + name.getURI());
91         }
92         assertTrue(count == 1);
93     }
94
95 }
96
Popular Tags