jaxp/test/javax/xml/jaxp/unittest/stream/XMLStreamReaderTest/DoubleXmlnsTest.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
/*
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
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 stream.XMLStreamReaderTest;
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 java.io.StringReader;
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    27
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    28
import javax.xml.stream.XMLInputFactory;
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    29
import javax.xml.stream.XMLStreamException;
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    30
import javax.xml.stream.XMLStreamReader;
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    31
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    32
import org.testng.Assert;
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
    33
import org.testng.annotations.Listeners;
32156
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    34
import org.testng.annotations.Test;
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
/*
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
    37
 * @test
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
    38
 * @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
    39
 * @run testng/othervm -DrunSecMngr=true stream.XMLStreamReaderTest.DoubleXmlnsTest
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
    40
 * @run testng/othervm stream.XMLStreamReaderTest.DoubleXmlnsTest
32156
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    41
 * @summary Test double namespaces and nested namespaces.
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    42
 */
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
    43
@Listeners({jaxp.library.BasePolicy.class})
32156
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    44
public class DoubleXmlnsTest {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    45
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    46
    @Test
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    47
    public void testDoubleNS() throws Exception {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    48
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    49
        final String INVALID_XML = "<foo xmlns:xmli='http://www.w3.org/XML/1998/namespacei' xmlns:xmli='http://www.w3.org/XML/1998/namespacei' />";
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    50
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    51
        try {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    52
            XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(INVALID_XML));
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    53
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    54
            while (xsr.hasNext()) {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    55
                xsr.next();
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    56
            }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    57
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    58
            Assert.fail("Wellformedness error expected: " + INVALID_XML);
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    59
        } catch (XMLStreamException e) {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    60
            ; // this is expected
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
    }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    63
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    64
    @Test
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    65
    public void testNestedNS() throws Exception {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    66
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    67
        final String VALID_XML = "<foo xmlns:xmli='http://www.w3.org/XML/1998/namespacei'><bar xmlns:xmli='http://www.w3.org/XML/1998/namespaceii'></bar></foo>";
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    68
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    69
        try {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    70
            XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(VALID_XML));
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    71
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    72
            while (xsr.hasNext()) {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    73
                xsr.next();
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    74
            }
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
            // expected success
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    77
        } catch (XMLStreamException e) {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    78
            e.printStackTrace();
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    79
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    80
            Assert.fail("Wellformedness error is not expected: " + VALID_XML + ", " + e.getMessage());
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    81
        }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    82
    }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    83
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    84
    @Test
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    85
    public void testDoubleXmlns() throws Exception {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    86
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    87
        final String INVALID_XML = "<foo xmlns:xml='http://www.w3.org/XML/1998/namespace' xmlns:xml='http://www.w3.org/XML/1998/namespace' ></foo>";
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    88
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    89
        try {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    90
            XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(INVALID_XML));
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    91
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    92
            while (xsr.hasNext()) {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    93
                xsr.next();
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    94
            }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    95
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    96
            Assert.fail("Wellformedness error expected :" + INVALID_XML);
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    97
        } catch (XMLStreamException e) {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    98
            ; // this is expected
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
    99
        }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   100
    }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   101
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   102
    @Test
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   103
    public void testNestedXmlns() throws Exception {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   104
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   105
        final String VALID_XML = "<foo xmlns:xml='http://www.w3.org/XML/1998/namespace'><bar xmlns:xml='http://www.w3.org/XML/1998/namespace'></bar></foo>";
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   106
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   107
        try {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   108
            XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(VALID_XML));
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   109
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   110
            while (xsr.hasNext()) {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   111
                xsr.next();
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   112
            }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   113
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   114
            // expected success
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   115
        } catch (XMLStreamException e) {
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   116
            e.printStackTrace();
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   117
            Assert.fail("Wellformedness error is not expected: " + VALID_XML + ", " + e.getMessage());
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   118
        }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   119
    }
8def5917a696 8132660: Change jaxp unit test package name to be different with jaxp api
joehw
parents:
diff changeset
   120
}
40223
64662417aa2d 8067170: Enable security manager on JAXP unit tests and make some improvement
fyuan
parents: 32156
diff changeset
   121