Path: blob/master/test/jaxp/javax/xml/jaxp/unittest/stream/XMLStreamReaderTest/DoubleXmlnsTest.java
43750 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package stream.XMLStreamReaderTest;2425import java.io.StringReader;2627import javax.xml.stream.XMLInputFactory;28import javax.xml.stream.XMLStreamException;29import javax.xml.stream.XMLStreamReader;3031import org.testng.Assert;32import org.testng.annotations.Listeners;33import org.testng.annotations.Test;3435/*36* @test37* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest38* @run testng/othervm -DrunSecMngr=true -Djava.security.manager=allow stream.XMLStreamReaderTest.DoubleXmlnsTest39* @run testng/othervm stream.XMLStreamReaderTest.DoubleXmlnsTest40* @summary Test double namespaces and nested namespaces.41*/42@Listeners({jaxp.library.BasePolicy.class})43public class DoubleXmlnsTest {4445@Test46public void testDoubleNS() throws Exception {4748final String INVALID_XML = "<foo xmlns:xmli='http://www.w3.org/XML/1998/namespacei' xmlns:xmli='http://www.w3.org/XML/1998/namespacei' />";4950try {51XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(INVALID_XML));5253while (xsr.hasNext()) {54xsr.next();55}5657Assert.fail("Wellformedness error expected: " + INVALID_XML);58} catch (XMLStreamException e) {59; // this is expected60}61}6263@Test64public void testNestedNS() throws Exception {6566final 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>";6768try {69XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(VALID_XML));7071while (xsr.hasNext()) {72xsr.next();73}7475// expected success76} catch (XMLStreamException e) {77e.printStackTrace();7879Assert.fail("Wellformedness error is not expected: " + VALID_XML + ", " + e.getMessage());80}81}8283@Test84public void testDoubleXmlns() throws Exception {8586final String INVALID_XML = "<foo xmlns:xml='http://www.w3.org/XML/1998/namespace' xmlns:xml='http://www.w3.org/XML/1998/namespace' ></foo>";8788try {89XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(INVALID_XML));9091while (xsr.hasNext()) {92xsr.next();93}9495Assert.fail("Wellformedness error expected :" + INVALID_XML);96} catch (XMLStreamException e) {97; // this is expected98}99}100101@Test102public void testNestedXmlns() throws Exception {103104final 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>";105106try {107XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(VALID_XML));108109while (xsr.hasNext()) {110xsr.next();111}112113// expected success114} catch (XMLStreamException e) {115e.printStackTrace();116Assert.fail("Wellformedness error is not expected: " + VALID_XML + ", " + e.getMessage());117}118}119}120121122