| 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; |
| 25 |
import javax.xml.soap.SOAPBody; |
| 26 |
import javax.xml.soap.SOAPEnvelope; |
| 27 |
import javax.xml.soap.SOAPException; |
| 28 |
import javax.xml.soap.SOAPHeader; |
| 29 |
|
| 30 |
/** |
| 31 |
* Test SOAPEnvelope class. |
| 32 |
* |
| 33 |
* @author Glyn Normington ([email protected]) |
| 34 |
*/ |
| 35 |
public class TestSOAPEnvelope extends TestCase { |
| 36 |
|
| 37 |
public TestSOAPEnvelope(String name) { |
| 38 |
super(name); |
| 39 |
} |
| 40 |
|
| 41 |
// Test JAXM methods... |
| 42 |
|
| 43 |
public void testName() throws Exception { |
| 44 |
SOAPEnvelope env = new org.apache.axis.message.SOAPEnvelope(); |
| 45 |
Name 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 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 { |
| 60 |
SOAPEnvelope env = new org.apache.axis.message.SOAPEnvelope(); |
| 61 |
SOAPHeader h1 = env.getHeader(); |
| 62 |
assertTrue("null initial header", h1 != null); |
| 63 |
h1.detachNode(); |
| 64 |
assertTrue("header not freed", env.getHeader() == null); |
| 65 |
SOAPHeader 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 e) { |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
public void testBody() throws Exception { |
| 77 |
SOAPEnvelope env = new org.apache.axis.message.SOAPEnvelope(); |
| 78 |
SOAPBody b1 = env.getBody(); |
| 79 |
assertTrue("null initial body", b1 != null); |
| 80 |
b1.detachNode(); |
| 81 |
assertTrue("body not freed", env.getBody() == null); |
| 82 |
SOAPBody 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 e) { |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
// Test for bug #14570 |
| 94 |
public void testNullpointer() throws Exception{ |
| 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{ |
| 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 args[]) throws Exception { |
| 115 |
TestSOAPEnvelope tester = new TestSOAPEnvelope("TestSOAPEnvelope"); |
| 116 |
tester.testNullpointer(); |
| 117 |
tester.testNullpointerInHeader(); |
| 118 |
} |
| 119 |
} |