jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXParserTest03.java
author joehw
Thu, 15 Jan 2015 19:10:56 -0800
changeset 28445 5a87f52ca380
parent 27983 f5f19fe0e83b
child 40223 64662417aa2d
permissions -rw-r--r--
8051563: Update JAXP functional tests Reviewed-by: lancea, joehw Contributed-by: tristan.yan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
     1
/*
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
     2
 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
     4
 *
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
     8
 *
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    13
 * accompanied this code).
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    14
 *
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    18
 *
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    21
 * questions.
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    22
 */
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    23
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    24
package javax.xml.parsers.ptests;
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    25
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    26
import static org.testng.Assert.assertFalse;
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    27
import static org.testng.Assert.assertTrue;
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    28
import java.io.File;
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    29
import java.io.FilePermission;
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    30
import javax.xml.parsers.SAXParser;
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    31
import javax.xml.parsers.SAXParserFactory;
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    32
import static javax.xml.parsers.ptests.ParserTestConst.XML_DIR;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    33
import jaxp.library.JAXPFileReadOnlyBaseTest;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    34
import static org.testng.Assert.fail;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    35
import org.testng.annotations.AfterGroups;
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    36
import org.testng.annotations.BeforeGroups;
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    37
import org.testng.annotations.DataProvider;
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    38
import org.testng.annotations.Test;
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    39
import org.xml.sax.SAXException;
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    40
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    41
/**
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    42
 * Class contains the test cases for SAXParser API
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    43
 */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    44
public class SAXParserTest03 extends JAXPFileReadOnlyBaseTest {
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    45
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    46
    /**
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    47
     * Provide SAXParserFactory.
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    48
     *
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    49
     * @return a dimensional contains.
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    50
     */
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    51
    @DataProvider(name = "input-provider")
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    52
    public Object[][] getFactory() {
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    53
        SAXParserFactory spf = SAXParserFactory.newInstance();
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    54
        spf.setValidating(true);
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    55
        return new Object[][] { { spf, MyErrorHandler.newInstance() } };
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    56
    }
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    57
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    58
    /**
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    59
     * parsertest.xml holds a valid document. This method tests the validating
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    60
     * parser.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    61
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    62
     * @param spf a Parser factory.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    63
     * @param handler an error handler for capturing events.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    64
     * @throws Exception If any errors occur.
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    65
     */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    66
    @Test(groups = {"readLocalFiles"}, dataProvider = "input-provider")
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    67
    public void testParseValidate01(SAXParserFactory spf, MyErrorHandler handler)
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    68
            throws Exception {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    69
            spf.newSAXParser().parse(new File(XML_DIR, "parsertest.xml"), handler);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    70
            assertFalse(handler.isErrorOccured());
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    71
    }
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    72
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    73
    /**
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    74
     * validns.xml holds a valid document with XML namespaces in it. This method
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    75
     * tests the Validating parser with namespace processing on.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    76
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    77
     * @param spf a Parser factory.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    78
     * @param handler an error handler for capturing events.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    79
     * @throws Exception If any errors occur.
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    80
     */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    81
    @Test(groups = {"readLocalFiles"}, dataProvider = "input-provider")
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    82
    public void testParseValidate02(SAXParserFactory spf, MyErrorHandler handler)
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    83
            throws Exception {
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    84
            spf.setNamespaceAware(true);
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    85
            spf.newSAXParser().parse(new File(XML_DIR, "validns.xml"), handler);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    86
            assertFalse(handler.isErrorOccured());
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    87
    }
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    88
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    89
    /**
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    90
     * invalidns.xml holds an invalid document with XML namespaces in it. This
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    91
     * method tests the validating parser with namespace processing on. It
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    92
     * should throw validation error.
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    93
     *
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    94
     * @param spf a Parser factory.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    95
     * @param handler an error handler for capturing events.
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    96
     * @throws Exception If any errors occur.
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
    97
     */
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    98
    @Test(groups = {"readLocalFiles"}, dataProvider = "input-provider")
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
    99
    public void testParseValidate03(SAXParserFactory spf, MyErrorHandler handler)
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
   100
            throws Exception {
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
   101
        try {
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
   102
            spf.setNamespaceAware(true);
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
   103
            SAXParser saxparser = spf.newSAXParser();
28445
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
   104
            saxparser.parse(new File(XML_DIR, "invalidns.xml"), handler);
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
   105
            fail("Expecting SAXException here");
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
   106
        } catch (SAXException e) {
5a87f52ca380 8051563: Update JAXP functional tests
joehw
parents: 27983
diff changeset
   107
            assertTrue(handler.isErrorOccured());
27983
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
   108
        }
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
   109
    }
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
   110
f5f19fe0e83b 8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
joehw
parents:
diff changeset
   111
}