< prev index next >

test/javax/xml/jaxp/unittest/stream/XMLEventReaderTest/Bug6668115Test.java

Print this page
rev 903 : 8153781: Issue in XMLScanner: EXPECTED_SQUARE_BRACKET_TO_CLOSE_INTERNAL_SUBSET


  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package stream.XMLEventReaderTest;
  25 
  26 import java.io.File;
  27 
  28 import javax.xml.stream.XMLEventReader;
  29 import javax.xml.stream.XMLInputFactory;
  30 import javax.xml.stream.XMLOutputFactory;
  31 import javax.xml.stream.events.XMLEvent;
  32 
  33 import org.testng.Assert;
  34 import org.testng.annotations.Test;
  35 
  36 /*
  37  * @bug 6668115
  38  * @summary Test XMLEventReader.getElementText() shall update last event even if no peek.
  39  */
  40 public class Bug6668115Test {
  41 
  42     public java.io.File input;
  43     public final String filesDir = "./";
  44     protected XMLInputFactory inputFactory;
  45     protected XMLOutputFactory outputFactory;
  46 
  47     /**
  48      * The reason the following call sequence is a problem is that with a
  49      * peekevent, getElementText calls nextEvent which does properly update the
  50      * lastEvent
  51      */


  57             er.nextTag();
  58 
  59             System.out.println(er.getElementText());
  60             er.nextTag();
  61             System.out.println(er.getElementText());
  62 
  63         } catch (Exception e) {
  64             System.out.println(e.getMessage());
  65             e.printStackTrace();
  66             Assert.fail(e.getMessage());
  67         }
  68     }
  69 
  70     @Test
  71     public void testNextTagWPeek() {
  72         try {
  73             XMLEventReader er = getReader();
  74             er.nextTag();
  75             er.nextTag();
  76 
  77             XMLEvent event = er.peek();
  78             System.out.println(er.getElementText());
  79             er.nextTag();
  80             System.out.println(er.getElementText());
  81 
  82         } catch (Exception e) {
  83             System.out.println(e.getMessage());
  84             e.printStackTrace();
  85             Assert.fail(e.getMessage());
  86         }
  87     }
  88 
  89     private XMLEventReader getReader() throws Exception {
  90         inputFactory = XMLInputFactory.newInstance();
  91         input = new File(getClass().getResource("play2.xml").getFile());
  92         // Check if event reader returns the correct event
  93         XMLEventReader er = inputFactory.createXMLEventReader(inputFactory.createXMLStreamReader(new java.io.FileInputStream(input), "UTF-8"));
  94         return er;
  95     }
  96 
  97 }


  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package stream.XMLEventReaderTest;
  25 
  26 import java.io.File;
  27 
  28 import javax.xml.stream.XMLEventReader;
  29 import javax.xml.stream.XMLInputFactory;
  30 import javax.xml.stream.XMLOutputFactory;

  31 
  32 import org.testng.Assert;
  33 import org.testng.annotations.Test;
  34 
  35 /*
  36  * @bug 6668115
  37  * @summary Test XMLEventReader.getElementText() shall update last event even if no peek.
  38  */
  39 public class Bug6668115Test {
  40 
  41     public java.io.File input;
  42     public final String filesDir = "./";
  43     protected XMLInputFactory inputFactory;
  44     protected XMLOutputFactory outputFactory;
  45 
  46     /**
  47      * The reason the following call sequence is a problem is that with a
  48      * peekevent, getElementText calls nextEvent which does properly update the
  49      * lastEvent
  50      */


  56             er.nextTag();
  57 
  58             System.out.println(er.getElementText());
  59             er.nextTag();
  60             System.out.println(er.getElementText());
  61 
  62         } catch (Exception e) {
  63             System.out.println(e.getMessage());
  64             e.printStackTrace();
  65             Assert.fail(e.getMessage());
  66         }
  67     }
  68 
  69     @Test
  70     public void testNextTagWPeek() {
  71         try {
  72             XMLEventReader er = getReader();
  73             er.nextTag();
  74             er.nextTag();
  75 
  76             er.peek();
  77             System.out.println(er.getElementText());
  78             er.nextTag();
  79             System.out.println(er.getElementText());
  80 
  81         } catch (Exception e) {
  82             System.out.println(e.getMessage());
  83             e.printStackTrace();
  84             Assert.fail(e.getMessage());
  85         }
  86     }
  87 
  88     private XMLEventReader getReader() throws Exception {
  89         inputFactory = XMLInputFactory.newInstance();
  90         input = new File(getClass().getResource("play2.xml").getFile());
  91         // Check if event reader returns the correct event
  92         XMLEventReader er = inputFactory.createXMLEventReader(inputFactory.createXMLStreamReader(new java.io.FileInputStream(input), "UTF-8"));
  93         return er;
  94     }
  95 
  96 }
< prev index next >