< prev index next >

test/javax/xml/jaxp/unittest/dom/ls/Bug6354955.java

Print this page


   1 /*
   2  * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package dom.ls;
  25 
  26 import javax.xml.parsers.DocumentBuilder;
  27 import javax.xml.parsers.DocumentBuilderFactory;
  28 
  29 import org.testng.Assert;

  30 import org.testng.annotations.Test;
  31 import org.w3c.dom.CDATASection;
  32 import org.w3c.dom.Comment;
  33 import org.w3c.dom.Document;
  34 import org.w3c.dom.EntityReference;
  35 import org.w3c.dom.Node;
  36 import org.w3c.dom.ProcessingInstruction;
  37 import org.w3c.dom.Text;
  38 import org.w3c.dom.ls.DOMImplementationLS;
  39 import org.w3c.dom.ls.LSSerializer;
  40 
  41 
  42 /*
  43  * @bug 6354955
  44  * @summary Test LSSerializer can writeToString on DOM Text node with white space.
  45  */

  46 public class Bug6354955 {
  47 
  48     @Test
  49     public void testTextNode() {
  50         try {
  51             Document xmlDocument = createNewDocument();
  52 
  53             String whitespace = "\r\n    ";
  54             Text textNode = xmlDocument.createTextNode(whitespace);
  55 
  56             System.out.println("original text is:\r\n\"" + whitespace + "\"");
  57             String outerXML = getOuterXML(textNode);
  58             System.out.println("OuterXML Text Node is:\r\n\"" + outerXML + "\"");
  59 
  60         } catch (Exception e) {
  61             e.printStackTrace();
  62             Assert.fail("Exception occured: " + e.getMessage());
  63         }
  64     }
  65 


   1 /*
   2  * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package dom.ls;
  25 
  26 import javax.xml.parsers.DocumentBuilder;
  27 import javax.xml.parsers.DocumentBuilderFactory;
  28 
  29 import org.testng.Assert;
  30 import org.testng.annotations.Listeners;
  31 import org.testng.annotations.Test;
  32 import org.w3c.dom.CDATASection;
  33 import org.w3c.dom.Comment;
  34 import org.w3c.dom.Document;
  35 import org.w3c.dom.EntityReference;
  36 import org.w3c.dom.Node;
  37 import org.w3c.dom.ProcessingInstruction;
  38 import org.w3c.dom.Text;
  39 import org.w3c.dom.ls.DOMImplementationLS;
  40 import org.w3c.dom.ls.LSSerializer;
  41 
  42 
  43 /*
  44  * @bug 6354955
  45  * @summary Test LSSerializer can writeToString on DOM Text node with white space.
  46  */
  47 @Listeners({jaxp.library.BasePolicy.class})
  48 public class Bug6354955 {
  49 
  50     @Test
  51     public void testTextNode() {
  52         try {
  53             Document xmlDocument = createNewDocument();
  54 
  55             String whitespace = "\r\n    ";
  56             Text textNode = xmlDocument.createTextNode(whitespace);
  57 
  58             System.out.println("original text is:\r\n\"" + whitespace + "\"");
  59             String outerXML = getOuterXML(textNode);
  60             System.out.println("OuterXML Text Node is:\r\n\"" + outerXML + "\"");
  61 
  62         } catch (Exception e) {
  63             e.printStackTrace();
  64             Assert.fail("Exception occured: " + e.getMessage());
  65         }
  66     }
  67 


< prev index next >