--- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/AbstractCharacterDataTest.java 2015-04-02 20:10:02.500237057 -0700 @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; +import static org.w3c.dom.DOMException.INDEX_SIZE_ERR; +import static org.w3c.dom.ptests.DOMTestUtil.DOMEXCEPTION_EXPECTED; + +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; + +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.w3c.dom.CharacterData; +import org.w3c.dom.DOMException; +import org.xml.sax.SAXException; + +/* + * @summary common test for the CharacterData Interface + */ +public abstract class AbstractCharacterDataTest extends JAXPFileBaseTest { + @DataProvider(name = "data-for-length") + public Object[][] getDataForTestLength() { + return new Object[][] { + { "", 0 }, + { "test", 4 } }; + } + + /* + * Verify getLength method works as the spec, for an empty string, should + * return zero + */ + @Test(dataProvider = "data-for-length") + public void testGetLength(String text, int length) throws Exception { + CharacterData cd = createCharacterData(text); + assertEquals(cd.getLength(), length); + + } + + @Test + public void testAppendData() throws Exception { + CharacterData cd = createCharacterData("DOM"); + cd.appendData("2"); + assertEquals(cd.getData(), "DOM2"); + + } + + @DataProvider(name = "data-for-delete") + public Object[][] getDataForTestDelete() { + return new Object[][] { + { "DOM", 2, 1, "DO" }, + { "DOM", 0, 2, "M" }, + { "DOM", 2, 3, "DO" } }; + } + + /* + * Verify deleteData method works as the spec. + */ + @Test(dataProvider = "data-for-delete") + public void testDeleteData(String text, int offset, int count, String result) throws Exception { + CharacterData cd = createCharacterData(text); + cd.deleteData(offset, count); + assertEquals(cd.getData(), result); + } + + @DataProvider(name = "data-for-replace") + public Object[][] getDataForTestReplace() { + return new Object[][] { + { "DOM", 0, 3, "SAX", "SAX" }, + { "DOM", 1, 1, "AA", "DAAM" }, + { "DOM", 1, 2, "A", "DA" }, + { "DOM", 2, 2, "SAX", "DOSAX" } }; + } + + /* + * Verify replaceData method works as the spec. + */ + @Test(dataProvider = "data-for-replace") + public void testReplaceData(String text, int offset, int count, String arg, String result) throws Exception { + CharacterData cd = createCharacterData(text); + cd.replaceData(offset, count, arg); + assertEquals(cd.getData(), result); + } + + @DataProvider(name = "data-for-replace-neg") + public Object[][] getDataForTestReplaceNeg() { + return new Object[][] { + { "DOM", -1, 3, "SAX" }, //offset if neg + { "DOM", 0, -1, "SAX" }, //count is neg + { "DOM", 4, 1, "SAX" } };//offset is greater than length + } + + /* + * Test for replaceData method: verifies that DOMException with + * INDEX_SIZE_ERR is thrown if offset or count is out of the bound. + */ + @Test(dataProvider = "data-for-replace-neg") + public void testReplaceDataNeg(String text, int offset, int count, String arg) throws Exception { + CharacterData cd = createCharacterData(text); + try { + cd.replaceData(offset, count, arg); + fail(DOMEXCEPTION_EXPECTED); + } catch (DOMException e) { + assertEquals(e.code, INDEX_SIZE_ERR); + } + } + + @DataProvider(name = "data-for-insert") + public Object[][] getDataForTestInsert() { + return new Object[][] { + { "DOM", 0, "SAX", "SAXDOM" }, + { "DOM", 3, "SAX", "DOMSAX" } }; + } + + /* + * Verify insertData method works as the spec. + */ + @Test(dataProvider = "data-for-insert") + public void testInsertData(String text, int offset, String arg, String result) throws Exception { + CharacterData cd = createCharacterData(text); + cd.insertData(offset, arg); + assertEquals(cd.getData(), result); + } + + @DataProvider(name = "data-for-insert-neg") + public Object[][] getDataForTestInsertNeg() { + return new Object[][] { + { "DOM", -1 }, //offset is neg + { "DOM", 4 } };//offset is greater than length + } + + /* + * Test for insertData method: verifies that DOMException with + * INDEX_SIZE_ERR is thrown if offset is out of the bound. + */ + @Test(dataProvider = "data-for-insert-neg") + public void testInsertDataNeg(String text, int offset) throws Exception { + CharacterData cd = createCharacterData(text); + try { + cd.insertData(offset, "TEST"); + fail(DOMEXCEPTION_EXPECTED); + } catch (DOMException e) { + assertEquals(e.code, INDEX_SIZE_ERR); + } + } + + @Test + public void testSetData() throws Exception { + CharacterData cd = createCharacterData("DOM"); + cd.setData("SAX"); + assertEquals(cd.getData(), "SAX"); + } + + @DataProvider(name = "data-for-substring") + public Object[][] getDataForTestSubstring() { + return new Object[][] { + { "DOM Level 2", 0, 3, "DOM" }, + { "DOM", 0, 3, "DOM" }, + { "DOM", 2, 5, "M" } }; + } + + /* + * Verify substringData method works as the spec. + */ + @Test(dataProvider = "data-for-substring") + public void testSubstringData(String text, int offset, int count, String result) throws Exception { + CharacterData cd = createCharacterData(text); + String retStr = cd.substringData(offset, count); + assertEquals(retStr, result); + } + + @DataProvider(name = "data-for-substring-neg") + public Object[][] getDataForTestSubstringNeg() { + return new Object[][] { + { "DOM Level 2", -1, 3 }, //offset is neg + { "DOM", 0, -1 }, //count is neg + { "DOM", 3, 1 } }; //offset exceeds length + } + + /* + * Test for substringData method: verifies that DOMException with + * INDEX_SIZE_ERR is thrown if offset or count is out of the bound. + */ + @Test(dataProvider = "data-for-substring-neg") + public void testSubstringDataNeg(String text, int offset, int count) throws Exception { + CharacterData cd = createCharacterData(text); + try { + cd.substringData(offset, count); + fail(DOMEXCEPTION_EXPECTED); + } catch (DOMException e) { + assertEquals(e.code, INDEX_SIZE_ERR); + } + + } + + /* + * Return a concrete CharacterData instance. + */ + abstract protected CharacterData createCharacterData(String text) throws IOException, SAXException, ParserConfigurationException; + +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/AttrTest.java 2015-04-02 20:10:02.916289935 -0700 @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package org.w3c.dom.ptests; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; +import static org.w3c.dom.ptests.DOMTestUtil.createDOM; +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.Test; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; + + +/* + * @summary Test for the Attr Interface + */ +public class AttrTest extends JAXPFileBaseTest { + @Test + public void testGetName() throws Exception { + Document document = createDOM("Attr01.xml"); + //test a new created Attr + Attr attr = document.createAttribute("newAttribute"); + assertEquals(attr.getName(), "newAttribute"); + + //test a Attr loaded from xml file + Element elemNode = (Element) document.getElementsByTagName("book").item(1); + Attr attr2 = (Attr) elemNode.getAttributes().item(0); + assertEquals(attr2.getName(), "category1"); + } + + @Test + public void testGetOwnerElement() throws Exception { + Document document = createDOM("Attr01.xml"); + + //test Attr loaded from xml file + Element elemNode = (Element) document.getElementsByTagName("book").item(1); + NamedNodeMap nnMap = elemNode.getAttributes(); + for (int i = 0; i < nnMap.getLength(); i++) { + Attr attr = (Attr) nnMap.item(i); + assertEquals(attr.getOwnerElement().getNodeName(), "book"); + } + + //test an Attr without owner node + Attr attr = document.createAttribute("newAttribute"); + assertNull(attr.getOwnerElement()); + + } + + @Test + public void testGetSpecified1() throws Exception { + Document document = createDOM("Attr01.xml"); + + Element elemNode = (Element) document.getElementsByTagName("book").item(1); + Attr attr = elemNode.getAttributeNode("category1"); + assertTrue(attr.getSpecified()); + + } + + /* + * In this xml file, the dtd has the value for the attrribute, but the xml + * element does not specify the value for the attrribute, as per the spec it + * should return false. + */ + @Test + public void testGetSpecified2() throws Exception { + + Document document = createDOM("Attr2.xml"); + Element elemNode = (Element) document.getElementsByTagName("Name").item(0); + Attr attr = elemNode.getAttributeNode("type"); + + assertFalse(attr.getSpecified()); + } + + /* + * Creating a new attribute, the owner element is null since the attribute + * has just been created, getSpecified should return true. + */ + @Test + public void testNewCreatedAttribute() throws Exception { + Document document = createDOM("Attr01.xml"); + Attr attr = document.createAttribute("newAttribute"); + assertTrue(attr.getSpecified()); + assertNull(attr.getOwnerElement()); + + } + + /* + * The xml file includes the dtd having the IMPLIED value for the attrribute + * and the xml element does not specify the value. As per the spec it should + * not be seen as a part of the structure model hence getAttributeNode + * rerurn null if the attribute is even found. + */ + @Test + public void testIMPLIEDAttribute() throws Exception { + Document document = createDOM("Attr3.xml"); + Element elemNode = (Element) document.getElementsByTagName("Name").item(0); + Attr attr = elemNode.getAttributeNode("type"); + assertNull(attr); + } + + @Test + public void testSetValue() throws Exception { + Document document = createDOM("Attr01.xml"); + Attr attr = document.createAttribute("newAttribute"); + attr.setValue("newVal"); + assertEquals(attr.getValue(), "newVal"); + + } + +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/CommentTest.java 2015-04-02 20:10:03.185324128 -0700 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static org.w3c.dom.ptests.DOMTestUtil.createNewDocument; + +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.CharacterData; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +/* + * @summary Test for Comment implementation returned by Document.createComment(String) + */ +public class CommentTest extends AbstractCharacterDataTest { + @Override + protected CharacterData createCharacterData(String text) throws IOException, SAXException, ParserConfigurationException { + Document document = createNewDocument(); + return document.createComment(text); + } +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/DocumentTest.java 2015-04-02 20:10:03.455358448 -0700 @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI; +import static javax.xml.XMLConstants.XML_NS_URI; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.fail; +import static org.w3c.dom.DOMException.NAMESPACE_ERR; +import static org.w3c.dom.ptests.DOMTestUtil.DOMEXCEPTION_EXPECTED; +import static org.w3c.dom.ptests.DOMTestUtil.createDOMWithNS; +import static org.w3c.dom.ptests.DOMTestUtil.createNewDocument; +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.w3c.dom.Attr; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/* + * @summary Test createAttributeNS, getElementsByTagNameNS and createElementNS method of Document + */ +public class DocumentTest extends JAXPFileBaseTest { + + @DataProvider(name = "invalid-nsuri") + public Object[][] getInvalidNamespaceURI() { + return new Object[][] { + { " ", "xml:novel" }, //blank + { "hello", "xml:novel" }, //unqualified + { null, "xml:novel" }, //null + { "", "xmlns:novel" } };//empty + } + + /* + * Test for createAttributeNS method: verifies that DOMException is thrown + * if reserved prefixes are used with an arbitrary namespace name. + */ + @Test(dataProvider = "invalid-nsuri", expectedExceptions = DOMException.class) + public void testCreateAttributeNSNeg(String namespaceURI, String name) throws Exception { + Document document = createDOMWithNS("DocumentTest01.xml"); + document.createAttributeNS(namespaceURI, name); + } + + @DataProvider(name = "valid-nsuri") + public Object[][] getValidNamespaceURI() { + return new Object[][] { + { XML_NS_URI, "xml:novel" }, + { XMLNS_ATTRIBUTE_NS_URI, "xmlns:novel" }, + { "urn:BooksAreUs.org:BookInfo", "attributeNew"}, + { "urn:BooksAreUs.org:BookInfonew", "attributeNew"} }; + } + + /* + * Verify the Attr from createAttributeNS. + */ + @Test(dataProvider = "valid-nsuri") + public void testCreateAttributeNS(String namespaceURI, String name) throws Exception { + Document document = createDOMWithNS("DocumentTest01.xml"); + Attr attr = document.createAttributeNS(namespaceURI, name); + assertEquals(attr.getNamespaceURI(), namespaceURI); + assertEquals(attr.getName(), name); + } + + @DataProvider(name = "elementName") + public Object[][] getElementName() { + return new Object[][] { + { "author", 1 }, + { "b:author", 0 } }; + } + + /* + * Verify the NodeList from getElementsByTagNameNS. + */ + @Test(dataProvider = "elementName") + public void testGetElementsByTagNameNS(String localName, int number) throws Exception { + Document document = createDOMWithNS("DocumentTest01.xml"); + NodeList nodeList = document.getElementsByTagNameNS("urn:BooksAreUs.org:BookInfo", localName); + assertEquals(nodeList.getLength(), number); + } + + /* + * Test for createElementNS method: verifies that DOMException is thrown + * if reserved prefixes are used with an arbitrary namespace name. + */ + @Test(dataProvider = "invalid-nsuri") + public void testCreateElementNSNeg(String namespaceURI, String name) throws Exception { + Document document = createDOMWithNS("DocumentTest01.xml"); + try { + document.createElementNS(namespaceURI, name); + fail(DOMEXCEPTION_EXPECTED); + } catch (DOMException e) { + assertEquals(e.code, NAMESPACE_ERR); + } + } + + @Test + public void testCreateElementNS() throws Exception { + Document document = createDOMWithNS("DocumentTest01.xml"); + assertNotNull(document.createElementNS("http://www.books.com", "b:novel")); + } + + /* + * Test createAttributeNS and then append it with setAttributeNode. + */ + @Test + public void testAddNewAttributeNode() throws Exception { + Document document = createDOMWithNS("DocumentTest01.xml"); + + NodeList nodeList = document.getElementsByTagNameNS("http://www.w3.org/TR/REC-html40", "body"); + NodeList childList = nodeList.item(0).getChildNodes(); + Element child = (Element) childList.item(1); + Attr a = document.createAttributeNS("urn:BooksAreUs.org:BookInfo", "attributeNew"); + child.setAttributeNode(a); + assertNotNull(child.getAttributeNodeNS("urn:BooksAreUs.org:BookInfo", "attributeNew")); + } + + /* + * Test createElementNS and then append it with appendChild. + */ + @Test + public void testAddNewElement() throws Exception { + Document document = createDOMWithNS("DocumentTest01.xml"); + + NodeList nodeList = document.getElementsByTagNameNS("http://www.w3.org/TR/REC-html40", "body"); + NodeList childList = nodeList.item(0).getChildNodes(); + Element child = (Element) childList.item(1); + Element elem = document.createElementNS("urn:BooksAreUs.org:BookInfonew", "newElement"); + assertNotNull(child.appendChild(elem)); + } + + /* + * Test createElement with unqualified xml name. + */ + @Test(expectedExceptions = DOMException.class) + public void testCreateElementNeg() throws Exception { + Document doc = createNewDocument(); + doc.createElement("!nc$%^*(!"); + } +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/DocumentTypeTest.java 2015-04-02 20:10:03.725392768 -0700 @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package org.w3c.dom.ptests; + +import static org.testng.Assert.assertEquals; +import static org.w3c.dom.ptests.DOMTestUtil.createDOM; +import jaxp.library.JAXPFileBaseTest; + +import org.testng.Assert; +import org.testng.annotations.Test; +import org.w3c.dom.DocumentType; +import org.w3c.dom.NamedNodeMap; + +/* + * @summary Test DocumentType + */ +public class DocumentTypeTest extends JAXPFileBaseTest { + + /* + * Test testGetEntities method, and verify the entity items. + */ + @Test + public void testGetEntities() throws Exception { + DocumentType documentType = createDOM("DocumentType01.xml").getDoctype(); + NamedNodeMap namedNodeMap = documentType.getEntities(); + // should return both external and internal. Parameter entities are not + // contained. Duplicates are discarded. + assertEquals(namedNodeMap.getLength(), 3); + assertEquals(namedNodeMap.item(0).getNodeName(), "author"); + assertEquals(namedNodeMap.item(1).getNodeName(), "test"); + assertEquals(namedNodeMap.item(2).getNodeName(), "writer"); + } + + /* + * Test getNotations method, and verify the notation items. + */ + @Test + public void testGetNotations() throws Exception { + DocumentType documentType = createDOM("DocumentType03.xml").getDoctype(); + NamedNodeMap nm = documentType.getNotations(); + assertEquals(nm.getLength(), 2); // should return 2 because the notation + // name is repeated and + // it considers only the first + // occurence + assertEquals(nm.item(0).getNodeName(), "gs"); + assertEquals(nm.item(1).getNodeName(), "name"); + } + + @Test + public void testGetName() throws Exception { + DocumentType documentType = createDOM("DocumentType03.xml").getDoctype(); + assertEquals(documentType.getName(), "note"); + } + + /* + * Test getSystemId and getPublicId method. + */ + @Test + public void testGetSystemId() throws Exception { + DocumentType documentType = createDOM("DocumentType05.xml").getDoctype(); + assertEquals(documentType.getSystemId(), "DocumentBuilderImpl02.dtd"); + Assert.assertNull(documentType.getPublicId()); + } + +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/DomImplementationTest.java 2015-04-02 20:10:03.999427597 -0700 @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static org.testng.Assert.assertEquals; +import static org.w3c.dom.ptests.DOMTestUtil.createNewDocument; + +import javax.xml.parsers.ParserConfigurationException; + +import jaxp.library.JAXPBaseTest; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentType; + +/* + * @summary Test DomImplementation API + */ +public class DomImplementationTest extends JAXPBaseTest { + /* + * Test createDocument method with a namespace uri, qualified name and null + * for the doctype + */ + @Test + public void testCreateDocument() throws ParserConfigurationException { + final String nsURI = "http://www.document.com"; + final String name = "document:localName"; + DOMImplementation domImpl = getDOMImplementation(); + Document document = domImpl.createDocument(nsURI, name, null); + assertEquals(document.getDocumentElement().getNamespaceURI(), nsURI); + assertEquals(document.getDocumentElement().getNodeName(), name); + } + + /* + * Test createDocumentType method with name, public id and system id. + */ + @Test + public void testCreateDocumentType01() throws ParserConfigurationException { + final String name = "document:localName"; + final String publicId = "pubid"; + final String systemId = "sysid"; + + DOMImplementation domImpl = getDOMImplementation(); + DocumentType documentType = domImpl.createDocumentType(name, publicId, systemId); + verifyDocumentType(documentType, name, publicId, systemId); + } + + + /* + * Test createDocument method using a DocumentType, verify the document will + * take that Doctype. + */ + @Test + public void testCreateDocumentType02() throws ParserConfigurationException { + final String name = "document:localName"; + final String publicId = "-//W3C//DTD HTML 4.0 Transitional//EN"; + final String systemId = "http://www.w3.org/TR/REC-html40/loose.dtd"; + DOMImplementation domImpl = getDOMImplementation(); + + DocumentType documentType = domImpl.createDocumentType(name, publicId, systemId); + Document document = domImpl.createDocument("http://www.document.com", "document:localName", documentType); + verifyDocumentType(document.getDoctype(), name, publicId, systemId); + } + + @DataProvider(name = "feature-supported") + public Object[][] getFeatureSupportedList() throws ParserConfigurationException { + DOMImplementation impl = getDOMImplementation(); + return new Object[][] { + { impl, "XML", "2.0", true }, + { impl, "HTML", "2.0", false }, + { impl, "Views", "2.0", false }, + { impl, "StyleSheets", "2.0", false }, + { impl, "CSS", "2.0", false }, + { impl, "CSS2", "2.0", false }, + { impl, "Events", "2.0", true }, + { impl, "UIEvents", "2.0", false }, + { impl, "MouseEvents", "2.0", false }, + { impl, "HTMLEvents", "2.0", false }, + { impl, "Traversal", "2.0", true }, + { impl, "Range", "2.0", true }, + { impl, "Core", "2.0", true }, + { impl, "XML", "", true } }; + } + + + @Test(dataProvider = "feature-supported") + public void testHasFeature(DOMImplementation impl, String feature, String version, boolean isSupported) { + assertEquals(impl.hasFeature(feature,version), isSupported); + } + + + private DOMImplementation getDOMImplementation() throws ParserConfigurationException { + return createNewDocument().getImplementation(); + } + + + private void verifyDocumentType(DocumentType documentType, String name, String publicId, String systemId) { + assertEquals(documentType.getPublicId(), publicId); + assertEquals(documentType.getSystemId(), systemId); + assertEquals(documentType.getName(), name); + } +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/ElementTest.java 2015-04-02 20:10:04.270462044 -0700 @@ -0,0 +1,253 @@ +/* + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static javax.xml.XMLConstants.XML_NS_URI; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; +import static org.w3c.dom.DOMException.INUSE_ATTRIBUTE_ERR; +import static org.w3c.dom.ptests.DOMTestUtil.DOMEXCEPTION_EXPECTED; +import static org.w3c.dom.ptests.DOMTestUtil.createDOM; +import static org.w3c.dom.ptests.DOMTestUtil.createDOMWithNS; +import static org.w3c.dom.ptests.DOMTestUtil.createNewDocument; + +import java.io.StringReader; + +import javax.xml.parsers.DocumentBuilderFactory; + +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.w3c.dom.Attr; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +/* + * @summary Test for the methods of Element Interface + */ +public class ElementTest extends JAXPFileBaseTest { + @Test + public void testGetAttributeNS() throws Exception { + Document document = createDOMWithNS("ElementSample01.xml"); + Element elemNode = (Element) document.getElementsByTagName("book").item(0); + String s = elemNode.getAttributeNS("urn:BooksAreUs.org:BookInfo", "category"); + assertEquals(s, "research"); + } + + @Test + public void testGetAttributeNodeNS() throws Exception { + Document document = createDOMWithNS("ElementSample01.xml"); + Element elemNode = (Element) document.getElementsByTagName("book").item(0); + Attr attr = elemNode.getAttributeNodeNS("urn:BooksAreUs.org:BookInfo", "category"); + assertEquals(attr.getValue(), "research"); + + } + + /* + * Test getAttributeNode to get a Attr and then remove it successfully by + * removeAttributeNode. + */ + @Test + public void testRemoveAttributeNode() throws Exception { + Document document = createDOMWithNS("ElementSample01.xml"); + Element elemNode = (Element) document.getElementsByTagName("book").item(1); + Attr attr = elemNode.getAttributeNode("category1"); + assertEquals(attr.getValue(), "research"); + + assertEquals(elemNode.getTagName(), "book"); + elemNode.removeAttributeNode(attr); + assertEquals(elemNode.getAttribute("category1"), ""); + } + + /* + * Test removing an Attribute Node with removeAttributeNS(String + * namespaceURI, String localName). + */ + @Test + public void testRemoveAttributeNS() throws Exception { + final String nsURI = "urn:BooksAreUs.org:BookInfo"; + final String localName = "category"; + Document document = createDOMWithNS("ElementSample01.xml"); + Element elemNode = (Element) document.getElementsByTagName("book").item(0); + elemNode.removeAttributeNS(nsURI, localName); + + assertNull(elemNode.getAttributeNodeNS(nsURI, localName)); + } + + /* + * Test getFirstChild and getLastChild. + */ + @Test + public void testGetChild() throws Exception { + Document document = createDOMWithNS("ElementSample01.xml"); + Element elemNode = (Element) document.getElementsByTagName("b:aaa").item(0); + elemNode.normalize(); + Node firstChild = elemNode.getFirstChild(); + Node lastChild = elemNode.getLastChild(); + assertEquals(firstChild.getNodeValue(), "fjfjf"); + assertEquals(lastChild.getNodeValue(), "fjfjf"); + } + + /* + * Test setAttributeNode with an Attr from createAttribute. + */ + @Test + public void testSetAttributeNode() throws Exception { + final String attrName = "myAttr"; + final String attrValue = "attrValue"; + Document document = createDOM("ElementSample02.xml"); + Element elemNode = document.createElement("pricetag2"); + Attr myAttr = document.createAttribute(attrName); + myAttr.setValue(attrValue); + + assertNull(elemNode.setAttributeNode(myAttr)); + assertEquals(elemNode.getAttribute(attrName), attrValue); + } + + @DataProvider(name = "attribute") + public Object[][] getAttributeData() { + return new Object[][] { + { "thisisname", "thisisitsvalue" }, + { "style", "font-Family" } }; + } + + @Test(dataProvider = "attribute") + public void testSetAttribute(String name, String value) throws Exception { + Document document = createDOM("ElementSample02.xml"); + Element elemNode = document.createElement("pricetag2"); + elemNode.setAttribute(name, value); + assertEquals(elemNode.getAttribute(name), value); + } + + /* + * Negative test for setAttribute, null is not a valid name. + */ + @Test(expectedExceptions = DOMException.class) + public void testSetAttributeNeg() throws Exception { + Document document = createDOM("ElementSample02.xml"); + Element elemNode = document.createElement("pricetag2"); + elemNode.setAttribute(null, null); + } + + /* + * Test setAttributeNode, newAttr can't be an attribute of another Element + * object, must explicitly clone Attr nodes to re-use them in other + * elements. + */ + @Test + public void testDuplicateAttributeNode() throws Exception { + final String name = "testAttrName"; + final String value = "testAttrValue"; + Document document = createNewDocument(); + Attr attr = document.createAttribute(name); + attr.setValue(value); + + Element element1 = document.createElement("AFirstElement"); + element1.setAttributeNode(attr); + Element element2 = document.createElement("ASecondElement"); + Attr attr2 = (Attr) attr.cloneNode(true); + element2.setAttributeNode(attr2); + assertEquals(element1.getAttribute(name), element2.getAttribute(name)); + + Element element3 = document.createElement("AThirdElement"); + try { + element3.setAttributeNode(attr); + fail(DOMEXCEPTION_EXPECTED); + } catch (DOMException doe) { + assertEquals(doe.code, INUSE_ATTRIBUTE_ERR); + } + } + + /* + * If not setting the namsepace aware method of DocumentBuilderFactory to + * true, can't retrieve element by namespace and local name. + */ + @Test + public void testNamespaceAware() throws Exception { + Document document = createDOM("ElementSample02.xml"); + + NodeList nl = document.getElementsByTagNameNS("urn:BooksAreUs.org:BookInfo", "author"); + assertNull(nl.item(0)); + + nl = document.getDocumentElement().getElementsByTagNameNS("urn:BooksAreUs.org:BookInfo", "author"); + assertNull(nl.item(0)); + } + + @DataProvider(name = "nsattribute") + public Object[][] getNSAttributeData() { + return new Object[][] { + { "h:html", "html", "attrValue" }, + { "b:style", "style", "attrValue" } }; + } + + /* + * setAttributeNodeNS and verify it with getAttributeNS. + */ + @Test(dataProvider = "nsattribute") + public void testSetAttributeNodeNS(String qualifiedName, String localName, String value) throws Exception { + Document document = createDOM("ElementSample03.xml"); + Element elemNode = document.createElement("pricetag2"); + Attr myAttr = document.createAttributeNS(XML_NS_URI, qualifiedName); + myAttr.setValue(value); + assertNull(elemNode.setAttributeNodeNS(myAttr)); + assertEquals(elemNode.getAttributeNS(XML_NS_URI, localName), value); + } + + @Test + public void testHasAttributeNS() throws Exception { + Document document = createDOMWithNS("ElementSample04.xml"); + NodeList nodeList = document.getElementsByTagName("body"); + NodeList childList = nodeList.item(0).getChildNodes(); + Element child = (Element) childList.item(7); + assertTrue(child.hasAttributeNS("urn:BooksAreUs.org:BookInfo", "style")); + } + + @Test + public void testToString() throws Exception { + final String xml = + "" + + "" + + "" + + " \n" + + " " + + " " + + ""; + + Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xml))); + Element root = doc.getDocumentElement(); + + assertEquals(root.toString(), "[datacenterlist: null]"); + } + +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/EntityChildTest.java 2015-04-02 20:10:04.539496237 -0700 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static org.testng.Assert.assertEquals; +import static org.w3c.dom.ptests.DOMTestUtil.XML_DIR; + +import java.io.File; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/* + * @summary Test DOM Parser: parsing an xml file that contains external entities. + */ +public class EntityChildTest extends JAXPFileBaseTest { + + @Test + public void test() throws Exception { + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setValidating(true); + DocumentBuilder docBuilder = dbf.newDocumentBuilder(); + Document document = docBuilder.parse(new File(XML_DIR + "entitychild.xml")); + + Element root = document.getDocumentElement(); + NodeList n = root.getElementsByTagName("table"); + NodeList nl = n.item(0).getChildNodes(); + assertEquals(n.getLength(), 1); + assertEquals(nl.getLength(), 3); + } +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/NamedNodeMapTest.java 2015-04-02 20:10:04.809530557 -0700 @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.w3c.dom.ptests.DOMTestUtil.createDOMWithNS; +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.Test; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/* + * @summary Test for the methods of NamedNodeMap Interface + */ +public class NamedNodeMapTest extends JAXPFileBaseTest { + /* + * Test setNamedItemNS method with a node having the same namespaceURI and + * qualified name as an existing one, and then test with a non-existing node. + */ + @Test + public void testSetNamedItemNS() throws Exception { + final String nsURI = "urn:BooksAreUs.org:BookInfo"; + Document document = createDOMWithNS("NamedNodeMap01.xml"); + NodeList nodeList = document.getElementsByTagName("body"); + nodeList = nodeList.item(0).getChildNodes(); + Node n = nodeList.item(3); + + NamedNodeMap namedNodeMap = n.getAttributes(); + + // creating an Attribute using createAttributeNS + // method having the same namespaceURI + // and the same qualified name as the existing one in the xml file + Attr attr = document.createAttributeNS(nsURI, "b:style"); + // setting to a new Value + attr.setValue("newValue"); + Node replacedAttr = namedNodeMap.setNamedItemNS(attr); // return the replaced attr + assertEquals(replacedAttr.getNodeValue(), "font-family"); + Node updatedAttr = namedNodeMap.getNamedItemNS(nsURI, "style"); + assertEquals(updatedAttr.getNodeValue(), "newValue"); + + + // creating a non existing attribute node + attr = document.createAttributeNS(nsURI, "b:newNode"); + attr.setValue("newValue"); + + assertNull(namedNodeMap.setNamedItemNS(attr)); // return null + + // checking if the node could be accessed + // using the getNamedItemNS method + Node newAttr = namedNodeMap.getNamedItemNS(nsURI, "newNode"); + assertEquals(newAttr.getNodeValue(), "newValue"); + } + + /* + * Verify getNamedItemNS works as the spec + */ + @Test + public void testGetNamedItemNS() throws Exception { + Document document = createDOMWithNS("NamedNodeMap03.xml"); + NodeList nodeList = document.getElementsByTagName("body"); + nodeList = nodeList.item(0).getChildNodes(); + Node n = nodeList.item(7); + NamedNodeMap namedNodeMap = n.getAttributes(); + Node node = namedNodeMap.getNamedItemNS("urn:BooksAreUs.org:BookInfo", "aaa"); + assertEquals(node.getNodeValue(), "value"); + + } + + /* + * Test setNamedItem method with a node having the same name as an existing + * one, and then test with a non-existing node. + */ + @Test + public void testSetNamedItem() throws Exception { + Document document = createDOMWithNS("NamedNodeMap03.xml"); + NodeList nodeList = document.getElementsByTagName("body"); + nodeList = nodeList.item(0).getChildNodes(); + Node n = nodeList.item(1); + + NamedNodeMap namedNodeMap = n.getAttributes(); + Attr attr = document.createAttribute("name"); + Node replacedAttr = namedNodeMap.setNamedItem(attr); + assertEquals(replacedAttr.getNodeValue(), "attributeValue"); + Node updatedAttrNode = namedNodeMap.getNamedItem("name"); + assertEquals(updatedAttrNode.getNodeValue(), ""); + + Attr newAttr = document.createAttribute("nonExistingName"); + assertNull(namedNodeMap.setNamedItem(newAttr)); + Node newAttrNode = namedNodeMap.getNamedItem("nonExistingName"); + assertEquals(newAttrNode.getNodeValue(), ""); + } + +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/NodeListTest.java 2015-04-02 20:10:05.080565004 -0700 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static org.testng.Assert.assertEquals; +import static org.w3c.dom.ptests.DOMTestUtil.createDOM; +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/* + * @summary Verifies a bug found in jaxp1.0.1 and 1.1FCS. After going out of + * bound, the last element of a NodeList returns null. The bug has been fixed + * in jaxp 1.1.1 build. + */ +public class NodeListTest extends JAXPFileBaseTest { + + @DataProvider(name = "xml") + public Object[][] getTestData() { + return new Object[][] { { "nodelist.xml", "document" }, { "Node01.xml", "body" } }; + } + + @Test(dataProvider = "xml") + public void lastItemTest(String xmlFileName, String nodeName) throws Exception { + Document document = createDOM(xmlFileName); + + NodeList nl = document.getElementsByTagName(nodeName); + int n = nl.getLength(); + + Element elem1 = (Element) nl.item(n - 1); + nl.item(n); + Element elem3 = (Element) nl.item(n - 1); + assertEquals(elem3, elem1); + + } + +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/NodeTest.java 2015-04-02 20:10:05.347598942 -0700 @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static java.io.File.separator; +import static jaxp.library.JAXPTestUtilities.USER_DIR; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertTrue; +import static org.w3c.dom.ptests.DOMTestUtil.GOLDEN_DIR; +import static org.w3c.dom.ptests.DOMTestUtil.createDOM; +import static org.w3c.dom.ptests.DOMTestUtil.createDOMWithNS; +import static org.w3c.dom.ptests.DOMTestUtil.createNewDocument; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentFragment; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/* + * @summary Test Node interface + */ +public class NodeTest extends JAXPFileBaseTest { + @BeforeClass + public void setup() throws Exception { + Files.createDirectories(Paths.get(USER_DIR + "dom")); + + } + + @DataProvider(name = "feature-supported") + public Object[][] getFeatureSupportedList() throws Exception { + Document document = createDOMWithNS("Node01.xml"); + Node node = document.getElementsByTagName("body").item(0); + return new Object[][] { + { node, "XML", "2.0", true }, + { node, "HTML", "2.0", false }, + { node, "Views", "2.0", false }, + { node, "StyleSheets", "2.0", false }, + { node, "CSS", "2.0", false }, + { node, "CSS2", "2.0", false }, + { node, "Events", "2.0", true }, + { node, "UIEvents", "2.0", false }, + { node, "MouseEvents", "2.0", false }, + { node, "HTMLEvents", "2.0", false }, + { node, "Traversal", "2.0", true }, + { node, "Range", "2.0", true } }; + } + + @Test(dataProvider = "feature-supported") + public void testHasFeature(Node node, String feature, String version, boolean supported) { + assertEquals(node.isSupported(feature, version), supported); + } + + /* + * Test normalize method will merge adjacent Text nodes. + */ + @Test + public void testNormalize() throws Exception { + Document document = createDOM("Node05.xml"); + + Element root = document.getDocumentElement(); + + Node node = document.getElementsByTagName("title").item(0); + node.appendChild(document.createTextNode("test")); + root.normalize(); + assertEquals(node.getChildNodes().item(0).getNodeValue(), "Typographytest"); + } + + /* + * Test cloneNode deeply, and the clone node can be appended on the same document. + */ + @Test + public void testCloneNode() throws Exception { + Document document = createDOMWithNS("Node02.xml"); + + NodeList nodeList = document.getElementsByTagName("body"); + Node node = nodeList.item(0); + Node cloneNode = node.cloneNode(true); + + assertTrue(node.isEqualNode(cloneNode)); + assertNotEquals(node, cloneNode); + + nodeList = document.getElementsByTagName("html"); + Node node2 = nodeList.item(0); + node2.appendChild(cloneNode); + } + + /* + * Test importing node from one document to another. + */ + @Test + public void testImportNode() throws Exception { + Document document = createDOMWithNS("Node02.xml"); + Document otherDocument = createDOMWithNS("ElementSample01.xml"); + + NodeList otherNodeList = otherDocument.getElementsByTagName("body"); + Node importedNode = otherNodeList.item(0); + Node clone = importedNode.cloneNode(true); + + Node retNode = document.importNode(importedNode, true); + assertTrue(clone.isEqualNode(importedNode)); //verify importedNode is not changed + assertNotEquals(retNode, importedNode); + assertTrue(importedNode.isEqualNode(retNode)); + + retNode = document.importNode(importedNode, false); + assertTrue(clone.isEqualNode(importedNode)); //verify importedNode is not changed + assertEquals(retNode.getNodeName(), importedNode.getNodeName()); + assertFalse(importedNode.isEqualNode(retNode)); + } + + /* + * Test inserting a document fragment before a particular node. + */ + @Test + public void testInsertBefore() throws Exception { + Document document = createDOM("Node04.xml"); + + Element parentElement = (Element) document.getElementsByTagName("to").item(0); + Element element = (Element) document.getElementsByTagName("sender").item(0); + parentElement.insertBefore(createTestDocumentFragment(document), element); + + String outputfile = USER_DIR + "dom" + separator + "InsertBefore.out"; + String goldfile = GOLDEN_DIR + "InsertBeforeGF.out"; + outputXml(document, outputfile); + assertTrue(compareWithGold(goldfile, outputfile)); + } + + + /* + * Test replacing a particular node with a document fragment. + */ + @Test + public void testReplaceChild() throws Exception { + Document document = createDOM("Node04.xml"); + + Element parentElement = (Element) document.getElementsByTagName("to").item(0); + Element element = (Element) document.getElementsByTagName("sender").item(0); + parentElement.replaceChild(createTestDocumentFragment(document), element); + + String outputfile = USER_DIR + "dom" + separator + "ReplaceChild3.out"; + String goldfile = GOLDEN_DIR + "ReplaceChild3GF.out"; + outputXml(document, outputfile); + assertTrue(compareWithGold(goldfile, outputfile)); + } + + /* + * This test case checks for the replaceChild replacing a particular node + * with a node which was created from a different document than the one + * which is trying to use this method. It should throw a DOMException. + */ + @Test(expectedExceptions = DOMException.class) + public void testReplaceChildNeg() throws Exception { + Document document = createDOM("Node04.xml"); + Document doc2 = createNewDocument(); + + Element parentElement = (Element) document.getElementsByTagName("to").item(0); + Element element = (Element) document.getElementsByTagName("sender").item(0); + parentElement.replaceChild(createTestDocumentFragment(doc2), element); + } + + private DocumentFragment createTestDocumentFragment(Document document) { + DocumentFragment docFragment = document.createDocumentFragment(); + Element elem = document.createElement("dfElement"); + elem.appendChild(document.createTextNode("Text in it")); + docFragment.appendChild(elem); + return docFragment; + } + + private void outputXml(Document document, String outputFileName) throws TransformerFactoryConfigurationError, TransformerException { + DOMSource domSource = new DOMSource(document); + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + StreamResult streamResult = new StreamResult(new File(outputFileName)); + transformer.transform(domSource, streamResult); + } +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/NotationTest.java 2015-04-02 20:10:05.615633008 -0700 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static org.testng.Assert.assertEquals; +import static org.w3c.dom.ptests.DOMTestUtil.createDOM; + +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; + +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Notation; +import org.xml.sax.SAXException; + +/* + * @summary Test for Notation interface + */ +public class NotationTest extends JAXPFileBaseTest { + + @Test + public void testGetSystemId() throws Exception { + assertEquals(findNotation("gs").getSystemId(), "http://who.knows.where/"); + } + + @Test + public void testGetPublicId() throws Exception { + assertEquals(findNotation("pubname").getPublicId(), "pubId"); + } + + //find notation in Notation01.xml + private Notation findNotation(String name) throws SAXException, IOException, ParserConfigurationException { + Document document = createDOM("Notation01.xml"); + NamedNodeMap nm = document.getDoctype().getNotations(); + for (int i = 0; i < nm.getLength(); i++) { + if (nm.item(i).getNodeName().equals(name)) { + return (Notation) nm.item(i); + } + } + throw new RuntimeException("Notation: '" + name + "' not found."); + } + +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/PITest.java 2015-04-02 20:10:05.901669362 -0700 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static org.testng.Assert.assertEquals; +import static org.w3c.dom.ptests.DOMTestUtil.createDOMWithNS; +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.w3c.dom.ProcessingInstruction; + +/* + * @summary Test for the methods of Processing Instruction + */ +public class PITest extends JAXPFileBaseTest { + /* + * Test getData, setData and getTarget methods + */ + @Test + public void test() throws Exception { + Document document = createDOMWithNS("PITest01.xml"); + ProcessingInstruction pi = document.createProcessingInstruction("PI", "processing"); + assertEquals(pi.getData(), "processing"); + assertEquals(pi.getTarget(), "PI"); + + pi.setData("newProcessing"); + assertEquals(pi.getData(), "newProcessing"); + } + +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/TextTest.java 2015-04-02 20:10:06.165702919 -0700 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static org.testng.Assert.assertEquals; +import static org.w3c.dom.ptests.DOMTestUtil.createDOMWithNS; +import static org.w3c.dom.ptests.DOMTestUtil.createNewDocument; + +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; + +import org.testng.annotations.Test; +import org.w3c.dom.CharacterData; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; +import org.xml.sax.SAXException; + +/* + * @summary Test for Text implementation returned by Document.createTextNode(String) + */ +public class TextTest extends AbstractCharacterDataTest { + /* + * Verify splitText method works as the spec. + */ + @Test + public void testSplitText() throws Exception { + Document document = createDOMWithNS("Text01.xml"); + + NodeList nodeList = document.getElementsByTagName("p"); + Node node = nodeList.item(0); + Text textNode = document.createTextNode("This is a text node"); + node.appendChild(textNode); + int rawChildNum = node.getChildNodes().getLength(); + + textNode.splitText(0); + int increased = node.getChildNodes().getLength() - rawChildNum; + assertEquals(increased, 1); + + } + + @Override + protected CharacterData createCharacterData(String text) throws IOException, SAXException, ParserConfigurationException { + Document document = createNewDocument(); + return document.createTextNode(text); + } + +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/TypeInfoTest.java 2015-04-02 20:10:06.428736349 -0700 @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; +import static org.testng.Assert.assertEquals; + +import java.io.StringReader; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import jaxp.library.JAXPBaseTest; + +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.TypeInfo; +import org.xml.sax.InputSource; + +/* + * @summary Test getTypeName and getTypeNamespace methods of TypeInfo interface + */ +public class TypeInfoTest extends JAXPBaseTest { + /* + * Get the TypeInfo of the root element, and verify it. + */ + @Test + public void test() throws Exception { + TypeInfo typeInfo = getTypeOfRoot(SCHEMA_INSTANCE, "\n" + "\n"); + + assertEquals(typeInfo.getTypeName(), "Test"); + assertEquals(typeInfo.getTypeNamespace(), "testNS"); + + } + + private TypeInfo getTypeOfRoot(String schemaText, String docText) throws Exception { + Element root = getRoot(schemaText, docText); + return root.getSchemaTypeInfo(); + } + + private Element getRoot(String schemaText, String docText) throws Exception { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + InputSource inSchema = new InputSource(new StringReader(schemaText)); + inSchema.setSystemId("schema.xsd"); + dbf.setNamespaceAware(true); + dbf.setValidating(true); + dbf.setAttribute(SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); + dbf.setAttribute(SCHEMA_SOURCE, inSchema); + + DocumentBuilder parser = dbf.newDocumentBuilder(); + + InputSource inSource = new InputSource(new StringReader(docText)); + inSource.setSystemId("doc.xml"); + Document document = parser.parse(inSource); + + return document.getDocumentElement(); + } + + private static final String SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; + + private static final String SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; + + /* + * Schema instance + */ + private static final String SCHEMA_INSTANCE = + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + "\n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + "\n"; + + +} --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/Attr01.xml 2015-04-02 20:10:06.690769652 -0700 @@ -0,0 +1,18 @@ + + + + Typography + + + +

Welcome to the world of typography! Here is a book that you may find useful.

+ Digital Typography + Donald Knuth + fjfjf + + Numerical Analysis of Partial Differential Equations + Numerical Analysis of Partial Differential Equations + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/Attr2.xml 2015-04-02 20:10:06.963804354 -0700 @@ -0,0 +1,11 @@ + + + + +]> + + + World's best book + \ No newline at end of file --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/Attr3.xml 2015-04-02 20:10:07.232838547 -0700 @@ -0,0 +1,10 @@ + + + +]> + + + World's best book + \ No newline at end of file --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/Comment01.xml 2015-04-02 20:10:07.496872104 -0700 @@ -0,0 +1,15 @@ + + + + Typography + + + +

+ Digital Typography + Donald Knuth + fjfjf + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/DocumentBuilderImpl02.dtd 2015-04-02 20:10:07.763906043 -0700 @@ -0,0 +1,12 @@ + + + + + + + + + + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/DocumentTest01.xml 2015-04-02 20:10:08.043941634 -0700 @@ -0,0 +1,12 @@ + + + + Typography + + + Welcome to the world of typography! Here is a book that you may find useful. + Digital Typography + Donald Knuth + + \ No newline at end of file --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/DocumentType01.xml 2015-04-02 20:10:08.310975572 -0700 @@ -0,0 +1,14 @@ + + + + + + + + +]> + +&writer; + + \ No newline at end of file --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/DocumentType03.xml 2015-04-02 20:10:08.581009892 -0700 @@ -0,0 +1,19 @@ + + + + + + + + + + + + + +]> + +lll + + \ No newline at end of file --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/DocumentType05.dtd 2015-04-02 20:10:08.852044339 -0700 @@ -0,0 +1,12 @@ + + + + + + + + + + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/DocumentType05.xml 2015-04-02 20:10:09.120078405 -0700 @@ -0,0 +1,28 @@ + + + + + Publishers of the Music of New York Women Composers + + The Publishers + + + Alfred Publishing + &w; + 15535 Morrison + South Oaks CA 91403 + + + + eXtensible Markup Language + + + + + + Publishers are not noted in report by time. + + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/ElementSample01.xml 2015-04-02 20:10:09.387112344 -0700 @@ -0,0 +1,18 @@ + + + + Typography + + + +

