Bug6370703.java revision 997:540334ae53fe
1193326Sed/* 2193326Sed * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 3193326Sed * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4193326Sed * 5193326Sed * This code is free software; you can redistribute it and/or modify it 6193326Sed * under the terms of the GNU General Public License version 2 only, as 7193326Sed * published by the Free Software Foundation. 8193326Sed * 9193326Sed * This code is distributed in the hope that it will be useful, but WITHOUT 10193326Sed * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11193326Sed * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12193326Sed * version 2 for more details (a copy is included in the LICENSE file that 13193326Sed * accompanied this code). 14193326Sed * 15193326Sed * You should have received a copy of the GNU General Public License version 16193326Sed * 2 along with this work; if not, write to the Free Software Foundation, 17226633Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18226633Sdim * 19193326Sed * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20193326Sed * or visit www.oracle.com if you need additional information or have any 21193326Sed * questions. 22193326Sed */ 23193326Sed 24193326Sedpackage stream; 25199482Srdivacky 26226633Sdimimport javax.xml.stream.XMLInputFactory; 27193326Sedimport javax.xml.stream.XMLStreamReader; 28199482Srdivacky 29193326Sedimport org.testng.Assert; 30199482Srdivackyimport org.testng.annotations.Listeners; 31193326Sedimport org.testng.annotations.Test; 32193326Sed 33193326Sed/* 34193326Sed * @test 35193326Sed * @bug 6370703 36226633Sdim * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest 37193326Sed * @run testng/othervm -DrunSecMngr=true stream.Bug6370703 38193326Sed * @run testng/othervm stream.Bug6370703 39193326Sed * @summary Test StAX parser can parse attribute default value when START_ELEMENT. 40193326Sed */ 41193326Sed@Listeners({jaxp.library.FilePolicy.class}) 42218893Sdimpublic class Bug6370703 { 43218893Sdim 44226633Sdim private static String INPUT_FILE = "sgml.xml"; 45218893Sdim 46193326Sed @Test 47193326Sed public void testStartElement() { 48193326Sed try { 49193326Sed XMLInputFactory xif = XMLInputFactory.newInstance(); 50193326Sed XMLStreamReader xsr = xif.createXMLStreamReader(this.getClass().getResource(INPUT_FILE).toExternalForm(), 51193326Sed this.getClass().getResourceAsStream(INPUT_FILE)); 52193326Sed 53193326Sed while (xsr.hasNext()) { 54193326Sed int event = xsr.next(); 55193326Sed if (event == XMLStreamReader.START_ELEMENT) { 56193326Sed String localName = xsr.getLocalName(); 57193326Sed boolean print = "para".equals(localName); 58 int nrOfAttr = xsr.getAttributeCount(); 59 if (print) { 60 Assert.assertTrue(nrOfAttr > 0, "Default attribute declared in DTD is missing"); 61 } 62 63 } 64 } 65 } catch (Exception e) { 66 e.printStackTrace(); 67 Assert.fail("Exception occured: " + e.getMessage()); 68 } 69 } 70 71} 72