jaxp/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/NodeTest.java
author joehw
Wed, 15 Apr 2015 21:54:29 -0700
changeset 29947 3ea7da18938d
child 40223 64662417aa2d
permissions -rw-r--r--
8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests Reviewed-by: lancea, joehw Contributed-by: frank.yuan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29947
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     1
/*
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     4
 *
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     8
 *
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    13
 * accompanied this code).
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    14
 *
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    18
 *
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    21
 * questions.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    22
 */
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    23
package org.w3c.dom.ptests;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    24
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    25
import static jaxp.library.JAXPTestUtilities.compareWithGold;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    26
import static org.testng.Assert.assertEquals;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    27
import static org.testng.Assert.assertFalse;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    28
import static org.testng.Assert.assertNotEquals;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    29
import static org.testng.Assert.assertTrue;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    30
import static org.w3c.dom.ptests.DOMTestUtil.GOLDEN_DIR;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    31
import static org.w3c.dom.ptests.DOMTestUtil.createDOM;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    32
import static org.w3c.dom.ptests.DOMTestUtil.createDOMWithNS;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    33
import static org.w3c.dom.ptests.DOMTestUtil.createNewDocument;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    34
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    35
import java.io.File;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    36
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    37
import javax.xml.transform.Transformer;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    38
import javax.xml.transform.TransformerException;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    39
import javax.xml.transform.TransformerFactory;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    40
import javax.xml.transform.TransformerFactoryConfigurationError;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    41
import javax.xml.transform.dom.DOMSource;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    42
import javax.xml.transform.stream.StreamResult;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    43
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    44
import jaxp.library.JAXPFileBaseTest;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    45
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    46
import org.testng.annotations.DataProvider;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    47
import org.testng.annotations.Test;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    48
import org.w3c.dom.DOMException;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    49
import org.w3c.dom.Document;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    50
import org.w3c.dom.DocumentFragment;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    51
import org.w3c.dom.Element;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    52
import org.w3c.dom.Node;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    53
import org.w3c.dom.NodeList;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    54
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    55
/*
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    56
 * @summary Test Node interface
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    57
 */
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    58
public class NodeTest extends JAXPFileBaseTest {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    59
    @DataProvider(name = "feature-supported")
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    60
    public Object[][] getFeatureSupportedList() throws Exception {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    61
        Document document = createDOMWithNS("Node01.xml");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    62
        Node node = document.getElementsByTagName("body").item(0);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    63
        return new Object[][] {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    64
                { node, "XML", "2.0", true },
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    65
                { node, "HTML", "2.0", false },
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    66
                { node, "Views", "2.0", false },
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    67
                { node, "StyleSheets", "2.0", false },
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    68
                { node, "CSS", "2.0", false },
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    69
                { node, "CSS2", "2.0", false },
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    70
                { node, "Events", "2.0", true },
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    71
                { node, "UIEvents", "2.0", false },
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    72
                { node, "MouseEvents", "2.0", false },
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    73
                { node, "HTMLEvents", "2.0", false },
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    74
                { node, "Traversal", "2.0", true },
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    75
                { node, "Range", "2.0", true } };
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    76
    }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    77
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    78
    /*
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    79
     * Verify Node for feature supporting.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    80
     */
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    81
    @Test(dataProvider = "feature-supported")
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    82
    public void testHasFeature(Node node, String feature, String version, boolean supported) {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    83
        assertEquals(node.isSupported(feature, version), supported);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    84
    }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    85
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    86
    /*
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    87
     * Test normalize method will merge adjacent Text nodes.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    88
     */
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    89
    @Test
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    90
    public void testNormalize() throws Exception {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    91
        Document document = createDOM("Node05.xml");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    92
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    93
        Element root = document.getDocumentElement();
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    94
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    95
        Node node =  document.getElementsByTagName("title").item(0);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    96
        node.appendChild(document.createTextNode("test"));
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    97
        root.normalize();
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    98
        assertEquals(node.getChildNodes().item(0).getNodeValue(), "Typographytest");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    99
    }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   100
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   101
    /*
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   102
     * Test cloneNode deeply, and the clone node can be appended on the same document.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   103
     */
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   104
    @Test
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   105
    public void testCloneNode() throws Exception {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   106
        Document document = createDOMWithNS("Node02.xml");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   107
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   108
        NodeList nodeList = document.getElementsByTagName("body");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   109
        Node node = nodeList.item(0);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   110
        Node cloneNode = node.cloneNode(true);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   111
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   112
        assertTrue(node.isEqualNode(cloneNode));
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   113
        assertNotEquals(node, cloneNode);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   114
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   115
        nodeList = document.getElementsByTagName("html");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   116
        Node node2 = nodeList.item(0);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   117
        node2.appendChild(cloneNode);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   118
    }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   119
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   120
    /*
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   121
     * Test importing node from one document to another.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   122
     */
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   123
    @Test
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   124
    public void testImportNode() throws Exception {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   125
        Document document = createDOMWithNS("Node02.xml");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   126
        Document otherDocument = createDOMWithNS("ElementSample01.xml");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   127
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   128
        NodeList otherNodeList = otherDocument.getElementsByTagName("body");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   129
        Node importedNode = otherNodeList.item(0);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   130
        Node clone = importedNode.cloneNode(true);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   131
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   132
        Node retNode = document.importNode(importedNode, true);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   133
        assertTrue(clone.isEqualNode(importedNode)); //verify importedNode is not changed
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   134
        assertNotEquals(retNode, importedNode);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   135
        assertTrue(importedNode.isEqualNode(retNode));
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   136
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   137
        retNode = document.importNode(importedNode, false);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   138
        assertTrue(clone.isEqualNode(importedNode)); //verify importedNode is not changed
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   139
        assertEquals(retNode.getNodeName(), importedNode.getNodeName());
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   140
        assertFalse(importedNode.isEqualNode(retNode));
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   141
    }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   142
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   143
    /*
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   144
     * Test inserting a document fragment before a particular node.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   145
     */
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   146
    @Test
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   147
    public void testInsertBefore() throws Exception {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   148
        Document document = createDOM("Node04.xml");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   149
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   150
        Element parentElement = (Element) document.getElementsByTagName("to").item(0);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   151
        Element element = (Element) document.getElementsByTagName("sender").item(0);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   152
        parentElement.insertBefore(createTestDocumentFragment(document), element);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   153
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   154
        String outputfile = "InsertBefore.out";
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   155
        String goldfile = GOLDEN_DIR + "InsertBeforeGF.out";
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   156
        outputXml(document, outputfile);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   157
        assertTrue(compareWithGold(goldfile, outputfile));
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   158
    }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   159
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   160
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   161
    /*
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   162
     * Test replacing a particular node with a document fragment.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   163
     */
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   164
    @Test
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   165
    public void testReplaceChild() throws Exception {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   166
        Document document = createDOM("Node04.xml");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   167
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   168
        Element parentElement = (Element) document.getElementsByTagName("to").item(0);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   169
        Element element = (Element) document.getElementsByTagName("sender").item(0);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   170
        parentElement.replaceChild(createTestDocumentFragment(document), element);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   171
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   172
        String outputfile = "ReplaceChild3.out";
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   173
        String goldfile = GOLDEN_DIR + "ReplaceChild3GF.out";
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   174
        outputXml(document, outputfile);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   175
        assertTrue(compareWithGold(goldfile, outputfile));
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   176
    }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   177
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   178
    /*
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   179
     * This test case checks for the replaceChild replacing a particular node
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   180
     * with a node which was created from a different document than the one
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   181
     * which is trying to use this method. It should throw a DOMException.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   182
     */
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   183
    @Test(expectedExceptions = DOMException.class)
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   184
    public void testReplaceChildNeg() throws Exception {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   185
        Document document = createDOM("Node04.xml");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   186
        Document doc2 = createNewDocument();
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   187
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   188
        Element parentElement = (Element) document.getElementsByTagName("to").item(0);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   189
        Element element = (Element) document.getElementsByTagName("sender").item(0);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   190
        parentElement.replaceChild(createTestDocumentFragment(doc2), element);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   191
    }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   192
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   193
    private DocumentFragment createTestDocumentFragment(Document document) {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   194
        DocumentFragment docFragment = document.createDocumentFragment();
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   195
        Element elem = document.createElement("dfElement");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   196
        elem.appendChild(document.createTextNode("Text in it"));
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   197
        docFragment.appendChild(elem);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   198
        return docFragment;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   199
    }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   200
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   201
    private void outputXml(Document document, String outputFileName) throws TransformerFactoryConfigurationError, TransformerException {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   202
        DOMSource domSource = new DOMSource(document);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   203
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   204
        StreamResult streamResult = new StreamResult(new File(outputFileName));
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   205
        transformer.transform(domSource, streamResult);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   206
    }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
   207
}