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 24 package org.w3c.dom.ptests; 25 26 import static org.testng.Assert.assertEquals; 27 import static org.w3c.dom.ptests.DOMTestUtil.createDOM; 28 import jaxp.library.JAXPFileBaseTest; 29 30 import org.testng.Assert; 31 import org.testng.annotations.Test; 32 import org.w3c.dom.DocumentType; 33 import org.w3c.dom.NamedNodeMap; 34 35 /* 36 * @summary Test DocumentType 37 */ 38 public class DocumentTypeTest extends JAXPFileBaseTest { 39 40 @Test 41 public void testGetEntities() throws Exception { 42 DocumentType documentType = createDOM("DocumentType01.xml").getDoctype(); 43 NamedNodeMap namedNodeMap = documentType.getEntities(); 44 // should return both external and internal. Parameter entities are not 45 // contained. Duplicates are discarded. 46 assertEquals(namedNodeMap.getLength(), 3); 47 assertEquals(namedNodeMap.item(0).getNodeName(), "author"); 48 assertEquals(namedNodeMap.item(1).getNodeName(), "test"); 49 assertEquals(namedNodeMap.item(2).getNodeName(), "writer"); 50 } 51 52 @Test 53 public void testGetNotations() throws Exception { 54 DocumentType documentType = createDOM("DocumentType03.xml").getDoctype(); 55 NamedNodeMap nm = documentType.getNotations(); 56 assertEquals(nm.getLength(), 2); // should return 2 because the notation 57 // name is repeated and 58 // it considers only the first 59 // occurence 60 assertEquals(nm.item(0).getNodeName(), "gs"); 61 assertEquals(nm.item(1).getNodeName(), "name"); 62 } 63 64 @Test 65 public void testGetName() throws Exception { 66 DocumentType documentType = createDOM("DocumentType03.xml").getDoctype(); 67 assertEquals(documentType.getName(), "note"); 68 } 69 70 @Test 71 public void testGetSystemId() throws Exception { 72 DocumentType documentType = createDOM("DocumentType05.xml").getDoctype(); 73 assertEquals(documentType.getSystemId(), "DocumentBuilderImpl02.dtd"); 74 Assert.assertNull(documentType.getPublicId()); 75 } 76 77 }