Welcome to the world of typography! Here is a book that you may find useful.

+ Digital Typography + Donald Knuth + fjfjf + + Numerical Analysis of Partial Differential Equations + Numerical Analysis of Partial Differential Equations + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/ElementSample02.xml 2015-04-02 20:10:09.651145901 -0700 @@ -0,0 +1,15 @@ + + + + Typography + + + +

Welcome to the world of typography! Here is a book that you may find useful.

+ Digital Typography + Donald Knuth + fjfjf + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/ElementSample03.xml 2015-04-02 20:10:09.918179840 -0700 @@ -0,0 +1,15 @@ + + + + Typography + + + +

Welcome to the world of typography! Here is a book that you may find useful.

+ Digital Typography + Donald Knuth + fjfjf + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/ElementSample04.xml 2015-04-02 20:10:10.190214414 -0700 @@ -0,0 +1,15 @@ + + + + Typography + + + +

Welcome to the world of typography! Here is a book that you may find useful.

+ Digital Typography + Donald Knuth + this is it + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/NamedNodeMap01.xml 2015-04-02 20:10:10.462248988 -0700 @@ -0,0 +1,15 @@ + + + + Typography + + + +

Welcome to the world of typography! Here is a book that you may find useful.

+ Digital Typography + Donald Knuth + fjfjf + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/NamedNodeMap03.xml 2015-04-02 20:10:10.731283181 -0700 @@ -0,0 +1,15 @@ + + + + Typography + + + +

