001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: /*
038: * The contents of this file are subject to the terms
039: * of the Common Development and Distribution License
040: * (the "License"). You may not use this file except
041: * in compliance with the License.
042: *
043: * You can obtain a copy of the license at
044: * https://jwsdp.dev.java.net/CDDLv1.0.html
045: * See the License for the specific language governing
046: * permissions and limitations under the License.
047: *
048: * When distributing Covered Code, include this CDDL
049: * HEADER in each file and include the License file at
050: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
051: * add the following below this CDDL HEADER, with the
052: * fields enclosed by brackets "[]" replaced with your
053: * own identifying information: Portions Copyright [yyyy]
054: * [name of copyright owner]
055: */
056: package soap12;
057:
058: import javax.xml.soap.*;
059: import javax.xml.namespace.QName;
060: import javax.xml.transform.stream.*;
061:
062: import java.io.*;
063:
064: import junit.framework.TestCase;
065:
066: public class SOAPElementTests extends TestCase {
067:
068: public SOAPElementTests(String name) throws Exception {
069: super (name);
070: }
071:
072: public void testSetEncodingStyle1() throws Exception {
073: MessageFactory mFactory = MessageFactory
074: .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
075: SOAPMessage msg = mFactory.createMessage();
076: SOAPBody body = msg.getSOAPBody();
077: SOAPBodyElement bodyElement = body.addBodyElement(new QName(
078: "some-uri", "content", "p"));
079: bodyElement.setEncodingStyle("http://example.com/encoding");
080: assertEquals(bodyElement
081: .getAttributeValue(new QName(
082: SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE,
083: "encodingStyle")),
084: "http://example.com/encoding");
085: }
086:
087: /**
088: * Testcase for CR ID 6213337
089: */
090: public void testSetEncodingStyle2() throws Exception {
091: MessageFactory mFactory = MessageFactory
092: .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
093: SOAPFactory sFactory = SOAPFactory
094: .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
095: SOAPMessage msg = mFactory.createMessage();
096: SOAPBody body = msg.getSOAPBody();
097: SOAPElement bodyElement = sFactory.createElement("content",
098: "p", "some-uri");
099: bodyElement.setEncodingStyle("http://example.com/encoding");
100: SOAPBodyElement addedElement = (SOAPBodyElement) body
101: .addChildElement(bodyElement);
102: assertEquals(addedElement
103: .getAttributeValue(new QName(
104: SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE,
105: "encodingStyle")),
106: "http://example.com/encoding");
107: }
108:
109: /**
110: * Testcase for CR ID 6213350
111: */
112: public void testGetEncodingStyle() throws Exception {
113: String xml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\"><SOAP-ENV:Header/><SOAP-ENV:Body><p:content SOAP-ENV:encodingStyle=\"http://example.com/encoding\" xmlns:p=\"some-uri\"/></SOAP-ENV:Body></SOAP-ENV:Envelope>";
114: MessageFactory mFactory = MessageFactory
115: .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
116: SOAPMessage msg = mFactory.createMessage();
117: SOAPPart soapPart = msg.getSOAPPart();
118: soapPart.setContent(new StreamSource(new ByteArrayInputStream(
119: xml.getBytes("utf-8"))));
120: SOAPBodyElement element = (SOAPBodyElement) msg.getSOAPBody()
121: .getChildElements().next();
122: assertNotNull(element.getEncodingStyle());
123: }
124: }
|