< prev index next >

test/javax/xml/jaxp/unittest/dom/ls/Bug6376823.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 java.io.StringBufferInputStream;
  27 
  28 import javax.xml.parsers.DocumentBuilder;
  29 import javax.xml.parsers.DocumentBuilderFactory;
  30 import javax.xml.parsers.ParserConfigurationException;
  31 
  32 import org.testng.Assert;

  33 import org.testng.annotations.Test;
  34 import org.w3c.dom.DOMConfiguration;
  35 import org.w3c.dom.DOMImplementation;
  36 import org.w3c.dom.Document;
  37 import org.w3c.dom.Node;
  38 import org.w3c.dom.ls.DOMImplementationLS;
  39 import org.w3c.dom.ls.LSInput;
  40 import org.w3c.dom.ls.LSParser;
  41 import org.w3c.dom.ls.LSSerializer;
  42 import org.w3c.dom.ls.LSSerializerFilter;
  43 import org.w3c.dom.traversal.NodeFilter;
  44 
  45 /*
  46  * @bug 6376823
  47  * @summary Test LSSerializer works.
  48  */

  49 public class Bug6376823 {
  50 
  51     private static String XML_STRING = "<?xml version=\"1.0\"?><ROOT><ELEMENT1><CHILD1/><CHILD1><COC1/></CHILD1></ELEMENT1><ELEMENT2>test1<CHILD2/></ELEMENT2></ROOT>";
  52     private static DOMImplementationLS implLS;
  53 
  54     @Test
  55     public void testStringSourceWithXmlDecl() {
  56         String result = prepare(XML_STRING, true);
  57         System.out.println("testStringSource: output: " + result);
  58         Assert.assertTrue(result.indexOf("<?xml", 5) < 0, "XML Declaration expected in output");
  59     }
  60 
  61     private String prepare(String source, boolean xmlDeclFlag) {
  62         Document startDoc = null;
  63         DocumentBuilder domParser = null;
  64         try {
  65             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  66             domParser = factory.newDocumentBuilder();
  67         } catch (ParserConfigurationException e) {
  68             e.printStackTrace();


   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 java.io.StringBufferInputStream;
  27 
  28 import javax.xml.parsers.DocumentBuilder;
  29 import javax.xml.parsers.DocumentBuilderFactory;
  30 import javax.xml.parsers.ParserConfigurationException;
  31 
  32 import org.testng.Assert;
  33 import org.testng.annotations.Listeners;
  34 import org.testng.annotations.Test;
  35 import org.w3c.dom.DOMConfiguration;
  36 import org.w3c.dom.DOMImplementation;
  37 import org.w3c.dom.Document;
  38 import org.w3c.dom.Node;
  39 import org.w3c.dom.ls.DOMImplementationLS;
  40 import org.w3c.dom.ls.LSInput;
  41 import org.w3c.dom.ls.LSParser;
  42 import org.w3c.dom.ls.LSSerializer;
  43 import org.w3c.dom.ls.LSSerializerFilter;
  44 import org.w3c.dom.traversal.NodeFilter;
  45 
  46 /*
  47  * @bug 6376823
  48  * @summary Test LSSerializer works.
  49  */
  50 @Listeners({jaxp.library.BasePolicy.class})
  51 public class Bug6376823 {
  52 
  53     private static String XML_STRING = "<?xml version=\"1.0\"?><ROOT><ELEMENT1><CHILD1/><CHILD1><COC1/></CHILD1></ELEMENT1><ELEMENT2>test1<CHILD2/></ELEMENT2></ROOT>";
  54     private static DOMImplementationLS implLS;
  55 
  56     @Test
  57     public void testStringSourceWithXmlDecl() {
  58         String result = prepare(XML_STRING, true);
  59         System.out.println("testStringSource: output: " + result);
  60         Assert.assertTrue(result.indexOf("<?xml", 5) < 0, "XML Declaration expected in output");
  61     }
  62 
  63     private String prepare(String source, boolean xmlDeclFlag) {
  64         Document startDoc = null;
  65         DocumentBuilder domParser = null;
  66         try {
  67             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  68             domParser = factory.newDocumentBuilder();
  69         } catch (ParserConfigurationException e) {
  70             e.printStackTrace();


< prev index next >