jaxp/test/javax/xml/jaxp/unittest/parsers/Bug4934208.java
author fyuan
Mon, 08 Aug 2016 12:50:00 +0800
changeset 40223 64662417aa2d
parent 32156 8def5917a696
child 40829 ad509d5baa06
permissions -rw-r--r--
8067170: Enable security manager on JAXP unit tests and make some improvement 8130494: [TESTBUG] 2 jaxp test cases are failing 8160216: jaxp/test/javax/xml/jaxp/unittest/validation/Bug6457662.java should clean up better Reviewed-by: joehw, dfuchs, amlu Contributed-by: Frank Yuan <frank.yuan@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32156
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
     1
/*
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
32156
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
     4
 *
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
     8
 *
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    13
 * accompanied this code).
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    14
 *
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    18
 *
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    21
 * questions.
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    22
 */
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    23
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    24
package parsers;
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    25
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    26
import javax.xml.parsers.SAXParser;
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    27
import javax.xml.parsers.SAXParserFactory;
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    28
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    29
import org.testng.Assert;
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
    30
import org.testng.annotations.Listeners;
32156
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    31
import org.testng.annotations.Test;
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    32
import org.xml.sax.InputSource;
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    33
import org.xml.sax.SAXException;
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    34
import org.xml.sax.XMLReader;
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    35
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    36
import util.DraconianErrorHandler;
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    37
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    38
/*
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
    39
 * @test
32156
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    40
 * @bug 4934208
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
    41
 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
    42
 * @run testng/othervm -DrunSecMngr=true parsers.Bug4934208
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
    43
 * @run testng/othervm parsers.Bug4934208
32156
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    44
 * @summary Test SAXParser can parse keyref constraint with a selector that is a union xpath expression selecting a node and its child.
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    45
 */
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
    46
@Listeners({jaxp.library.FilePolicy.class})
32156
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    47
public class Bug4934208 {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    48
    @Test
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    49
    public void test1() throws Exception {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    50
        parse(new InputSource(Bug4934208.class.getResourceAsStream("test1.xml")));
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    51
    }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    52
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    53
    @Test
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    54
    public void test2() throws Exception {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    55
        try {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    56
            parse(new InputSource(Bug4934208.class.getResourceAsStream("test2.xml")));
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    57
        } catch (SAXException e) {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    58
            Assert.assertTrue(e.getMessage().startsWith("cvc-complex-type.2.4.a"));
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    59
        }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    60
    }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    61
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    62
    private void parse(InputSource is) throws Exception {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    63
        SAXParserFactory spf = SAXParserFactory.newInstance();
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    64
        spf.setNamespaceAware(true);
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    65
        spf.setValidating(true);
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    66
        SAXParser parser = spf.newSAXParser();
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    67
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    68
        parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    69
        parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", Bug4934208.class.getResourceAsStream("test.xsd"));
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    70
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    71
        XMLReader r = parser.getXMLReader();
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    72
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    73
        r.setErrorHandler(new DraconianErrorHandler());
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    74
        r.parse(is);
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    75
    }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    76
}
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
    77