001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.saaj;
020:
021: import junit.framework.TestCase;
022:
023: import javax.xml.soap.MessageFactory;
024: import javax.xml.soap.SOAPBody;
025: import javax.xml.soap.SOAPElement;
026: import javax.xml.soap.SOAPEnvelope;
027: import javax.xml.soap.SOAPHeader;
028: import javax.xml.soap.SOAPHeaderElement;
029: import javax.xml.soap.SOAPMessage;
030: import javax.xml.soap.SOAPPart;
031: import java.util.Iterator;
032:
033: /**
034: *
035: */
036: public class NodeTest extends TestCase {
037: private SOAPMessage msg = null;
038: private SOAPPart sp = null;
039: private SOAPBody body = null;
040: private SOAPEnvelope envelope = null;
041: private SOAPHeader header = null;
042: private SOAPHeaderElement headerEle = null;
043:
044: protected void setUp() throws Exception {
045: msg = MessageFactory.newInstance().createMessage();
046: sp = msg.getSOAPPart();
047: envelope = sp.getEnvelope();
048: body = envelope.getBody();
049: header = envelope.getHeader();
050: headerEle = header.addHeaderElement(envelope.createName("foo",
051: "f", "foo-URI"));
052: headerEle.setActor("actor-URI");
053: }
054:
055: public void testDetachNode() {
056: try {
057: headerEle.detachNode();
058: Iterator iterator = header
059: .examineHeaderElements("actor-URI");
060: assertFalse(
061: "SOAPHeader element is not detached - unexpected",
062: iterator.hasNext());
063: } catch (Exception e) {
064: fail("Exception: " + e);
065: }
066: }
067:
068: public void testParentElement() {
069: try {
070: headerEle.detachNode();
071: SOAPElement parentElement = headerEle.getParentElement();
072: assertNull("Parent is not null : " + parentElement,
073: parentElement);
074: } catch (Exception e) {
075: fail("Exception: " + e);
076: }
077: }
078:
079: public void testSetParentElement1() {
080: try {
081: headerEle.detachNode();
082: headerEle.setParentElement(header);
083: SOAPElement se = headerEle.getParentElement();
084: assertTrue("SOAPHeader element not returned - unexpected",
085: se instanceof SOAPHeader);
086: SOAPHeader sh = (SOAPHeader) se;
087: assertTrue("SOAPHeader element does not match", sh
088: .equals(header));
089: } catch (Exception e) {
090: fail("Exception: " + e);
091: }
092: }
093:
094: public void testSetParentElement2() {
095: try {
096: try {
097: headerEle.setParentElement(body);
098: fail("Expected IllegalArgumentException did not occur");
099: } catch (IllegalArgumentException e) {
100: assertTrue(
101: "Expected IllegalArgumentException occurred",
102: true);
103: }
104: } catch (Exception e) {
105: fail("Exception: " + e);
106: }
107: }
108:
109: public void testSetValue() {
110: try {
111: headerEle.addTextNode("foo-bar");
112: String value = headerEle.getValue();
113: assertNotNull(value);
114: assertEquals("foo-bar", value);
115:
116: headerEle.setValue("foo-bar2");
117: value = headerEle.getValue();
118: assertNotNull(value);
119: assertEquals("foo-bar2", value);
120: } catch (Exception e) {
121: e.printStackTrace();
122: fail("Exception: " + e);
123: }
124: }
125: }
|