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 parsers.xinclude;
25
26 import static java.lang.System.lineSeparator;
27 import static org.testng.Assert.assertEquals;
28
29 import java.io.File;
30 import java.io.StringWriter;
31
32 import javax.xml.parsers.DocumentBuilder;
33 import javax.xml.parsers.DocumentBuilderFactory;
34 import javax.xml.transform.OutputKeys;
35 import javax.xml.transform.Transformer;
36 import javax.xml.transform.TransformerFactory;
37 import javax.xml.transform.dom.DOMSource;
38 import javax.xml.transform.stream.StreamResult;
39
40 import org.testng.annotations.Test;
41 import org.w3c.dom.Document;
42 import org.w3c.dom.NodeList;
43
44 /*
45 * @bug 6794483 8080908
46 * @summary Test JAXP parser can resolve the included content properly if the
47 * included xml contains an empty tag that ends with "/>", refer to XERCESJ-1134.
48 */
49 public class Bug6794483Test {
50
51 @Test
52 public final void test() throws Exception {
53 Document doc = parseXmlFile(getClass().getResource("test1.xml").getPath());
54
55 // check node4
56 NodeList nodeList = doc.getElementsByTagName("node4");
57 assertEquals(nodeList.getLength(), 1);
58 assertEquals(nodeList.item(0).getTextContent(), "Node4 Value", "The data of node4 is missed in parsing: " + lineSeparator() + printXmlDoc(doc));
59
60 // check node6
61 nodeList = doc.getElementsByTagName("node6");
62 assertEquals(nodeList.getLength(), 1);
63 assertEquals(nodeList.item(0).getTextContent(), "Node6 Value", "The data of node6 is missed in parsing: " + lineSeparator() + printXmlDoc(doc));
64 }
65
66 public String printXmlDoc(Document doc) throws Exception {
67 StringWriter sw = new StringWriter();
68 StreamResult result = new StreamResult(sw);
|
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 parsers.xinclude;
25
26 import static java.lang.System.lineSeparator;
27 import static org.testng.Assert.assertEquals;
28
29 import java.io.File;
30 import java.io.StringWriter;
31
32 import javax.xml.parsers.DocumentBuilder;
33 import javax.xml.parsers.DocumentBuilderFactory;
34 import javax.xml.transform.OutputKeys;
35 import javax.xml.transform.Transformer;
36 import javax.xml.transform.TransformerFactory;
37 import javax.xml.transform.dom.DOMSource;
38 import javax.xml.transform.stream.StreamResult;
39
40 import org.testng.annotations.Listeners;
41 import org.testng.annotations.Test;
42 import org.w3c.dom.Document;
43 import org.w3c.dom.NodeList;
44
45 /*
46 * @bug 6794483 8080908
47 * @summary Test JAXP parser can resolve the included content properly if the
48 * included xml contains an empty tag that ends with "/>", refer to XERCESJ-1134.
49 */
50 @Listeners({jaxp.library.FilePolicy.class})
51 public class Bug6794483Test {
52
53 @Test
54 public final void test() throws Exception {
55 Document doc = parseXmlFile(getClass().getResource("test1.xml").getPath());
56
57 // check node4
58 NodeList nodeList = doc.getElementsByTagName("node4");
59 assertEquals(nodeList.getLength(), 1);
60 assertEquals(nodeList.item(0).getTextContent(), "Node4 Value", "The data of node4 is missed in parsing: " + lineSeparator() + printXmlDoc(doc));
61
62 // check node6
63 nodeList = doc.getElementsByTagName("node6");
64 assertEquals(nodeList.getLength(), 1);
65 assertEquals(nodeList.item(0).getTextContent(), "Node6 Value", "The data of node6 is missed in parsing: " + lineSeparator() + printXmlDoc(doc));
66 }
67
68 public String printXmlDoc(Document doc) throws Exception {
69 StringWriter sw = new StringWriter();
70 StreamResult result = new StreamResult(sw);
|