0001: /*
0002: * The contents of this file are subject to the terms
0003: * of the Common Development and Distribution License
0004: * (the "License"). You may not use this file except
0005: * in compliance with the License.
0006: *
0007: * You can obtain a copy of the license at
0008: * https://jwsdp.dev.java.net/CDDLv1.0.html
0009: * See the License for the specific language governing
0010: * permissions and limitations under the License.
0011: *
0012: * When distributing Covered Code, include this CDDL
0013: * HEADER in each file and include the License file at
0014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
0015: * add the following below this CDDL HEADER, with the
0016: * fields enclosed by brackets "[]" replaced with your
0017: * own identifying information: Portions Copyright [yyyy]
0018: * [name of copyright owner]
0019: */
0020: /*
0021: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0022: *
0023: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0024: *
0025: * The contents of this file are subject to the terms of either the GNU
0026: * General Public License Version 2 only ("GPL") or the Common Development
0027: * and Distribution License("CDDL") (collectively, the "License"). You
0028: * may not use this file except in compliance with the License. You can obtain
0029: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
0030: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
0031: * language governing permissions and limitations under the License.
0032: *
0033: * When distributing the software, include this License Header Notice in each
0034: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
0035: * Sun designates this particular file as subject to the "Classpath" exception
0036: * as provided by Sun in the GPL Version 2 section of the License file that
0037: * accompanied this code. If applicable, add the following below the License
0038: * Header, with the fields enclosed by brackets [] replaced by your own
0039: * identifying information: "Portions Copyrighted [year]
0040: * [name of copyright owner]"
0041: *
0042: * Contributor(s):
0043: *
0044: * If you wish your version of this file to be governed by only the CDDL or
0045: * only the GPL Version 2, indicate your decision by adding "[Contributor]
0046: * elects to include this software in this distribution under the [CDDL or GPL
0047: * Version 2] license." If you don't indicate a single choice of license, a
0048: * recipient has the option to distribute your version of this file under
0049: * either the CDDL, the GPL Version 2 or to extend the choice of license to
0050: * its licensees as provided above. However, if you add GPL Version 2 code
0051: * and therefore, elected the GPL Version 2 license, then the option applies
0052: * only if the new code is made subject to such option by the copyright
0053: * holder.
0054: */
0055:
0056: /*
0057: * $Id: BugfixesTest.java,v 1.4 2007/07/16 16:41:26 ofung Exp $
0058: * $Revision: 1.4 $
0059: * $Date: 2007/07/16 16:41:26 $
0060: */
0061:
0062: package bugfixes;
0063:
0064: import java.io.*;
0065: import java.net.URL;
0066: import java.net.URLStreamHandler;
0067: import javax.activation.URLDataSource;
0068: import java.util.Iterator;
0069: import java.util.Properties;
0070: import java.util.Locale;
0071:
0072: import javax.xml.namespace.QName;
0073: import javax.xml.parsers.DocumentBuilder;
0074: import javax.xml.parsers.DocumentBuilderFactory;
0075: import javax.xml.soap.*;
0076: import javax.xml.transform.*;
0077: import javax.xml.transform.dom.DOMResult;
0078: import javax.xml.transform.stream.StreamSource;
0079:
0080: import junit.framework.TestCase;
0081: import junit.framework.TestSuite;
0082:
0083: import javax.xml.transform.stream.StreamSource;
0084: import org.w3c.dom.Document;
0085: import org.w3c.dom.Element;
0086:
0087: import util.TestHelper;
0088:
0089: import com.sun.xml.messaging.saaj.soap.SOAPVersionMismatchException;
0090: import com.sun.xml.messaging.saaj.util.ByteInputStream;
0091:
0092: /*
0093: * A class that contains test cases that verify some of the bug fixes made.
0094: * This is just a convinience class that makes sure the fix is in place,
0095: * and is intended to be a part of our local test package and is not meant
0096: * to be shipped ofcourse.
0097: *
0098: * @author Manveen Kaur (manveen.kaur@sun.com)
0099: */
0100: public class BugfixesTest extends TestCase {
0101: private static TestHelper th = TestHelper.getInstance();
0102:
0103: public BugfixesTest(String name) {
0104: super (name);
0105: }
0106:
0107: private SOAPMessage createMessageOne() throws SOAPException {
0108: MessageFactory msgFactory = MessageFactory.newInstance();
0109:
0110: SOAPMessage msg = msgFactory.createMessage();
0111:
0112: SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
0113:
0114: SOAPHeader hdr = envelope.getHeader();
0115: SOAPBody bdy = envelope.getBody();
0116:
0117: // create a fault element with a prefix other than soap-env
0118: SOAPBodyElement ltp = bdy.addBodyElement(envelope.createName(
0119: "Fault", "soap",
0120: "http://schemas.xmlsoap.org/soap/envelope/"));
0121:
0122: ltp.addChildElement(envelope.createName("faultcode"))
0123: .addTextNode("100");
0124:
0125: return msg;
0126: }
0127:
0128: private SOAPMessage createMessageTwo() throws SOAPException {
0129: MessageFactory msgFactory = MessageFactory.newInstance();
0130:
0131: SOAPMessage msg = msgFactory.createMessage();
0132:
0133: SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
0134:
0135: SOAPHeader hdr = envelope.getHeader();
0136: SOAPBody bdy = envelope.getBody();
0137:
0138: SOAPFault fault = bdy.addFault();
0139: String prefix = envelope.getElementName().getPrefix();
0140: fault.setFaultCode(prefix + ":100");
0141: fault.setFaultString("some reason for fault");
0142: Detail detail = fault.addDetail();
0143: detail.addTextNode("this is what she was talking abt?");
0144: DetailEntry de = detail.addDetailEntry(envelope.createName(
0145: "DetailEntry", "e", "some-otherw-uri"));
0146: de.addTextNode("somedetailheretext");
0147:
0148: return msg;
0149: }
0150:
0151: /*
0152: * Test to verify that ClassCastException is not thrown on
0153: * SOAPBody.getFault() when the prefix is different from soap-env.
0154: */
0155: public void testFault() throws SOAPException {
0156:
0157: String exception = null;
0158:
0159: // try {
0160:
0161: SOAPMessage msgOne = createMessageOne();
0162:
0163: SOAPEnvelope envelope = msgOne.getSOAPPart().getEnvelope();
0164: SOAPBody bdy = envelope.getBody();
0165:
0166: SOAPFault fault = bdy.getFault();
0167:
0168: // } catch (Exception e) {
0169: // exception = e.getMessage();
0170: // }
0171:
0172: // no exception should be thrown
0173: assertTrue("Exception should not have been thrown: "
0174: + exception, (exception == null));
0175: }
0176:
0177: /**
0178: * Test to verify XML files can be attached to a SOAP Message.
0179: * There is a testcase in JAXM SQE to reproduce the test case.
0180: * It is under saaj13/soap/attachments.
0181: **/
0182: public void testAddAnXmlAttachment() throws Exception {
0183:
0184: SOAPMessage msg = createMessageOne();
0185:
0186: // These are failing in SQE tests (Bug ID- 6287927) -
0187: // (1) ap = msg.createAttachmentPart((Object)new URLDataSource(new URL
0188: // (hostname+data2)),"text/xml");
0189:
0190: // (2) ap = msg.createAttachmentPart((Object)new StreamSource(new File
0191: //(req.getParameter("basedir")+data2)),"text/xml");
0192:
0193: // (1)
0194:
0195: /* URLDataSource urlDataS = new URLDataSource(
0196: new java.net.URL("file:/c:/ws/saaj-ri/build.xml"));
0197:
0198: AttachmentPart ap1 = msg.createAttachmentPart(urlDataS ,"text/xml");
0199: msg.addAttachmentPart(ap1);
0200: */
0201: java.io.File file = new File(
0202: "src/test/bugfixes/data/setContent.xml");
0203: javax.activation.FileDataSource fd = new javax.activation.FileDataSource(
0204: file);
0205: // StreamSource stream = new StreamSource(fd.getInputStream());
0206: AttachmentPart ap2 = msg.createAttachmentPart(fd, "text/xml");
0207: msg.addAttachmentPart(ap2);
0208:
0209: AttachmentPart ap3 = msg.createAttachmentPart(new StreamSource(
0210: file), "text/xml");
0211: msg.addAttachmentPart(ap3);
0212:
0213: msg.writeTo(System.out);
0214: }
0215:
0216: /*
0217: * Detail.getDetailEntries() iterator returned should only contain
0218: * DetailEntry objects (and not Text objects).
0219: */
0220: public void testDetailEntry() throws Exception {
0221: SOAPMessage msg = createMessageTwo();
0222:
0223: SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
0224: SOAPBody bdy = envelope.getBody();
0225:
0226: SOAPFault fault = bdy.getFault();
0227: Detail detail = fault.getDetail();
0228:
0229: Iterator iter = detail.getDetailEntries();
0230: while (iter.hasNext()) {
0231: Object object = iter.next();
0232: assertTrue("WRONG TYPE:" + object.getClass().toString(),
0233: object instanceof DetailEntry);
0234: }
0235: }
0236:
0237: /*
0238: * Test to verify that the setContent bug has been fixed.
0239: * Input is from a StreamSource.
0240: */
0241: public void testSetContentStrSrc() throws Exception {
0242: MessageFactory mfactory = MessageFactory.newInstance();
0243: SOAPMessage msg = mfactory.createMessage();
0244:
0245: SOAPPart part = msg.getSOAPPart();
0246: StreamSource streamSource = new StreamSource(
0247: new FileInputStream(
0248: "src/test/bugfixes/data/setContent.xml"));
0249:
0250: // white spaces should be retained
0251: part.setContent(streamSource);
0252: SOAPEnvelope envelope = part.getEnvelope();
0253: SOAPHeader header = envelope.getHeader();
0254: Iterator headerChildren = header.getChildElements();
0255: assertTrue("Header has first child", headerChildren.hasNext());
0256: Node firstChild = (Node) headerChildren.next();
0257: assertTrue("First text node contains newLine char", firstChild
0258: .getNodeValue().equals("\n"));
0259: assertTrue("Header has second child", headerChildren.hasNext());
0260: Node secondChild = (Node) headerChildren.next();
0261: assertEquals("Second child has only one child", secondChild
0262: .getFirstChild(), secondChild.getLastChild());
0263: assertTrue("Second child has a text node as a child "
0264: + "with a particular value", secondChild
0265: .getFirstChild().getNodeValue().equals(
0266: "line 1\nline 2\nline 3\n"));
0267: }
0268:
0269: /*
0270: * Test to verify that whitespace between elements should be ignored.
0271: * Input is from a StreamSource.
0272: */
0273: // disabling this for now. This test hangs??
0274: public void xtestIgnoreInterElementWhiteSpace() throws Exception {
0275: MessageFactory mfactory = MessageFactory.newInstance();
0276: SOAPMessage msg = mfactory.createMessage();
0277:
0278: SOAPPart part = msg.getSOAPPart();
0279: StreamSource streamSource = new StreamSource(
0280: new FileInputStream(
0281: "src/test/bugfixes/data/setContent.xml"));
0282:
0283: part.setContent(streamSource);
0284:
0285: // need to set property to ignore inter element whitespace here.
0286:
0287: int count = 0;
0288:
0289: SOAPEnvelope envelope = part.getEnvelope();
0290: Iterator i = envelope.getChildElements();
0291: while (i.hasNext()) {
0292: // System.out.println("######Iterator i="+i.next());
0293: count++;
0294: }
0295:
0296: // TODO: Uncomment this when the property is set, otherwise this
0297: // test will fail
0298: /*
0299: if (count > 2)
0300: fail("Inter-element whitespace should have been ignored");
0301: */
0302: }
0303:
0304: public void testReadMultipleLines() throws Exception {
0305: MessageFactory mfactory = MessageFactory.newInstance();
0306: SOAPMessage msg = mfactory.createMessage();
0307:
0308: SOAPPart part = msg.getSOAPPart();
0309: StreamSource streamSource = new StreamSource(
0310: new FileInputStream(
0311: "src/test/bugfixes/data/certificate.xml"));
0312:
0313: // part.setContent(streamSource);
0314:
0315: TransformerFactory transformerFactory = new com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl();
0316: Transformer transformer = transformerFactory.newTransformer();
0317: DOMResult result = new DOMResult(part);
0318: transformer.transform(streamSource, result);
0319:
0320: SOAPBody body = msg.getSOAPBody();
0321: Iterator eachChild = body.getChildElements();
0322: eachChild.next();
0323: SOAPElement element = (SOAPElement) eachChild.next();
0324: assertEquals("ds:X509Certificate", element.getTagName());
0325: //element.normalize();
0326: // System.out.println(element.getValue());
0327: }
0328:
0329: // public void testReadMultipleLinesControlCase() throws Exception {
0330: // MessageFactory mfactory = MessageFactory.newInstance();
0331: // SOAPMessage msg = mfactory.createMessage();
0332: //
0333: // DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
0334: // factory.setAttribute("http://apache.org/xml/features/dom/defer-node-expansion", Boolean.FALSE);
0335: // DocumentBuilder builder = factory.newDocumentBuilder();
0336: // Document content = builder.parse(new FileInputStream("src/test/bugfixes/data/certificate.xml"));
0337: // SOAPPart part = msg.getSOAPPart();
0338: // DOMSource source = new DOMSource(content.getDocumentElement());
0339: // part.setContent(source);
0340: //
0341: //
0342: // SOAPBody body = msg.getSOAPBody();
0343: // Iterator eachChild = body.getChildElements();
0344: // eachChild.next();
0345: // SOAPElement element = (SOAPElement) eachChild.next();
0346: // assertEquals("ds:X509Certificate", element.getTagName());
0347: // //element.normalize();
0348: // System.out.println(element.getValue());
0349: // }
0350:
0351: /*
0352: * Test to verify that the setContent bug has been fixed.
0353: * Input is from a DOMSource.
0354: */
0355: public void testSetContentDOMSrc() throws Exception {
0356:
0357: DocumentBuilderFactory factory = new com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl();
0358: factory.setNamespaceAware(true);
0359: DocumentBuilder builder = factory.newDocumentBuilder();
0360:
0361: Document domDoc = builder.parse(new File(
0362: "src/test/bugfixes/data/setContent.xml"));
0363: Source domSource = new javax.xml.transform.dom.DOMSource(domDoc);
0364:
0365: MessageFactory mfactory = MessageFactory.newInstance();
0366: SOAPMessage msg = mfactory.createMessage();
0367:
0368: SOAPPart part = msg.getSOAPPart();
0369: part.setContent(domSource);
0370:
0371: try {
0372: msg.writeTo(new FileOutputStream(
0373: "src/test/bugfixes/data/tempFile"));
0374: } catch (Exception e) {
0375: e.printStackTrace();
0376: fail("Exception should not be thrown.");
0377: }
0378:
0379: // white spaces should be retained
0380: SOAPEnvelope envelope = part.getEnvelope();
0381: SOAPHeader header = envelope.getHeader();
0382: Iterator headerChildren = header.getChildElements();
0383: assertTrue("Header has first child", headerChildren.hasNext());
0384: Node firstChild = (Node) headerChildren.next();
0385: assertTrue("First text node contains newLine char", firstChild
0386: .getNodeValue().equals("\n"));
0387: assertTrue("Header has second child", headerChildren.hasNext());
0388: Node secondChild = (Node) headerChildren.next();
0389: assertEquals("Second child has only one child", secondChild
0390: .getFirstChild(), secondChild.getLastChild());
0391: assertTrue("Second child has a text node as a child "
0392: + "with a particular value", secondChild
0393: .getFirstChild().getNodeValue().equals(
0394: "line 1\nline 2\nline 3\n"));
0395: }
0396:
0397: /*
0398: * Test to reproduce the 'inputStream closed' bug. 4642290.
0399: * Still can't seem to reproduce it?
0400: */
0401:
0402: // This test assumes that getContent returns a StreamSource which is not always true
0403: // so don't run it.
0404: public void xtestWriteTo() {
0405:
0406: boolean error = false;
0407:
0408: try {
0409:
0410: MessageFactory mfactory = MessageFactory.newInstance();
0411: SOAPMessage msg = mfactory.createMessage();
0412:
0413: SOAPPart part = msg.getSOAPPart();
0414: StreamSource streamSource = new StreamSource(
0415: new FileInputStream(
0416: "src/test/bugfixes/data/setContent.xml"));
0417:
0418: part.setContent(streamSource);
0419:
0420: // create and add an attachment
0421: AttachmentPart attachment = msg.createAttachmentPart();
0422: String stringContent = "blah";
0423:
0424: attachment.setContent(stringContent, "text/plain");
0425: msg.addAttachmentPart(attachment);
0426:
0427: // adding another attachment
0428: attachment.setContent(streamSource, "text/xml");
0429: msg.addAttachmentPart(attachment);
0430:
0431: System.out.println("First write To.... ");
0432: // msg.writeTo(System.out);
0433:
0434: // do something to the tree
0435: SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
0436: SOAPHeader hdr = envelope.getHeader();
0437: SOAPBody bdy = envelope.getBody();
0438:
0439: // try to get stream source now
0440: StreamSource src = (StreamSource) msg.getSOAPPart()
0441: .getContent();
0442: InputStream inStream = src.getInputStream();
0443:
0444: System.out.println("Trying to read input stream here");
0445: // trying to read this input stream
0446: inStream.read();
0447:
0448: // stream should not be closed on second write to...
0449: System.out.println("Second write To.... ");
0450: // msg.writeTo(System.out);
0451:
0452: } catch (Exception e) {
0453: e.printStackTrace();
0454: error = true;
0455: }
0456:
0457: // check that no exception should be thrown
0458: assertTrue(
0459: "Stream should not be closed;no exception should be thrown",
0460: (!error));
0461:
0462: }
0463:
0464: /*
0465: * Test to reproduce and verify that the URLStreamHandler bug has been fixed.
0466: * Bug id 4747050.
0467: * The value of data Handler should be set to the value set in the
0468: * test. (perhaps use a debugger to verify this?)
0469: */
0470: public void xtestURLStreamHandler() {
0471:
0472: boolean error = false;
0473:
0474: try {
0475: SOAPConnectionFactory factory = SOAPConnectionFactory
0476: .newInstance();
0477: SOAPConnection con = factory.createConnection();
0478:
0479: // create a request message and give it content
0480: MessageFactory mfactory = MessageFactory.newInstance();
0481: SOAPMessage msg = mfactory.createMessage();
0482:
0483: // Create an envelope in the message
0484: SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
0485: SOAPBody body = envelope.getBody();
0486:
0487: body
0488: .addChildElement(
0489: envelope.createName("find_business", "",
0490: "urn:uddi-org:api"))
0491: .addAttribute(envelope.createName("generic"), "1.0")
0492: .addAttribute(envelope.createName("maxRows"), "100")
0493: .addChildElement("name").addTextNode("SUNW");
0494:
0495: //set proxy properties before sending message
0496: Properties props = System.getProperties();
0497: // setting these to sun settings for now
0498: props.put("http.proxyHost", "wcscaa.sfbay.sun.com");
0499: props.put("http.proxyPort", "8080");
0500:
0501: // URL without StreamHandler
0502: /*
0503: URL to_url = new
0504: URL("http://www-3.ibm.com/services/uddi/testregistry/inquiryapi");
0505: */
0506:
0507: // create a URL that takes a URLStramHandler in its c'tor
0508: // this value should be preserved.
0509: URL to_url = new URL("http", "www-3.ibm.com", -1,
0510: "/services/uddi/testregistry/inquiryapi",
0511: (URLStreamHandler) Class.forName(
0512: "sun.net.www.protocol.http.Handler")
0513: .newInstance());
0514:
0515: SOAPMessage reply = con.call(msg, to_url);
0516:
0517: System.out.println("Received reply from: " + to_url);
0518: // reply.writeTo(System.out);
0519: con.close();
0520: } catch (Exception e) {
0521: error = true;
0522: }
0523:
0524: assertTrue("URLStreamhandler test failed ", (!error));
0525: }
0526:
0527: /*
0528: * 4793014 SAAJ needs to reject messages with DTDs
0529: *
0530: * Note: this does not actually test of messages with DTDs but messages
0531: * with <em>entity definitions</em> in the DTD. Although messages with
0532: * DTDs should also be rejected, entity definitions can be used in a
0533: * denial of service attack and is thus important to check for. [eeg
0534: * 17dec02]
0535: */
0536: public void testRejectDtd() throws Exception {
0537: InputStream is = th.getInputStream("rejectDtd.xml");
0538: MimeHeaders mimeHeaders = new MimeHeaders();
0539: mimeHeaders.addHeader("Content-Type", "text/xml");
0540:
0541: MessageFactory msgFactory = MessageFactory.newInstance();
0542: try {
0543: SOAPMessage msg = msgFactory.createMessage(mimeHeaders, is);
0544: th.writeTo(msg);
0545: SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
0546: } catch (SOAPException se) {
0547: // This is the expected outcome since SAAJ should reject this
0548: // document b/c it contains a general entity in its local DTD
0549: // subset
0550: return;
0551: }
0552: fail("SOAPMessage should have been rejected b/c it contains a DTD");
0553: }
0554:
0555: /*
0556: * Parse a simple SOAP message
0557: */
0558: public void testSanity() throws Exception {
0559: InputStream is = th.getInputStream("sanity.xml");
0560: MimeHeaders mimeHeaders = new MimeHeaders();
0561: mimeHeaders.addHeader("Content-Type", "text/xml");
0562:
0563: MessageFactory msgFactory = MessageFactory.newInstance();
0564: try {
0565: SOAPMessage msg = msgFactory.createMessage(mimeHeaders, is);
0566: SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
0567: } catch (SOAPException se) {
0568: fail("SOAPException unexpected" + se);
0569: }
0570: }
0571:
0572: /*
0573: * Test case to reproduce text element getValue bug. This bug is a regression
0574: * found in the tck test suite.
0575: */
0576: public void testTextGetValue() throws Exception {
0577:
0578: MessageFactory msgFactory = MessageFactory.newInstance();
0579: SOAPMessage msg = msgFactory.createMessage();
0580:
0581: SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
0582: SOAPBody body = envelope.getBody();
0583:
0584: Name name = envelope.createName("localname", "prefix", "uri");
0585: SOAPElement element = body.addChildElement(name);
0586: element.addTextNode("abctext");
0587:
0588: String value = element.getValue();
0589:
0590: if (!"abctext".equals(value))
0591: fail("Value should be abctext; got " + value);
0592:
0593: }
0594:
0595: /*
0596: * 4800266 Possible WSI releated saaj bug when creating a SOAPFault
0597: * message. Closed as not reproducible. [eeg 21jan03]
0598: */
0599: public void testFaultUnqualifiedSubElements() throws Exception {
0600: MessageFactory msgFactory = MessageFactory.newInstance();
0601: SOAPMessage msg = msgFactory.createMessage();
0602: SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
0603: SOAPHeader hdr = envelope.getHeader();
0604: SOAPBody body = envelope.getBody();
0605:
0606: SOAPFault sf = body.addFault();
0607: String envPrefix = envelope.getElementName().getPrefix();
0608: sf.setFaultCode(envPrefix + ":Client");
0609: sf.setFaultString("This is the fault string");
0610: sf.setFaultActor("http://example.org/faultactor");
0611: sf.setFaultActor(null);
0612: Detail d = sf.addDetail();
0613: d.addTextNode("This should be a valid SOAP Fault Message");
0614:
0615: Iterator faultChildren = sf.getChildElements();
0616: assertTrue("Fault has the first child", faultChildren.hasNext());
0617: SOAPElement faultCode = (SOAPElement) faultChildren.next();
0618: assertNull("FaultCode does not have an xmlns attribute",
0619: faultCode.getAttributeValue(new QName("xmlns")));
0620: th.writeTo(msg);
0621: }
0622:
0623: public void testGetFaultActor() throws Exception {
0624:
0625: MessageFactory msgFactory = MessageFactory.newInstance();
0626: SOAPMessage msg = msgFactory.createMessage();
0627: SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
0628: SOAPHeader hdr = envelope.getHeader();
0629: SOAPBody body = envelope.getBody();
0630:
0631: SOAPFault sf = body.addFault();
0632: String envPrefix = envelope.getElementName().getPrefix();
0633: sf.setFaultCode(envPrefix + ":Client");
0634: sf.setFaultString("This is the fault string");
0635: sf.setFaultActor("/faultActor");
0636:
0637: sf.setFaultCode(envPrefix + ":Client2");
0638: assertEquals(sf.getFaultCode(), new String(envPrefix
0639: + ":Client2"));
0640:
0641: sf.setFaultActor("/faultActor2");
0642: assertEquals(sf.getFaultActor(), new String("/faultActor2"));
0643: }
0644:
0645: public void testGetFaultCodeAsName() throws Exception {
0646:
0647: MessageFactory msgFactory = MessageFactory.newInstance();
0648: SOAPMessage msg = msgFactory.createMessage();
0649: SOAPPart soapPart = msg.getSOAPPart();
0650: SOAPEnvelope envelope = soapPart.getEnvelope();
0651: SOAPHeader hdr = envelope.getHeader();
0652: SOAPBody body = envelope.getBody();
0653:
0654: SOAPFault sf = body.addFault();
0655: String faultCodeLocalName = "Client2";
0656: String faultCodePrefix = "fcp";
0657: String faultCodeUri = "http://test/fault/code";
0658: body.addNamespaceDeclaration(faultCodePrefix, faultCodeUri);
0659: //Name faultCodeName = envelope.createName(faultCodeLocalName, faultCodePrefix, faultCodeUri);
0660: //sf.setFaultCode(faultCodeName);
0661: sf.setFaultCode(faultCodePrefix + ":" + faultCodeLocalName);
0662: sf.setFaultString("This is the fault string");
0663:
0664: Name faultCode = sf.getFaultCodeAsName();
0665: assertEquals(faultCodePrefix, faultCode.getPrefix());
0666: assertEquals(faultCodeUri, faultCode.getURI());
0667: assertEquals(faultCodeLocalName, faultCode.getLocalName());
0668:
0669: }
0670:
0671: public void testGetFaultCodeAsName2() throws Exception {
0672:
0673: MessageFactory msgFactory = MessageFactory.newInstance();
0674: SOAPMessage msg = msgFactory.createMessage();
0675: SOAPPart soapPart = msg.getSOAPPart();
0676: SOAPEnvelope envelope = soapPart.getEnvelope();
0677: SOAPHeader hdr = envelope.getHeader();
0678: SOAPBody body = envelope.getBody();
0679:
0680: SOAPFault sf = body.addFault();
0681: String faultCodeLocalName = "Client2";
0682: String faultCodePrefix = "fcp";
0683: String faultCodeUri = "http://test/fault/code";
0684: Name faultCodeName = envelope.createName(faultCodeLocalName,
0685: faultCodePrefix, faultCodeUri);
0686: sf.setFaultCode(faultCodeName);
0687: sf.setFaultString("This is the fault string");
0688:
0689: Name faultCode = sf.getFaultCodeAsName();
0690: assertEquals(faultCodePrefix, faultCode.getPrefix());
0691: assertEquals(faultCodeUri, faultCode.getURI());
0692: assertEquals(faultCodeLocalName, faultCode.getLocalName());
0693:
0694: }
0695:
0696: // Bug 4824922
0697: public void testEvelopeNamespacePropogation() throws Exception {
0698:
0699: DocumentBuilderFactory factory = new com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl();
0700: factory.setNamespaceAware(true);
0701: DocumentBuilder builder = factory.newDocumentBuilder();
0702:
0703: Document domDoc = builder.parse(new File(
0704: "src/test/bugfixes/data/env-prefix.xml"));
0705: Source domSource = new javax.xml.transform.dom.DOMSource(domDoc);
0706:
0707: MessageFactory mfactory = MessageFactory.newInstance();
0708: SOAPMessage msg = mfactory.createMessage();
0709:
0710: SOAPPart part = msg.getSOAPPart();
0711:
0712: part.setContent(domSource);
0713:
0714: SOAPEnvelope env = part.getEnvelope();
0715: SOAPHeader header = env.getHeader();
0716: if (header == null)
0717: header = env.addHeader();
0718: header.addTextNode("This goes inside the SOAP header");
0719:
0720: SOAPBody body = env.getBody();
0721: body.addTextNode("Some random stuff goes in here");
0722: assertEquals("env", header.getPrefix());
0723:
0724: }
0725:
0726: public void testVersionMismatch() throws Exception {
0727: String RPC = "<soap:Envelope\n"
0728: + " xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/bogus/'>\n"
0729: + " <soap:Header/>\n" + " <soap:Body/>\n"
0730: + "</soap:Envelope>\n";
0731:
0732: final MimeHeaders headers = new MimeHeaders();
0733: headers.addHeader("Content-Type", "text/xml");
0734:
0735: MessageFactory factory = MessageFactory.newInstance();
0736: InputStream istream = new StringBufferInputStream(RPC);
0737: BufferedInputStream bistream = new BufferedInputStream(istream);
0738: try {
0739: SOAPMessage m = factory.createMessage(headers, bistream);
0740: m.getSOAPBody();
0741: } catch (SOAPVersionMismatchException e) {
0742: assertTrue(true);
0743: return;
0744: }
0745: fail();
0746: }
0747:
0748: /**
0749: * Trying to reproduce bug 4819222.
0750: */
0751: public void testCreateSOAPMessage() throws Exception {
0752: String RPC = "<soap:Envelope\n"
0753: + " xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"
0754: + "<soap:Body/>" + "</soap:Envelope>";
0755:
0756: final MimeHeaders headers = new MimeHeaders();
0757: headers.addHeader("Content-Type", "text/xml");
0758:
0759: MessageFactory factory = MessageFactory.newInstance();
0760: InputStream istream = new StringBufferInputStream(RPC);
0761: BufferedInputStream bistream = new BufferedInputStream(istream);
0762: SOAPMessage m = factory.createMessage(headers, bistream);
0763:
0764: SOAPPart part = m.getSOAPPart();
0765: SOAPEnvelope envelope = part.getEnvelope();
0766: SOAPHeader header = envelope.addHeader();
0767: assertTrue("Header has the same prefix as envelope", header
0768: .getPrefix().equals(envelope.getPrefix()));
0769: }
0770:
0771: /*
0772: * Reproducing GetAllAttributes TCK failure.
0773: */
0774: public void testGetAllAttributes() throws Exception {
0775:
0776: MessageFactory msgFactory = MessageFactory.newInstance();
0777: SOAPMessage msg = msgFactory.createMessage();
0778: SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
0779: SOAPHeader hdr = envelope.getHeader();
0780: SOAPBody body = envelope.getBody();
0781:
0782: Name name1 = envelope.createName("MyAttr1");
0783: String value1 = "MyValue1";
0784: Name name2 = envelope.createName("MyAttr2");
0785: String value2 = "MyValue2";
0786: Name name3 = envelope.createName("MyAttr3");
0787: String value3 = "MyValue3";
0788:
0789: body.addAttribute(name1, value1);
0790: body.addAttribute(name2, value2);
0791: body.addAttribute(name3, value3);
0792:
0793: Iterator i = body.getAllAttributes();
0794: int count = 0;
0795: while (i.hasNext()) {
0796: count++;
0797: i.next();
0798: }
0799:
0800: if (count != 3)
0801: fail("Wrong iterator count returned of " + count
0802: + ", expected 3");
0803:
0804: i = body.getAllAttributes();
0805: while (i.hasNext()) {
0806: Name name = (Name) i.next();
0807: assertEquals("Wrong Name returned", name.getPrefix(), name1
0808: .getPrefix());
0809: // the bug was that the URI's were not matching.
0810: assertEquals("Wrong Name returned", name.getURI(), name1
0811: .getURI());
0812:
0813: }
0814: }
0815:
0816: /*
0817: * Add Namespace of the attribute if it is not declared before.
0818: * Namespace declaration should not be an attribute (complying
0819: * with saaj 1.1)
0820: */
0821: public void testGetAllAttributesXmlns() throws Exception {
0822:
0823: MessageFactory msgFactory = MessageFactory.newInstance();
0824: SOAPMessage msg = msgFactory.createMessage();
0825: SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
0826: SOAPHeader hdr = envelope.getHeader();
0827: SOAPBody body = envelope.getBody();
0828:
0829: Name name1 = envelope.createName("MyAttr1");
0830: String value1 = "MyValue1";
0831: Name name2 = envelope.createName("MyAttr2");
0832: String value2 = "MyValue2";
0833: Name name3 = envelope.createName("MyAttr3", "f",
0834: "http://www.ee.com");
0835: String value3 = "MyValue3";
0836:
0837: body.addAttribute(name1, value1);
0838: body.addAttribute(name2, value2);
0839: body.addAttribute(name3, value3);
0840:
0841: Iterator i = body.getAllAttributes();
0842: int count = 0;
0843: while (i.hasNext()) {
0844: count++;
0845: i.next();
0846: }
0847: if (count != 3)
0848: fail("Wrong iterator count returned of " + count
0849: + ", expected 3");
0850:
0851: }
0852:
0853: /*
0854: * Bug Id 4823704
0855: */
0856: public void testSOAPBodyAddDocument() throws Exception {
0857:
0858: DocumentBuilderFactory factory = new com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl();
0859: factory.setNamespaceAware(true);
0860: DocumentBuilder builder = factory.newDocumentBuilder();
0861:
0862: InputStream istream = new StringBufferInputStream(
0863: "<foo> bar <w> we </w> </foo>");
0864: Document doc = builder.parse(istream);
0865:
0866: MessageFactory mfactory = MessageFactory.newInstance();
0867: SOAPMessage msg = mfactory.createMessage();
0868: SOAPPart part = msg.getSOAPPart();
0869: SOAPBody body = part.getEnvelope().getBody();
0870:
0871: SOAPBodyElement e = body.addDocument(doc);
0872: // System.out.println("e " + e.getNodeName());
0873:
0874: String expected = "<SOAP-ENV:Envelope xmlns:SOAP-ENV"
0875: + "=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header/>"
0876: + "<SOAP-ENV:Body><foo> bar <w> we </w> </foo></SOAP-ENV:Body>"
0877: + "</SOAP-ENV:Envelope>";
0878: ByteArrayOutputStream output = new ByteArrayOutputStream();
0879: msg.writeTo(output);
0880: String actual = output.toString();
0881: assertEquals(expected, actual);
0882: }
0883:
0884: /*
0885: * TCK failure for addChildElementTest5.
0886: */
0887: public void testAddChildElementTest5() throws Exception {
0888:
0889: MessageFactory mfactory = MessageFactory.newInstance();
0890: SOAPMessage msg = mfactory.createMessage();
0891: SOAPPart part = msg.getSOAPPart();
0892: SOAPEnvelope envelope = part.getEnvelope();
0893: SOAPBody body = envelope.getBody();
0894:
0895: SOAPElementFactory sfactory = SOAPElementFactory.newInstance();
0896: Name name = envelope.createName("MyName1", "MyPrefix1",
0897: "MyUri1");
0898:
0899: SOAPElement myse = sfactory.create(name);
0900: SOAPElement se = body.addChildElement(myse);
0901:
0902: if (se == null) {
0903: fail("addChildElement() did not return SOAPElement");
0904: } else {
0905: Iterator i = body.getChildElements(name);
0906: int count = 0;
0907: while (i.hasNext()) {
0908: count++;
0909: i.next();
0910: }
0911: if (count != 1)
0912: fail("Count should be 1, but got " + count);
0913:
0914: i = body.getChildElements(name);
0915:
0916: SOAPElement se2 = (SOAPElement) i.next();
0917: if (!se.equals(se2)) {
0918: fail("addChildElementTest5() test FAILED");
0919: }
0920: }
0921:
0922: Name n = se.getElementName();
0923: if (!n.equals(name)) {
0924: fail("addChildElement() did not return "
0925: + "correct name object expected localname="
0926: + name.getLocalName() + ", got localname="
0927: + n.getLocalName());
0928: }
0929: }
0930:
0931: public void testAddTextNode1() throws Exception {
0932:
0933: MessageFactory mfactory = MessageFactory.newInstance();
0934: SOAPMessage msg = mfactory.createMessage();
0935: SOAPPart part = msg.getSOAPPart();
0936: SOAPEnvelope envelope = part.getEnvelope();
0937: SOAPBody body = envelope.getBody();
0938:
0939: Iterator iStart = envelope.getChildElements();
0940: SOAPElement se = envelope
0941: .addTextNode("<txt>This is text</txt>");
0942:
0943: if (se == null) {
0944: fail("addTextNode() did not return SOAPElement");
0945: } else if (!envelope.getValue().equals(
0946: "<txt>This is text</txt>")) {
0947: String s = body.getValue();
0948: fail("Returned " + s + ", Expected <txt>"
0949: + "This is text</txt>");
0950: }
0951: }
0952:
0953: public void testAddDocument() throws Exception {
0954:
0955: Document document = null;
0956: DocumentBuilderFactory factory = new com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl();
0957: factory.setNamespaceAware(true);
0958:
0959: DocumentBuilder builder = factory.newDocumentBuilder();
0960: // document = builder.parse(new File("src/test/bugfixes/data/slide.xml"));
0961: document = builder.parse(new File(
0962: "src/test/bugfixes/data/message.xml"));
0963:
0964: // Create message factory and SOAP factory
0965: MessageFactory messageFactory = MessageFactory.newInstance();
0966: SOAPFactory soapFactory = SOAPFactory.newInstance();
0967:
0968: // Create a message
0969: SOAPMessage message = messageFactory.createMessage();
0970:
0971: // Get the SOAP header from the message and remove it
0972: SOAPHeader header = message.getSOAPHeader();
0973: header.detachNode();
0974:
0975: // Get the SOAP body from the message
0976: SOAPBody body = message.getSOAPBody();
0977:
0978: SOAPBodyElement sbe = body.addBodyElement(new QName(
0979: "http://schemas.xmlsoap.org/soap/envelope/",
0980: "Envelope", "SOAP-ENV"));
0981:
0982: // Add the DOM to the message body
0983: SOAPBodyElement docElement = body.addDocument(document);
0984:
0985: assertTrue("Both body elements have the same name.", sbe
0986: .getElementQName().equals(docElement.getElementQName()));
0987:
0988: message.saveChanges();
0989:
0990: Iterator iter1 = body.getChildElements();
0991:
0992: SOAPBodyElement firstChild = (SOAPBodyElement) iter1.next();
0993: assertNull("firstChild (sbe) has no child.", firstChild
0994: .getFirstChild());
0995:
0996: SOAPBodyElement secondChild = (SOAPBodyElement) iter1.next();
0997: assertNotNull(
0998: "secondChild (docElement) has atleast one child.",
0999: secondChild.getFirstChild());
1000: assertEquals("secondChild (docElement) has exactly one child.",
1001: secondChild.getFirstChild(), secondChild.getLastChild());
1002:
1003: // Get contents using SAAJ APIs
1004: getContents(iter1, "", false);
1005: }
1006:
1007: /*
1008: * Add a document which contains an undeclared namespace.
1009: */
1010: public void testAddDocWithUndeclaredNS() throws Exception {
1011:
1012: try {
1013: Document document = null;
1014: DocumentBuilderFactory factory = new com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl();
1015: //factory.setNamespaceAware(true);
1016:
1017: DocumentBuilder builder = factory.newDocumentBuilder();
1018: document = builder.parse(new File(
1019: "src/test/bugfixes/data/undeclNS.xml"));
1020:
1021: // Create message factory and SOAP factory
1022: MessageFactory messageFactory = MessageFactory
1023: .newInstance();
1024: SOAPFactory soapFactory = SOAPFactory.newInstance();
1025:
1026: // Create a message
1027: SOAPMessage message = messageFactory.createMessage();
1028:
1029: // Get the SOAP header from the message and remove it
1030: SOAPHeader header = message.getSOAPHeader();
1031: header.detachNode();
1032:
1033: // Get the SOAP body from the message
1034: SOAPBody body = message.getSOAPBody();
1035:
1036: // Add the DOM to the message body
1037: SOAPBodyElement docElement = body.addDocument(document);
1038:
1039: message.saveChanges();
1040: } catch (Exception e) {
1041: return;
1042: }
1043: fail("An exception should have been thrown");
1044:
1045: // Get contents using SAAJ APIs
1046: //Iterator iter1 = body.getChildElements();
1047: //getContents(iter1, "", false);
1048: }
1049:
1050: /*
1051: * Recursive method to get and print contents of elements
1052: */
1053: private void getContents(Iterator iterator, String indent,
1054: boolean display) {
1055: String displayStr = null;
1056:
1057: while (iterator.hasNext()) {
1058: Node node = (Node) iterator.next();
1059: SOAPElement element = null;
1060: Text text = null;
1061: if (node instanceof SOAPElement) {
1062: element = (SOAPElement) node;
1063: Name name = element.getElementName();
1064: displayStr = indent + "Name is "
1065: + name.getQualifiedName();
1066: if (display) {
1067: System.out.println(displayStr);
1068: }
1069: Iterator attrs = element.getAllAttributes();
1070: while (attrs.hasNext()) {
1071: Name attrName = (Name) attrs.next();
1072: displayStr = indent + " Attribute name is "
1073: + attrName.getQualifiedName();
1074: if (display) {
1075: System.out.println(displayStr);
1076: }
1077: displayStr = indent + " Attribute value is "
1078: + element.getAttributeValue(attrName);
1079: if (display) {
1080: System.out.println(displayStr);
1081: }
1082: }
1083: Iterator iter2 = element.getChildElements();
1084: getContents(iter2, indent + " ", display);
1085: } else {
1086: text = (Text) node;
1087: displayStr = indent + "Content is: " + text.getValue();
1088: if (display) {
1089: System.out.println(displayStr);
1090: }
1091: }
1092: }
1093: }
1094:
1095: /*
1096: * Bug : 4863987
1097: * Creates unnecessary xmlns:SOAP-ENV attributes for header elements
1098: */
1099: public void testExamineHeaderElements() throws Exception {
1100:
1101: MessageFactory mf = MessageFactory.newInstance();
1102: SOAPMessage msg = mf.createMessage();
1103: SOAPPart sp = msg.getSOAPPart();
1104:
1105: SOAPEnvelope envelope = sp.getEnvelope();
1106:
1107: SOAPHeader hdr = envelope.getHeader();
1108: SOAPBody bdy = envelope.getBody();
1109:
1110: // Add to body
1111: SOAPBodyElement gltp = bdy.addBodyElement(envelope.createName(
1112: "GetLastTradePrice", "ztrade",
1113: "http://wombat.ztrade.com"));
1114:
1115: gltp.addChildElement(
1116: envelope.createName("symbol", "ztrade",
1117: "http://wombat.ztrade.com"))
1118: .addTextNode("SUNW");
1119:
1120: // Attach header
1121: SOAPHeaderElement she = null;
1122: Name reservation = envelope.createName("reservation", "tr",
1123: "http://trs.org/reservation");
1124: SOAPHeaderElement resHeaderElem = hdr
1125: .addHeaderElement(reservation);
1126: resHeaderElem.setActor(SOAPConstants.URI_SOAP_ACTOR_NEXT);
1127: resHeaderElem.setMustUnderstand(false);
1128:
1129: // Save the soap message to file
1130: FileOutputStream sentFile = new FileOutputStream(
1131: "src/test/bugfixes/data/examine.xml");
1132: msg.writeTo(sentFile);
1133: sentFile.close();
1134:
1135: // Examine the headers
1136: FileInputStream fin = new FileInputStream(
1137: "src/test/bugfixes/data/examine.xml");
1138: SOAPMessage recvMsg = mf.createMessage(msg.getMimeHeaders(),
1139: fin);
1140: ByteArrayOutputStream correct = new ByteArrayOutputStream();
1141: recvMsg.writeTo(correct);
1142: SOAPHeader recvHdr = recvMsg.getSOAPHeader();
1143: recvHdr
1144: .examineHeaderElements(SOAPConstants.URI_SOAP_ACTOR_NEXT);
1145: ByteArrayOutputStream incorrect = new ByteArrayOutputStream();
1146: recvMsg.writeTo(incorrect);
1147: fin.close();
1148: Iterator it = ((javax.xml.soap.SOAPHeader) recvHdr)
1149: .getChildElements();
1150: SOAPHeaderElement n = (SOAPHeaderElement) it.next();
1151: //making sure there was a Actor.
1152: assertTrue(n.getActor() != null);
1153: //making sure MU was "0""
1154: assertTrue(!n.getMustUnderstand());
1155:
1156: // the check cannot be like this because with the latest workspace
1157: // there is just a re-ordering of the attributes.
1158: //assertTrue(correct.toString().equals(incorrect.toString()));
1159: }
1160:
1161: /*
1162: * Doesn't produce the text node value correctly
1163: */
1164: public void testSplitAttrValue() throws Exception {
1165: byte[] junk = new byte[10000];
1166: FileInputStream fin = new FileInputStream(
1167: "src/test/bugfixes/data/bugAttr.xml");
1168: int chars = fin.read(junk);
1169: fin.close();
1170: MessageFactory mfactory = MessageFactory.newInstance();
1171: SOAPMessage msg = mfactory.createMessage();
1172:
1173: SOAPPart part = msg.getSOAPPart();
1174: StreamSource streamSource = new StreamSource(
1175: new ByteInputStream(junk, chars));
1176:
1177: part.setContent(streamSource);
1178: SOAPElement root = part.getEnvelope();
1179: org.w3c.dom.Node node = root.getFirstChild();
1180: node = node.getFirstChild();
1181: node = node.getNextSibling();
1182: node = node.getNextSibling();
1183: node = node.getNextSibling();
1184: node = node.getNextSibling();
1185: node = node.getNextSibling();
1186: node = node.getNextSibling();
1187: SOAPElement item = (SOAPElement) node.getFirstChild();
1188: assertEquals("s12", item.getValue());
1189: }
1190:
1191: /*
1192: * Doesn't produce the text node value correctly
1193: */
1194: public void testSimpleSplitText() throws Exception {
1195: String msgText = "<SOAP-ENV:Envelope "
1196: + "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
1197: + "<SOAP-ENV:Body>" + "<foo>hello9world</foo>"
1198: + "</SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>";
1199:
1200: for (int i = 0; i < 1950; i++) {
1201: msgText = msgText.replaceFirst("9", "99");
1202: }
1203: //System.out.println("Msg text="+msgText);
1204: //System.out.println("Endorsed="+System.getProperty("java.endorsed.dirs"));
1205: MessageFactory mfactory = MessageFactory.newInstance();
1206: SOAPMessage msg = mfactory.createMessage();
1207:
1208: SOAPPart part = msg.getSOAPPart();
1209: StreamSource streamSource = new StreamSource(
1210: new ByteArrayInputStream(msgText.getBytes()));
1211:
1212: part.setContent(streamSource);
1213: SOAPEnvelope envelope = part.getEnvelope();
1214: SOAPHeader hdr = envelope.getHeader();
1215: SOAPBody body = envelope.getBody();
1216: SOAPElement foo = (SOAPElement) body.getFirstChild();
1217: if (!foo.getValue().endsWith("world")) {
1218: fail("The text is broken into multiple nodes");
1219: }
1220: }
1221:
1222: public void testBug4742689() throws Exception {
1223: MessageFactory mf = MessageFactory.newInstance();
1224: SOAPMessage sm = mf.createMessage();
1225: sm.getSOAPPart().getEnvelope().getBody()
1226: .addChildElement("test").addTextNode(
1227: "<![CDATA[testing]]>");
1228: SOAPBody body = sm.getSOAPBody();
1229: SOAPBodyElement element = (SOAPBodyElement) body
1230: .getFirstChild();
1231: assertEquals(element.getValue(), "testing");
1232: }
1233:
1234: public void testBug6389297() throws SOAPException {
1235: MessageFactory factory = MessageFactory
1236: .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
1237: SOAPMessage message = factory.createMessage();
1238: SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
1239: SOAPBody body = envelope.getBody();
1240: SOAPFault fault = body.addFault();
1241: fault.addFaultReasonText("Version Mismatch", Locale.ENGLISH);
1242: org.w3c.dom.Node reason = fault.getLastChild();
1243: Element text = (Element) reason.getFirstChild();
1244: //returns an empty string for xmlns:xml
1245: assertEquals("", text.getAttribute("xmlns:xml"));
1246: }
1247:
1248: public static void main(String[] args) throws Exception {
1249: if (th.isDebug()) {
1250: // Run a subset of tests. Developers should feel free to
1251: // change which tests are run here. As of Dec 2002, one can
1252: // use the "test-1" Ant target to run these tests in debug
1253: // mode. [eeg 07jan03]
1254: TestSuite ts = new TestSuite();
1255: //ts.addTest(new BugfixesTest("testFaultDetailSoap1_2"));
1256: ts.addTest(new BugfixesTest(
1257: "testFaultUnqualifiedSubElements"));
1258: junit.textui.TestRunner.run(ts);
1259: } else {
1260: junit.textui.TestRunner.run(BugfixesTest.class);
1261: }
1262: }
1263: }
|