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