11/*
2- * Copyright (c) 2018, 2019 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2018, 2022 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3434import org .testng .Assert ;
3535import org .testng .annotations .Listeners ;
3636import org .testng .annotations .Test ;
37+ import org .w3c .dom .Attr ;
3738import org .w3c .dom .Document ;
3839import org .w3c .dom .Element ;
3940import org .w3c .dom .Node ;
41+ import org .w3c .dom .bootstrap .DOMImplementationRegistry ;
4042import org .w3c .dom .events .Event ;
4143import org .w3c .dom .events .EventListener ;
44+ import org .w3c .dom .ls .DOMImplementationLS ;
45+ import org .w3c .dom .ls .LSInput ;
46+ import org .w3c .dom .ls .LSParser ;
4247
4348/*
4449 * @test
45- * @bug 8213117 8222743
50+ * @bug 8213117 8222743 8287076
4651 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
4752 * @modules java.xml
4853 * @modules java.xml/com.sun.org.apache.xerces.internal.dom
@@ -56,6 +61,53 @@ public class DocumentTest {
5661 static final int DOC1 = 1 ;
5762 static final int DOC2 = 2 ;
5863
64+ /*
65+ * @bug 8287076
66+ * Verifies that Document::normalizeDocument returns the same result as that
67+ * prior to JDK 10 (JDK-8181150).
68+ * Attribute Name:
69+ * JDK 9: NS1:wsu and NS2:wsu2
70+ * After the JDK 10 change: wsu and wsu2
71+ */
72+ @ Test
73+ public void testNormalizeDocument () throws Exception {
74+ final DOMImplementationRegistry registry = DOMImplementationRegistry .newInstance ();
75+ final DOMImplementationLS impl = (DOMImplementationLS ) registry .getDOMImplementation ("LS" );
76+ final LSParser builder = impl .createLSParser (DOMImplementationLS .MODE_SYNCHRONOUS , null );
77+ final LSInput input = impl .createLSInput ();
78+ input .setStringData ("<xml/>" );
79+ final Document document = builder .parse (input );
80+ final Element root = document .getDocumentElement ();
81+
82+ // Generate a single element
83+ final Element element = document .createElement ("token" );
84+ final Attr attr = element .getOwnerDocument ().createAttributeNS ("http://blah.xsd" , "wsu" );
85+ attr .setValue ("Id" );
86+ element .setAttributeNodeNS (attr );
87+
88+ final Attr attr2 = element .getOwnerDocument ().createAttributeNS ("http://blah2.xsd" , "wsu2" );
89+ element .setAttributeNodeNS (attr2 );
90+
91+ final Attr attr3 = element .getOwnerDocument ().createAttribute ("aa" );
92+ element .setAttributeNodeNS (attr3 );
93+
94+ final Attr attr4 = element .getOwnerDocument ().createAttribute ("zz" );
95+ element .setAttributeNodeNS (attr4 );
96+
97+ final Attr attr5 = element .getOwnerDocument ().createAttribute ("tt" );
98+ element .setAttributeNodeNS (attr5 );
99+
100+ root .appendChild (element );
101+
102+ document .normalizeDocument ();
103+
104+ Node wsu = element .getAttributes ().getNamedItemNS ("http://blah.xsd" , "wsu" );
105+ Node wsu2 = element .getAttributes ().getNamedItemNS ("http://blah2.xsd" , "wsu2" );
106+
107+ Assert .assertEquals (wsu .getNodeName (), "NS1:wsu" );
108+ Assert .assertEquals (wsu2 .getNodeName (), "NS2:wsu2" );
109+ }
110+
59111 /**
60112 * Verifies the adoptNode method. Before a node from a deferred DOM can be
61113 * adopted, it needs to be fully expanded.
0 commit comments