< prev index next >

test/javax/xml/jaxp/unittest/dom/Bug4915748.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;
  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.DOMConfiguration;
  33 import org.w3c.dom.DOMError;
  34 import org.w3c.dom.DOMErrorHandler;
  35 import org.w3c.dom.Document;
  36 
  37 /*
  38  * @bug 4915748
  39  * @summary Test DOMErrorHandler is called in case CDATA section is split by termination marker ']]>'.
  40  */

  41 public class Bug4915748 {
  42 
  43     @Test
  44     public void testMain() throws Exception {
  45 
  46         final boolean[] hadError = new boolean[1];
  47 
  48         DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance();
  49         DocumentBuilder docBuilder = docBF.newDocumentBuilder();
  50 
  51         Document doc = docBuilder.getDOMImplementation().createDocument("namespaceURI", "ns:root", null);
  52 
  53         CDATASection cdata = doc.createCDATASection("text1]]>text2");
  54         doc.getDocumentElement().appendChild(cdata);
  55 
  56         DOMConfiguration config = doc.getDomConfig();
  57         DOMErrorHandler erroHandler = new DOMErrorHandler() {
  58             public boolean handleError(DOMError error) {
  59                 System.out.println(error.getMessage());
  60                 Assert.assertEquals(error.getType(), "cdata-sections-splitted");
   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;
  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.DOMConfiguration;
  34 import org.w3c.dom.DOMError;
  35 import org.w3c.dom.DOMErrorHandler;
  36 import org.w3c.dom.Document;
  37 
  38 /*
  39  * @bug 4915748
  40  * @summary Test DOMErrorHandler is called in case CDATA section is split by termination marker ']]>'.
  41  */
  42 @Listeners({jaxp.library.BasePolicy.class})
  43 public class Bug4915748 {
  44 
  45     @Test
  46     public void testMain() throws Exception {
  47 
  48         final boolean[] hadError = new boolean[1];
  49 
  50         DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance();
  51         DocumentBuilder docBuilder = docBF.newDocumentBuilder();
  52 
  53         Document doc = docBuilder.getDOMImplementation().createDocument("namespaceURI", "ns:root", null);
  54 
  55         CDATASection cdata = doc.createCDATASection("text1]]>text2");
  56         doc.getDocumentElement().appendChild(cdata);
  57 
  58         DOMConfiguration config = doc.getDomConfig();
  59         DOMErrorHandler erroHandler = new DOMErrorHandler() {
  60             public boolean handleError(DOMError error) {
  61                 System.out.println(error.getMessage());
  62                 Assert.assertEquals(error.getType(), "cdata-sections-splitted");
< prev index next >