Welcome to the world of typography! Here is a book that you may find useful.

+ Digital Typography + Donald Knuth + fjfjf + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/Node01.xml 2015-04-02 20:10:11.007318264 -0700 @@ -0,0 +1,15 @@ + + + + Typography + + + +

Welcome to the world of typography! Here is a book that you may find useful.

+ Digital Typography + Donald Knuth + fjfjf + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/Node02.xml 2015-04-02 20:10:11.369364278 -0700 @@ -0,0 +1,15 @@ + + + + Typography + + + +

Welcome to the world of typography! Here is a book that you may find useful.

+ Digital Typography + Donald Knuth + fjfjf + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/Node04.xml 2015-04-02 20:10:11.717408512 -0700 @@ -0,0 +1,8 @@ + + + +John + +message + weekend! + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/Node05.xml 2015-04-02 20:10:12.067453001 -0700 @@ -0,0 +1,6 @@ + + + + Typography + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/Notation01.xml 2015-04-02 20:10:12.418497617 -0700 @@ -0,0 +1,19 @@ + + + + + + + + + + + + + +]> + +lll + + \ No newline at end of file --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/PITest01.xml 2015-04-02 20:10:12.686531683 -0700 @@ -0,0 +1,15 @@ + + + + Typography + + + +

Welcome to the world of typography! Here is a book that you may find useful.

