< prev index next >

test/javax/xml/jaxp/unittest/common/Sources.java

Print this page




   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 package common;
  24 
  25 import java.io.ByteArrayInputStream;
  26 import java.io.File;

  27 import java.io.StringReader;
  28 import java.io.UnsupportedEncodingException;
  29 import java.net.URISyntaxException;

  30 import javax.xml.parsers.DocumentBuilderFactory;
  31 import javax.xml.parsers.ParserConfigurationException;
  32 import javax.xml.parsers.SAXParserFactory;
  33 import javax.xml.stream.XMLEventReader;
  34 import javax.xml.stream.XMLInputFactory;
  35 import javax.xml.stream.XMLStreamException;
  36 import javax.xml.stream.XMLStreamReader;
  37 import javax.xml.transform.Source;
  38 import javax.xml.transform.dom.DOMSource;
  39 import javax.xml.transform.sax.SAXSource;
  40 import javax.xml.transform.stax.StAXSource;
  41 import javax.xml.transform.stream.StreamSource;



  42 import org.testng.Assert;
  43 import org.testng.annotations.DataProvider;

  44 import org.testng.annotations.Test;
  45 import org.w3c.dom.Document;
  46 import org.xml.sax.InputSource;
  47 import org.xml.sax.SAXException;
  48 import org.xml.sax.XMLReader;
  49 
  50 /*
  51  * @bug 8144967
  52  * @summary Tests related to the javax.xml.transform.Source
  53  * and org.xml.sax.InputSource
  54  */

  55 public class Sources {
  56 
  57     /**
  58      * @bug 8144967
  59      * Tests whether a Source object is empty
  60      * @param source the Source object
  61      */
  62     @Test(dataProvider = "emptySources")
  63     public void testIsEmpty(Source source) {
  64         Assert.assertTrue(source.isEmpty(), "The source is not empty");
  65     }
  66 
  67     /**
  68      * @bug 8144967
  69      * Tests that the source is not empty
  70      * @param source the Source object
  71      */
  72     @Test(dataProvider = "nonEmptySources")
  73     public void testIsNotEmpty(Source source) {
  74         Assert.assertTrue(!source.isEmpty(), "The source is empty");


  91     Object[][] getSources() throws URISyntaxException {
  92 
  93         return new Object[][]{
  94             {new DOMSource()},
  95             {new DOMSource(getDocument())},
  96             {new SAXSource()},
  97             {new SAXSource(new InputSource(new StringReader("")))},
  98             {new SAXSource(getXMLReader(), new InputSource(new StringReader("")))},
  99             {new StreamSource()},
 100             {new StreamSource(new ByteArrayInputStream("".getBytes()))},
 101             {new StreamSource(new StringReader(""))},
 102             {new StreamSource(new StringReader(""), null)},
 103             {new StreamSource((String) null)}
 104         };
 105     }
 106 
 107     /*
 108      * DataProvider: sources that are not empty
 109      */
 110     @DataProvider(name = "nonEmptySources")
 111     Object[][] getSourcesEx() throws URISyntaxException {
 112         StAXSource ss = null;
 113         try {
 114             ss = new StAXSource(getXMLEventReader());
 115         } catch (XMLStreamException ex) {}

 116 
 117         return new Object[][]{
 118             //This will set a non-null systemId on the resulting StreamSource
 119             {new StreamSource(new File(""))},
 120             //Can't tell because XMLStreamReader is a pull parser, cursor advancement
 121             //would have been required in order to examine the reader.
 122             {new StAXSource(getXMLStreamReader())},
 123             {ss}
 124         };

 125     }
 126 
 127     /*
 128      * DataProvider: sources that are empty
 129      */
 130     @DataProvider(name = "emptyInputSource")
 131     Object[][] getInputSources() throws URISyntaxException {
 132         byte[] utf8Bytes = null;
 133         try {
 134             utf8Bytes = "".getBytes("UTF8");
 135         } catch (UnsupportedEncodingException ex) {
 136             throw new RuntimeException(ex.getMessage());
 137         }
 138         return new Object[][]{
 139             {new InputSource()},
 140             {new InputSource(new ByteArrayInputStream(utf8Bytes))},
 141             {new InputSource(new StringReader(""))},
 142             {new InputSource((String) null)}
 143         };
 144     }




   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 package common;
  24 
  25 import java.io.ByteArrayInputStream;
  26 import java.io.File;
  27 import java.io.FilePermission;
  28 import java.io.StringReader;
  29 import java.io.UnsupportedEncodingException;
  30 import java.net.URISyntaxException;
  31 
  32 import javax.xml.parsers.DocumentBuilderFactory;
  33 import javax.xml.parsers.ParserConfigurationException;
  34 import javax.xml.parsers.SAXParserFactory;
  35 import javax.xml.stream.XMLEventReader;
  36 import javax.xml.stream.XMLInputFactory;
  37 import javax.xml.stream.XMLStreamException;
  38 import javax.xml.stream.XMLStreamReader;
  39 import javax.xml.transform.Source;
  40 import javax.xml.transform.dom.DOMSource;
  41 import javax.xml.transform.sax.SAXSource;
  42 import javax.xml.transform.stax.StAXSource;
  43 import javax.xml.transform.stream.StreamSource;
  44 
  45 import jaxp.library.JAXPTestUtilities;
  46 
  47 import org.testng.Assert;
  48 import org.testng.annotations.DataProvider;
  49 import org.testng.annotations.Listeners;
  50 import org.testng.annotations.Test;
  51 import org.w3c.dom.Document;
  52 import org.xml.sax.InputSource;
  53 import org.xml.sax.SAXException;
  54 import org.xml.sax.XMLReader;
  55 
  56 /*
  57  * @bug 8144967
  58  * @summary Tests related to the javax.xml.transform.Source
  59  * and org.xml.sax.InputSource
  60  */
  61 @Listeners({jaxp.library.FilePolicy.class})
  62 public class Sources {
  63 
  64     /**
  65      * @bug 8144967
  66      * Tests whether a Source object is empty
  67      * @param source the Source object
  68      */
  69     @Test(dataProvider = "emptySources")
  70     public void testIsEmpty(Source source) {
  71         Assert.assertTrue(source.isEmpty(), "The source is not empty");
  72     }
  73 
  74     /**
  75      * @bug 8144967
  76      * Tests that the source is not empty
  77      * @param source the Source object
  78      */
  79     @Test(dataProvider = "nonEmptySources")
  80     public void testIsNotEmpty(Source source) {
  81         Assert.assertTrue(!source.isEmpty(), "The source is empty");


  98     Object[][] getSources() throws URISyntaxException {
  99 
 100         return new Object[][]{
 101             {new DOMSource()},
 102             {new DOMSource(getDocument())},
 103             {new SAXSource()},
 104             {new SAXSource(new InputSource(new StringReader("")))},
 105             {new SAXSource(getXMLReader(), new InputSource(new StringReader("")))},
 106             {new StreamSource()},
 107             {new StreamSource(new ByteArrayInputStream("".getBytes()))},
 108             {new StreamSource(new StringReader(""))},
 109             {new StreamSource(new StringReader(""), null)},
 110             {new StreamSource((String) null)}
 111         };
 112     }
 113 
 114     /*
 115      * DataProvider: sources that are not empty
 116      */
 117     @DataProvider(name = "nonEmptySources")
 118     Object[][] getSourcesEx() {
 119         StAXSource ss = null;
 120         try {
 121             ss = new StAXSource(getXMLEventReader());
 122         } catch (XMLStreamException ex) {
 123         }
 124 
 125         return new Object[][] {
 126             // This will set a non-null systemId on the resulting
 127             // StreamSource
 128             { new StreamSource(new File("")) },// )},
 129             // Can't tell because XMLStreamReader is a pull parser, cursor
 130             // advancement
 131             // would have been required in order to examine the reader.
 132             { new StAXSource(getXMLStreamReader()) },
 133             { ss } };
 134     }
 135 
 136     /*
 137      * DataProvider: sources that are empty
 138      */
 139     @DataProvider(name = "emptyInputSource")
 140     Object[][] getInputSources() throws URISyntaxException {
 141         byte[] utf8Bytes = null;
 142         try {
 143             utf8Bytes = "".getBytes("UTF8");
 144         } catch (UnsupportedEncodingException ex) {
 145             throw new RuntimeException(ex.getMessage());
 146         }
 147         return new Object[][]{
 148             {new InputSource()},
 149             {new InputSource(new ByteArrayInputStream(utf8Bytes))},
 150             {new InputSource(new StringReader(""))},
 151             {new InputSource((String) null)}
 152         };
 153     }


< prev index next >