jaxp/test/javax/xml/jaxp/functional/org/w3c/dom/ptests/NotationTest.java
author joehw
Wed, 15 Apr 2015 21:54:29 -0700
changeset 29947 3ea7da18938d
child 40223 64662417aa2d
permissions -rw-r--r--
8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests Reviewed-by: lancea, joehw Contributed-by: frank.yuan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29947
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     1
/*
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     4
 *
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     8
 *
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    13
 * accompanied this code).
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    14
 *
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    18
 *
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    21
 * questions.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    22
 */
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    23
package org.w3c.dom.ptests;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    24
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    25
import static org.testng.Assert.assertEquals;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    26
import static org.w3c.dom.ptests.DOMTestUtil.createDOM;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    27
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    28
import java.io.IOException;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    29
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    30
import javax.xml.parsers.ParserConfigurationException;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    31
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    32
import jaxp.library.JAXPFileBaseTest;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    33
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    34
import org.testng.annotations.Test;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    35
import org.w3c.dom.Document;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    36
import org.w3c.dom.NamedNodeMap;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    37
import org.w3c.dom.Notation;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    38
import org.xml.sax.SAXException;
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    39
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    40
/*
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    41
 * @summary Test for Notation interface
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    42
 */
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    43
public class NotationTest extends JAXPFileBaseTest {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    44
    /*
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    45
     * Test getSystemId method.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    46
     */
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    47
    @Test
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    48
    public void testGetSystemId() throws Exception {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    49
        assertEquals(findNotation("gs").getSystemId(), "http://who.knows.where/");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    50
    }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    51
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    52
    /*
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    53
     * Test getPublicId method.
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    54
     */
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    55
    @Test
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    56
    public void testGetPublicId() throws Exception {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    57
        assertEquals(findNotation("pubname").getPublicId(), "pubId");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    58
    }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    59
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    60
    //find notation in Notation01.xml
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    61
    private Notation findNotation(String name) throws SAXException, IOException, ParserConfigurationException {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    62
        Document document = createDOM("Notation01.xml");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    63
        NamedNodeMap nm = document.getDoctype().getNotations();
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    64
        for (int i = 0; i < nm.getLength(); i++) {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    65
            if (nm.item(i).getNodeName().equals(name)) {
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    66
                return (Notation) nm.item(i);
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    67
            }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    68
        }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    69
        throw new RuntimeException("Notation: '" + name + "' not found.");
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    70
    }
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    71
3ea7da18938d 8051559: Convert JAXP function tests: org.w3c.dom to jtreg (testng) tests
joehw
parents:
diff changeset
    72
}