1 /* 2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.w3c.dom.ptests; 24 25 import static org.testng.Assert.assertEquals; 26 import static org.w3c.dom.ptests.DOMTestUtil.createNewDocument; 27 28 import javax.xml.parsers.ParserConfigurationException; 29 30 import jaxp.library.JAXPBaseTest; 31 32 import org.testng.annotations.DataProvider; 33 import org.testng.annotations.Test; 34 import org.w3c.dom.DOMImplementation; 35 import org.w3c.dom.Document; 36 import org.w3c.dom.DocumentType; 37 38 /* 39 * @summary Test DomImplementation API 40 */ 41 public class DomImplementationTest extends JAXPBaseTest { 42 @Test 43 public void testCreateDocument() throws ParserConfigurationException { 44 final String nsURI = "http://www.document.com"; 45 final String name = "document:localName"; 46 DOMImplementation domImpl = getDOMImplementation(); 47 Document document = domImpl.createDocument(nsURI, name, null); 48 assertEquals(document.getDocumentElement().getNamespaceURI(), nsURI); 49 assertEquals(document.getDocumentElement().getNodeName(), name); 50 } 51 52 @Test 53 public void testCreateDocumentType01() throws ParserConfigurationException { 54 final String name = "document:localName"; 55 final String publicId = "pubid"; 56 final String systemId = "sysid"; 57 58 DOMImplementation domImpl = getDOMImplementation(); 59 DocumentType documentType = domImpl.createDocumentType(name, publicId, systemId); 60 verifyDocumentType(documentType, name, publicId, systemId); 61 } 62 63 64 @Test 65 public void testCreateDocumentType02() throws ParserConfigurationException { 66 final String name = "document:localName"; 67 final String publicId = "-//W3C//DTD HTML 4.0 Transitional//EN"; 68 final String systemId = "http://www.w3.org/TR/REC-html40/loose.dtd"; 69 DOMImplementation domImpl = getDOMImplementation(); 70 71 DocumentType documentType = domImpl.createDocumentType(name, publicId, systemId); 72 Document document = domImpl.createDocument("http://www.document.com", "document:localName", documentType); 73 verifyDocumentType(document.getDoctype(), name, publicId, systemId); 74 } 75 76 @DataProvider(name = "feature-supported") 77 public Object[][] getFeatureSupportedList() throws ParserConfigurationException { 78 DOMImplementation impl = getDOMImplementation(); 79 return new Object[][] { 80 { impl, "XML", "2.0", true }, 81 { impl, "HTML", "2.0", false }, 82 { impl, "Views", "2.0", false }, 83 { impl, "StyleSheets", "2.0", false }, 84 { impl, "CSS", "2.0", false }, 85 { impl, "CSS2", "2.0", false }, 86 { impl, "Events", "2.0", true }, 87 { impl, "UIEvents", "2.0", false }, 88 { impl, "MouseEvents", "2.0", false }, 89 { impl, "HTMLEvents", "2.0", false }, 90 { impl, "Traversal", "2.0", true }, 91 { impl, "Range", "2.0", true }, 92 { impl, "Core", "2.0", true }, 93 { impl, "XML", "", true } }; 94 } 95 96 97 @Test(dataProvider = "feature-supported") 98 public void testHasFeature(DOMImplementation impl, String feature, String version, boolean isSupported) { 99 assertEquals(impl.hasFeature(feature,version), isSupported); 100 } 101 102 103 private DOMImplementation getDOMImplementation() throws ParserConfigurationException { 104 return createNewDocument().getImplementation(); 105 } 106 107 108 private void verifyDocumentType(DocumentType documentType, String name, String publicId, String systemId) { 109 assertEquals(documentType.getPublicId(), publicId); 110 assertEquals(documentType.getSystemId(), systemId); 111 assertEquals(documentType.getName(), name); 112 } 113 }