+ Digital Typography + Donald Knuth + fjfjf + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/Text01.xml 2015-04-02 20:10:12.962566766 -0700 @@ -0,0 +1,15 @@ + + + + Typography + + + +

+ Digital Typography + Donald Knuth + fjfjf + + + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/ee.xml 2015-04-02 20:10:13.231600958 -0700 @@ -0,0 +1,7 @@ + + + + +&mkm; + +
--- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/entitychild.xml 2015-04-02 20:10:13.498634897 -0700 @@ -0,0 +1,15 @@ + + + + + + + + + +]> + +
+ⅇ +
--- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/nodelist.xml 2015-04-02 20:10:13.769669344 -0700 @@ -0,0 +1,2 @@ + +onenode --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/out/InsertBeforeGF.out 2015-04-02 20:10:14.040703791 -0700 @@ -0,0 +1,7 @@ + + +Text in itJohn + +message + weekend! + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/functional/org/w3c/dom/xmlfiles/out/ReplaceChild3GF.out 2015-04-02 20:10:14.308737857 -0700 @@ -0,0 +1,7 @@ + + +Text in it + +message + weekend! + --- /dev/null 2015-04-03 02:12:31.250416598 -0700 +++ new/test/javax/xml/jaxp/libs/org/w3c/dom/ptests/DOMTestUtil.java 2015-04-02 20:10:14.575771796 -0700 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.w3c.dom.ptests; + +import static jaxp.library.JAXPTestUtilities.FILE_SEP; +import static jaxp.library.JAXPTestUtilities.getPathByClassName; + +import java.io.File; +import java.io.IOException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +/* + * This class defines the path constant and common method + */ +public class DOMTestUtil { + /* + * XML source file directory. + */ + public static final String XML_DIR = getPathByClassName(DOMTestUtil.class, ".." + FILE_SEP + "xmlfiles"); + + /* + * Golden validation files directory. + */ + public static final String GOLDEN_DIR = getPathByClassName(DOMTestUtil.class, ".." + FILE_SEP + "xmlfiles" + FILE_SEP + "out"); + + /* + * Error Message for DOMException being expected. + */ + public static final String DOMEXCEPTION_EXPECTED = "Should throw DOMException"; + + /* + * Create DOM Document from an xml file. + */ + public static Document createDOM(String xmlFileName) throws SAXException, IOException, ParserConfigurationException { + return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(XML_DIR + xmlFileName)); + } + + /* + * Create DOM Document from an xml file with setNamespaceAware(true). + */ + public static Document createDOMWithNS(String xmlFileName) throws IOException, SAXException, ParserConfigurationException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + return dbf.newDocumentBuilder().parse(new File(XML_DIR + xmlFileName)); + } + + /* + * Create a new DOM Document. + */ + public static Document createNewDocument() throws ParserConfigurationException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + return db.newDocument(); + } +}