< prev index next >

test/javax/xml/jaxp/unittest/stream/StreamReaderDelegateTest.java

Print this page


   1 /*
   2  * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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;
  25 
  26 import java.io.File;
  27 import java.io.FileInputStream;
  28 import java.io.FileNotFoundException;
  29 import java.io.InputStream;
  30 import java.util.Iterator;
  31 
  32 import javax.xml.namespace.NamespaceContext;
  33 import javax.xml.stream.FactoryConfigurationError;
  34 import javax.xml.stream.XMLInputFactory;
  35 import javax.xml.stream.XMLStreamConstants;
  36 import javax.xml.stream.XMLStreamException;
  37 import javax.xml.stream.XMLStreamReader;
  38 import javax.xml.stream.util.StreamReaderDelegate;
  39 
  40 import org.testng.Assert;

  41 import org.testng.annotations.Test;
  42 
  43 /*
  44  * @summary Test StreamReaderDelegate.
  45  */

  46 public class StreamReaderDelegateTest {
  47 
  48     /**
  49      * Tested xml file looks as below: <?xml version="1.0" standalone="no" ?>
  50      * <ns1:foo attr1="defaultAttr1" ns1:attr1="ns1Attr1" ns2:attr1="ns2Attr1"
  51      * attr2="defaultAttr2" attr3="defaultAttr3" xmlns:ns1="http://ns1.java.com"
  52      * xmlns:ns2="http://ns2.java.com"> <!--description--> content text
  53      * <![CDATA[<greeting>Hello</greeting>]]> other content </ns1:foo>
  54      **/
  55     @Test
  56     public void testAttribute() {
  57         StreamReaderDelegate delegate = null;
  58         try {
  59             System.out.println("===in testAttribute()===");
  60             XMLInputFactory ifac = XMLInputFactory.newFactory();
  61             XMLStreamReader reader = ifac.createXMLStreamReader(new FileInputStream(new File(getClass().getResource("testfile1.xml").getFile())));
  62             delegate = new StreamReaderDelegate(reader);
  63 
  64             Assert.assertTrue(delegate.standaloneSet());
  65             Assert.assertFalse(delegate.isStandalone());


   1 /*
   2  * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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;
  25 
  26 import java.io.File;
  27 import java.io.FileInputStream;
  28 import java.io.FileNotFoundException;
  29 import java.io.InputStream;
  30 import java.util.Iterator;
  31 
  32 import javax.xml.namespace.NamespaceContext;
  33 import javax.xml.stream.FactoryConfigurationError;
  34 import javax.xml.stream.XMLInputFactory;
  35 import javax.xml.stream.XMLStreamConstants;
  36 import javax.xml.stream.XMLStreamException;
  37 import javax.xml.stream.XMLStreamReader;
  38 import javax.xml.stream.util.StreamReaderDelegate;
  39 
  40 import org.testng.Assert;
  41 import org.testng.annotations.Listeners;
  42 import org.testng.annotations.Test;
  43 
  44 /*
  45  * @summary Test StreamReaderDelegate.
  46  */
  47 @Listeners({jaxp.library.FilePolicy.class})
  48 public class StreamReaderDelegateTest {
  49 
  50     /**
  51      * Tested xml file looks as below: <?xml version="1.0" standalone="no" ?>
  52      * <ns1:foo attr1="defaultAttr1" ns1:attr1="ns1Attr1" ns2:attr1="ns2Attr1"
  53      * attr2="defaultAttr2" attr3="defaultAttr3" xmlns:ns1="http://ns1.java.com"
  54      * xmlns:ns2="http://ns2.java.com"> <!--description--> content text
  55      * <![CDATA[<greeting>Hello</greeting>]]> other content </ns1:foo>
  56      **/
  57     @Test
  58     public void testAttribute() {
  59         StreamReaderDelegate delegate = null;
  60         try {
  61             System.out.println("===in testAttribute()===");
  62             XMLInputFactory ifac = XMLInputFactory.newFactory();
  63             XMLStreamReader reader = ifac.createXMLStreamReader(new FileInputStream(new File(getClass().getResource("testfile1.xml").getFile())));
  64             delegate = new StreamReaderDelegate(reader);
  65 
  66             Assert.assertTrue(delegate.standaloneSet());
  67             Assert.assertFalse(delegate.isStandalone());


< prev index next >