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     /*
  41      * Test testGetEntities method, and verify the entity items.
  42      */
  43     @Test
  44     public void testGetEntities() throws Exception {
  45         DocumentType documentType = createDOM("DocumentType01.xml").getDoctype();
  46         NamedNodeMap namedNodeMap = documentType.getEntities();
  47         // should return both external and internal. Parameter entities are not
  48         // contained. Duplicates are discarded.
  49         assertEquals(namedNodeMap.getLength(), 3);
  50         assertEquals(namedNodeMap.item(0).getNodeName(), "author");
  51         assertEquals(namedNodeMap.item(1).getNodeName(), "test");
  52         assertEquals(namedNodeMap.item(2).getNodeName(), "writer");
  53     }
  54 
  55     /*
  56      * Test getNotations method, and verify the notation items.
  57      */
  58     @Test
  59     public void testGetNotations() throws Exception {
  60         DocumentType documentType = createDOM("DocumentType03.xml").getDoctype();
  61         NamedNodeMap nm = documentType.getNotations();
  62         assertEquals(nm.getLength(), 2); // should return 2 because the notation
  63                                          // name is repeated and
  64                                          // it considers only the first
  65                                          // occurence
  66         assertEquals(nm.item(0).getNodeName(), "gs");
  67         assertEquals(nm.item(1).getNodeName(), "name");
  68     }
  69 
  70     /*
  71      * Test getName method.
  72      */
  73     @Test
  74     public void testGetName() throws Exception {
  75         DocumentType documentType = createDOM("DocumentType03.xml").getDoctype();
  76         assertEquals(documentType.getName(), "note");
  77     }
  78 
  79     /*
  80      * Test getSystemId and getPublicId method.
  81      */
  82     @Test
  83     public void testGetSystemId() throws Exception {
  84         DocumentType documentType = createDOM("DocumentType05.xml").getDoctype();
  85         assertEquals(documentType.getSystemId(), "DocumentBuilderImpl02.dtd");
  86         Assert.assertNull(documentType.getPublicId());
  87     }
  88 
  89 }