KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > message > TestSOAPEnvelope


1 /*
2  * Copyright 2002-2004 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
17 package test.message;
18
19 import junit.framework.TestCase;
20 import org.apache.axis.Message;
21 import org.apache.axis.message.SOAPBodyElement;
22 import org.apache.axis.message.SOAPHeaderElement;
23
24 import javax.xml.soap.Name JavaDoc;
25 import javax.xml.soap.SOAPBody JavaDoc;
26 import javax.xml.soap.SOAPEnvelope JavaDoc;
27 import javax.xml.soap.SOAPException JavaDoc;
28 import javax.xml.soap.SOAPHeader JavaDoc;
29
30 /**
31  * Test SOAPEnvelope class.
32  *
33  * @author Glyn Normington (glyn@apache.org)
34  */

35 public class TestSOAPEnvelope extends TestCase {
36
37     public TestSOAPEnvelope(String JavaDoc name) {
38         super(name);
39     }
40
41     // Test JAXM methods...
42

43     public void testName() throws Exception JavaDoc {
44         SOAPEnvelope JavaDoc env = new org.apache.axis.message.SOAPEnvelope();
45         Name JavaDoc n = env.createName("local", "pref", "urn:blah");
46         assertEquals("local part of name did not match", "local",
47                      n.getLocalName());
48         assertEquals("qname of name did not match", "pref:local",
49                      n.getQualifiedName());
50         assertEquals("prefix of name did not match", "pref",
51                      n.getPrefix());
52         assertEquals("uri of name did not match", "urn:blah",
53                      n.getURI());
54         Name JavaDoc n2 = env.createName("loc");
55         assertEquals("local part of name2 did not match", "loc",
56                      n2.getLocalName());
57     }
58
59     public void testHeader() throws Exception JavaDoc {
60         SOAPEnvelope JavaDoc env = new org.apache.axis.message.SOAPEnvelope();
61         SOAPHeader JavaDoc h1 = env.getHeader();
62         assertTrue("null initial header", h1 != null);
63         h1.detachNode();
64         assertTrue("header not freed", env.getHeader() == null);
65         SOAPHeader JavaDoc h2 = env.addHeader();
66         assertTrue("null created header", h2 != null);
67         assertEquals("wrong header retrieved", h2, env.getHeader());
68         assertEquals("header parent incorrect", env, h2.getParentElement());
69         try {
70             env.addHeader();
71             assertTrue("second header added", false);
72         } catch (SOAPException JavaDoc e) {
73         }
74     }
75
76     public void testBody() throws Exception JavaDoc {
77         SOAPEnvelope JavaDoc env = new org.apache.axis.message.SOAPEnvelope();
78         SOAPBody JavaDoc b1 = env.getBody();
79         assertTrue("null initial body", b1 != null);
80         b1.detachNode();
81         assertTrue("body not freed", env.getBody() == null);
82         SOAPBody JavaDoc b2 = env.addBody();
83         assertTrue("null created body", b2 != null);
84         assertEquals("wrong body retrieved", b2, env.getBody());
85         assertEquals("body parent incorrect", env, b2.getParentElement());
86         try {
87             env.addBody();
88             assertTrue("second body added", false);
89         } catch (SOAPException JavaDoc e) {
90         }
91     }
92     
93     // Test for bug #14570
94
public void testNullpointer() throws Exception JavaDoc{
95         org.apache.axis.message.SOAPEnvelope env=new org.apache.axis.message.SOAPEnvelope();
96         SOAPBodyElement bdy=new SOAPBodyElement();
97         bdy.setName("testResponse");
98         env.addBodyElement(bdy);
99         Message msg=new Message(env);
100         SOAPBodyElement sbe = msg.getSOAPEnvelope().getBodyByName(null,"testResponse");
101         assertTrue(sbe != null);
102     }
103
104     // Test for bug 14574
105
public void testNullpointerInHeader() throws Exception JavaDoc{
106         org.apache.axis.message.SOAPEnvelope env=new org.apache.axis.message.SOAPEnvelope();
107         SOAPHeaderElement hdr=new SOAPHeaderElement("", "testHeader");
108         env.addHeader(hdr);
109         Message msg=new Message(env);
110         SOAPHeaderElement she = msg.getSOAPEnvelope().getHeaderByName(null,"testHeader");
111         assertTrue(she != null);
112     }
113     
114     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
115         TestSOAPEnvelope tester = new TestSOAPEnvelope("TestSOAPEnvelope");
116         tester.testNullpointer();
117         tester.testNullpointerInHeader();
118     }
119 }
120
Popular Tags