< prev index next >

test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXParserTest.java

Print this page




   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 javax.xml.parsers.ptests;
  25 
  26 import static jaxp.library.JAXPTestUtilities.failUnexpected;
  27 
  28 import java.io.File;
  29 import java.io.FileInputStream;

  30 import java.io.IOException;
  31 
  32 import javax.xml.parsers.ParserConfigurationException;
  33 import javax.xml.parsers.SAXParser;
  34 import javax.xml.parsers.SAXParserFactory;
  35 



  36 import org.testng.annotations.DataProvider;
  37 import org.testng.annotations.Test;
  38 import org.xml.sax.HandlerBase;
  39 import org.xml.sax.InputSource;
  40 import org.xml.sax.SAXException;
  41 import org.xml.sax.helpers.DefaultHandler;
  42 
  43 /**
  44  * Class contains the test cases for SAXParser API
  45  */
  46 public class SAXParserTest {
  47 
  48     /**
  49      * Provide SAXParser.
  50      *
  51      * @throws SAXException
  52      * @throws ParserConfigurationException



  53      */
  54     @DataProvider(name = "parser-provider")
  55     public Object[][] getParser() throws ParserConfigurationException, SAXException {
  56         SAXParserFactory spf = SAXParserFactory.newInstance();
  57         SAXParser saxparser = spf.newSAXParser();
  58         return new Object[][] { { saxparser } };
  59     }
  60 
  61     /**
  62      * Test case with FileInputStream null, parsing should fail and throw
  63      * IllegalArgumentException.
  64      *
  65      * @throws IllegalArgumentException



  66      */
  67     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
  68     public void testParse01(SAXParser saxparser) throws IllegalArgumentException {
  69         try {
  70             FileInputStream instream = null;
  71             HandlerBase handler = new HandlerBase();
  72             saxparser.parse(instream, handler);
  73         } catch (SAXException | IOException e) {
  74             failUnexpected(e);
  75         }
  76     }
  77 
  78     /**
  79      * Testcase with an error in xml file, parsing should fail and throw
  80      * SAXException.
  81      *
  82      * @throws SAXException
  83      */
  84     @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
  85     public void testParse02(SAXParser saxparser) throws SAXException {
  86         try {
  87             HandlerBase handler = new HandlerBase();
  88             FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "invalid.xml"));
  89             saxparser.parse(instream, handler);
  90         } catch (IOException e) {
  91             failUnexpected(e);
  92         }
  93     }
  94 
  95     /**
  96      * Testcase with a valid in xml file, parser should parse the xml document.





  97      */
  98     @Test(dataProvider = "parser-provider")
  99     public void testParse03(SAXParser saxparser) {
 100         try {
 101             HandlerBase handler = new HandlerBase();
 102             saxparser.parse(new File(TestUtils.XML_DIR, "parsertest.xml"), handler);
 103         } catch (IOException | SAXException e) {
 104             failUnexpected(e);
 105         }
 106     }
 107 
 108     /**
 109      * Testcase with valid input stream, parser should parse the xml document
 110      * successfully.





 111      */
 112     @Test(dataProvider = "parser-provider")
 113     public void testParse04(SAXParser saxparser) {
 114         try {
 115             HandlerBase handler = new HandlerBase();
 116             FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "correct.xml"));
 117             saxparser.parse(instream, handler);
 118         } catch (SAXException | IOException e) {
 119             failUnexpected(e);
 120         }
 121     }
 122 
 123     /**
 124      * Testcase with valid input source, parser should parse the xml document
 125      * successfully.





 126      */
 127     @Test(dataProvider = "parser-provider")
 128     public void testParse05(SAXParser saxparser) {
 129         try {
 130             HandlerBase handler = new HandlerBase();
 131             FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "parsertest.xml"));
 132             saxparser.parse(instream, handler, new File(TestUtils.XML_DIR).toURI().toASCIIString());
 133         } catch (SAXException | IOException e) {
 134             failUnexpected(e);
 135         }
 136     }
 137 
 138     /**
 139      * Testcase with uri null, parsing should fail and throw
 140      * IllegalArgumentException.
 141      *
 142      * @throws IllegalArgumentException



 143      */
 144     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
 145     public void testParse07(SAXParser saxparser) throws IllegalArgumentException {
 146         try {
 147             String uri = null;
 148             HandlerBase handler = new HandlerBase();
 149             saxparser.parse(uri, handler);
 150         } catch (SAXException | IOException e) {
 151             failUnexpected(e);
 152         }
 153     }
 154 
 155     /**
 156      * Testcase with non-existant uri, parsing should fail and throw
 157      * IOException.
 158      *
 159      * @throws SAXException
 160      * @throws IOException


 161      */
 162     @Test(expectedExceptions = { SAXException.class, IOException.class }, dataProvider = "parser-provider")
 163     public void testParse08(SAXParser saxparser) throws SAXException, IOException {
 164         String uri = " ";
 165 
 166         HandlerBase handler = new HandlerBase();
 167         saxparser.parse(uri, handler);
 168 
 169     }
 170 
 171     /**
 172      * Testcase with proper uri, parser should parse successfully.
 173      */
 174     @Test(dataProvider = "parser-provider")
 175     public void testParse09(SAXParser saxparser) {
 176         try {
 177             File file = new File(TestUtils.XML_DIR, "correct.xml");
 178             HandlerBase handler = new HandlerBase();
 179             saxparser.parse(file.toURI().toASCIIString(), handler);
 180         } catch (SAXException | IOException e) {
 181             failUnexpected(e);
 182         }
 183     }
 184 
 185     /**
 186      * Testcase with File null, parsing should fail and throw
 187      * IllegalArgumentException.
 188      *
 189      * @throws IllegalArgumentException



 190      */
 191     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
 192     public void testParse10(SAXParser saxparser) throws IllegalArgumentException {
 193         try {
 194             File file = null;
 195             HandlerBase handler = new HandlerBase();
 196             saxparser.parse(file, handler);
 197         } catch (SAXException | IOException e) {
 198             failUnexpected(e);
 199         }
 200     }
 201 
 202     /**
 203      * Testcase with empty string as File, parsing should fail and throw
 204      * SAXException.
 205      *
 206      * @throws SAXException
 207      */
 208     @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
 209     public void testParse11(SAXParser saxparser) throws SAXException {
 210         try {
 211             HandlerBase handler = new HandlerBase();
 212             File file = new File("");
 213             saxparser.parse(file, handler);
 214         } catch (IOException e) {
 215             failUnexpected(e);
 216         }



 217     }
 218 
 219     /**
 220      * Testcase with xml file that has errors parsing should fail and throw
 221      * SAXException.
 222      *
 223      * @throws SAXException



 224      */
 225     @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
 226     public void testParse12(SAXParser saxparser) throws SAXException {
 227         try {
 228             HandlerBase handler = new HandlerBase();
 229             File file = new File(TestUtils.XML_DIR, "valid.xml");
 230             saxparser.parse(file, handler);
 231         } catch (IOException e) {
 232             failUnexpected(e);
 233         }
 234     }
 235 
 236     /**
 237      * Testcase with xml file that has no errors Parser should successfully
 238      * parse the xml document.





 239      */
 240     @Test(dataProvider = "parser-provider")
 241     public void testParse13(SAXParser saxparser) {
 242         try {
 243             HandlerBase handler = new HandlerBase();
 244             File file = new File(TestUtils.XML_DIR, "correct.xml");
 245             saxparser.parse(file, handler);
 246         } catch (SAXException | IOException e) {
 247             failUnexpected(e);
 248         }
 249 
 250     }
 251 
 252     /**
 253      * Testcase with input source null, parsing should fail and throw
 254      * IllegalArgumentException.
 255      *
 256      * @throws IllegalArgumentException



 257      */
 258     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
 259     public void testParse14(SAXParser saxparser) throws IllegalArgumentException {
 260         try {
 261             InputSource is = null;
 262             HandlerBase handler = new HandlerBase();
 263             saxparser.parse(is, handler);
 264         } catch (SAXException | IOException e) {
 265             failUnexpected(e);
 266         }
 267     }
 268 
 269     /**
 270      * Testcase with input source attached an invaild xml, parsing should fail
 271      * and throw SAXException.
 272      *
 273      * @throws SAXException
 274      */
 275     @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
 276     public void testParse15(SAXParser saxparser) throws SAXException {
 277         try {
 278             HandlerBase handler = new HandlerBase();
 279             FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "invalid.xml"));
 280             InputSource is = new InputSource(instream);
 281             saxparser.parse(is, handler);
 282         } catch (IOException e) {
 283             failUnexpected(e);
 284         }
 285     }
 286 
 287     /**
 288      * Testcase with input source attached an vaild xml, parser should
 289      * successfully parse the xml document.
 290      */
 291     @Test(dataProvider = "parser-provider")
 292     public void testParse16(SAXParser saxparser) {
 293         try {
 294             HandlerBase handler = new HandlerBase();
 295             FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "correct.xml"));
 296             InputSource is = new InputSource(instream);
 297             saxparser.parse(is, handler);
 298         } catch (SAXException | IOException e) {
 299             failUnexpected(e);
 300         }
 301     }
 302 
 303     /**
 304      * Testcase with FileInputStream null, parsing should fail and throw
 305      * IllegalArgumentException.
 306      *
 307      * @throws IllegalArgumentException



 308      */
 309     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
 310     public void testParse17(SAXParser saxparser) throws IllegalArgumentException {
 311         try {
 312             FileInputStream instream = null;
 313             DefaultHandler handler = new DefaultHandler();
 314             saxparser.parse(instream, handler);
 315         } catch (SAXException | IOException e) {
 316             failUnexpected(e);
 317         }
 318     }
 319 
 320     /**
 321      * Testcase with an error in xml file, parsing should fail and throw
 322      * SAXException.
 323      *
 324      * @throws SAXException



 325      */
 326     @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
 327     public void testParse18(SAXParser saxparser) throws SAXException {
 328         try {
 329             DefaultHandler handler = new DefaultHandler();
 330             FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "invalid.xml"));
 331             saxparser.parse(instream, handler);
 332         } catch (IOException e) {
 333             failUnexpected(e);
 334         }
 335     }
 336 
 337     /**
 338      * Testcase with valid input stream, parser should parse the xml document
 339      * successfully.





 340      */
 341     @Test(dataProvider = "parser-provider")
 342     public void testParse19(SAXParser saxparser) {
 343         try {
 344             DefaultHandler handler = new DefaultHandler();
 345             saxparser.parse(new File(TestUtils.XML_DIR, "parsertest.xml"), handler);
 346         } catch (IOException | SAXException e) {
 347             failUnexpected(e);
 348         }
 349     }
 350 
 351     /**
 352      * Testcase with valid input stream, parser should parse the xml document
 353      * successfully.





 354      */
 355     @Test(dataProvider = "parser-provider")
 356     public void testParse20(SAXParser saxparser) {
 357         try {
 358             DefaultHandler handler = new DefaultHandler();
 359             FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "correct.xml"));
 360             saxparser.parse(instream, handler);
 361         } catch (SAXException | IOException e) {
 362             failUnexpected(e);
 363         }
 364     }
 365 
 366     /**
 367      * Testcase with valid input source, parser should parse the xml document
 368      * successfully.




 369      */
 370     @Test(dataProvider = "parser-provider")
 371     public void testParse21(SAXParser saxparser) {
 372         try {
 373             DefaultHandler handler = new DefaultHandler();
 374             FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "parsertest.xml"));
 375             saxparser.parse(instream, handler, new File(TestUtils.XML_DIR).toURI().toASCIIString());
 376         } catch (SAXException | IOException e) {
 377             failUnexpected(e);
 378         }
 379 












 380     }
 381 
 382     /**
 383      * Testcase with uri null, parsing should fail and throw
 384      * IllegalArgumentException.
 385      *
 386      * @throws IllegalArgumentException



 387      */
 388     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
 389     public void testParse23(SAXParser saxparser) throws IllegalArgumentException {
 390         try {
 391             String uri = null;
 392             DefaultHandler handler = new DefaultHandler();
 393             saxparser.parse(uri, handler);
 394         } catch (SAXException | IOException e) {
 395             failUnexpected(e);
 396         }
 397     }
 398 
 399     /**
 400      * Testcase with non-existant uri, parsing should fail and throw
 401      * SAXException or IOException.
 402      *
 403      * @throws SAXException
 404      * @throws IOException


 405      */
 406     @Test(expectedExceptions = { SAXException.class, IOException.class }, dataProvider = "parser-provider")
 407     public void testParse24(SAXParser saxparser) throws SAXException, IOException {
 408         String uri = " ";
 409         DefaultHandler handler = new DefaultHandler();
 410         saxparser.parse(uri, handler);
 411 
 412     }
 413 
 414     /**
 415      * Testcase with proper uri, parser should parse successfully.






 416      */
 417     @Test(dataProvider = "parser-provider")
 418     public void testParse25(SAXParser saxparser) {
 419         try {
 420             File file = new File(TestUtils.XML_DIR, "correct.xml");
 421 
 422             DefaultHandler handler = new DefaultHandler();
 423             saxparser.parse(file.toURI().toASCIIString(), handler);
 424         } catch (SAXException | IOException e) {
 425             failUnexpected(e);
 426         }
 427     }
 428 
 429     /**
 430      * Testcase with File null, parsing should fail and throw
 431      * IllegalArgumentException.
 432      *
 433      * @throws IllegalArgumentException



 434      */
 435     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
 436     public void testParse26(SAXParser saxparser) throws IllegalArgumentException {
 437         try {
 438             DefaultHandler handler = new DefaultHandler();
 439             saxparser.parse((File) null, handler);
 440         } catch (SAXException | IOException e) {
 441             failUnexpected(e);
 442         }
 443     }
 444 
 445     /**
 446      * Testcase with empty string as File, parsing should fail and throw
 447      * SAXException.
 448      *
 449      * @throws SAXException



 450      */
 451     @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
 452     public void testParse27(SAXParser saxparser) throws SAXException {
 453         try {
 454             DefaultHandler handler = new DefaultHandler();
 455             File file = new File("");
 456             saxparser.parse(file, handler);
 457         } catch (IOException e) {
 458             failUnexpected(e);
 459         }
 460     }
 461 
 462     /**
 463      * Testcase with xml file that has errors, parsing should fail and throw
 464      * SAXException.
 465      *
 466      * @throws SAXException



 467      */
 468     @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
 469     public void testParse28(SAXParser saxparser) throws SAXException {
 470         try {

 471             DefaultHandler handler = new DefaultHandler();
 472             File file = new File(TestUtils.XML_DIR, "valid.xml");
 473             saxparser.parse(file, handler);
 474         } catch (IOException e) {
 475             failUnexpected(e);
 476         }
 477     }
 478 
 479     /**
 480      * Testcase with xml file that has no errors, parser should successfully
 481      * parse the xml document.





 482      */
 483     @Test(dataProvider = "parser-provider")
 484     public void testParse29(SAXParser saxparser) {
 485         try {
 486             DefaultHandler handler = new DefaultHandler();
 487             File file = new File(TestUtils.XML_DIR, "correct.xml");
 488             saxparser.parse(file, handler);
 489         } catch (SAXException | IOException e) {
 490             failUnexpected(e);
 491         }
 492     }
 493 
 494     /**
 495      * Testcase with input source null, parsing should fail and throw
 496      * IllegalArgumentException.
 497      *
 498      * @throws IllegalArgumentException



 499      */
 500     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
 501     public void testParse30(SAXParser saxparser) throws IllegalArgumentException {
 502         try {
 503             InputSource is = null;
 504             DefaultHandler handler = new DefaultHandler();
 505             saxparser.parse(is, handler);
 506         } catch (SAXException | IOException e) {
 507             failUnexpected(e);
 508         }













 509     }
 510 
 511     /**
 512      * Testcase with an invalid xml file, parser should throw SAXException.

 513      *
 514      * @throws SAXException



 515      */
 516     @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
 517     public void testParse31(SAXParser saxparser) throws SAXException {
 518         try {
 519             DefaultHandler handler = new DefaultHandler();
 520             FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "invalid.xml"));
 521             InputSource is = new InputSource(instream);
 522             saxparser.parse(is, handler);
 523         } catch (IOException e) {
 524             failUnexpected(e);









 525         }
 526     }
 527 
 528     /**
 529      * Test case to parse an xml file that not use namespaces.





 530      */
 531     @Test(dataProvider = "parser-provider")
 532     public void testParse32(SAXParser saxparser) {
 533         try {
 534             DefaultHandler handler = new DefaultHandler();
 535             FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "correct.xml"));
 536             InputSource is = new InputSource(instream);
 537             saxparser.parse(is, handler);
 538         } catch (SAXException | IOException e) {
 539             failUnexpected(e);
 540         }
 541     }
 542 
 543     /**
 544      * Test case to parse an xml file that uses namespaces.






 545      */
 546     @Test
 547     public void testParse33() {
 548         try {
 549             SAXParserFactory spf = SAXParserFactory.newInstance();
 550             spf.setNamespaceAware(true);
 551             SAXParser saxparser = spf.newSAXParser();
 552             HandlerBase handler = new HandlerBase();
 553             FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "ns4.xml"));
 554             saxparser.parse(instream, handler);
 555         } catch (ParserConfigurationException | SAXException | IOException e) {
 556             failUnexpected(e);
 557         }
 558     }
 559 }


   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 javax.xml.parsers.ptests;
  25 


  26 import java.io.File;
  27 import java.io.FileInputStream;
  28 import java.io.FilePermission;
  29 import java.io.IOException;
  30 import java.util.PropertyPermission;
  31 import javax.xml.parsers.ParserConfigurationException;
  32 import javax.xml.parsers.SAXParser;
  33 import javax.xml.parsers.SAXParserFactory;
  34 import static javax.xml.parsers.ptests.TestUtils.XML_DIR;
  35 import jaxp.library.JAXPBaseTest;
  36 import org.testng.annotations.AfterGroups;
  37 import org.testng.annotations.BeforeGroups;
  38 import org.testng.annotations.DataProvider;
  39 import org.testng.annotations.Test;
  40 import org.xml.sax.HandlerBase;
  41 import org.xml.sax.InputSource;
  42 import org.xml.sax.SAXException;
  43 import org.xml.sax.helpers.DefaultHandler;
  44 
  45 /**
  46  * Class contains the test cases for SAXParser API
  47  */
  48 public class SAXParserTest extends JAXPBaseTest {

  49     /**
  50      * Provide SAXParser.
  51      *
  52      * @return a data provider contains a SAXParser instance.
  53      * @throws SAXException If any parse errors occur.
  54      * @throws ParserConfigurationException in case of ServiceConfigurationError
  55      * service configuration error or if the implementation is not available or
  56      * cannot be instantiated.
  57      */
  58     @DataProvider(name = "parser-provider")
  59     public Object[][] getParser() throws ParserConfigurationException, SAXException {
  60         SAXParserFactory spf = SAXParserFactory.newInstance();
  61         SAXParser saxparser = spf.newSAXParser();
  62         return new Object[][] { { saxparser } };
  63     }
  64 
  65     /**
  66      * Test case with FileInputStream null, parsing should fail and throw
  67      * IllegalArgumentException.
  68      *
  69      * @param saxparser a SAXParser instance.
  70      * @throws SAXException If any parse errors occur.
  71      * @throws IOException If an IO error occurs interacting with the 
  72      *         InputStream.
  73      */
  74     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
  75     public void testParse01(SAXParser saxparser) throws SAXException, IOException {

  76         FileInputStream instream = null;
  77         saxparser.parse(instream, new HandlerBase());




  78     }
  79 
  80     /**
  81      * Test with by setting URI as null, parsing should fail and throw
  82      * IllegalArgumentException.
  83      *
  84      * @param saxparser a SAXParser instance.
  85      * @throws SAXException If any parse errors occur.
  86      * @throws IOException If an IO error occurs interacting with the 
  87      *         InputStream.
  88      */
  89     @Test(expectedExceptions = IllegalArgumentException.class,
  90             dataProvider = "parser-provider")
  91     public void testParse02(SAXParser saxparser) throws SAXException, IOException {
  92         String uri = null;
  93         saxparser.parse(uri, new HandlerBase());

  94     }
  95 
  96     /**
  97      * Test with non-existence URI, parsing should fail and throw IOException.
  98      *
  99      * @param saxparser a SAXParser instance.
 100      * @throws SAXException If any parse errors occur.
 101      * @throws IOException If an IO error occurs interacting with the 
 102      *         InputStream.
 103      */
 104     @Test(expectedExceptions = { SAXException.class, IOException.class }, 
 105             dataProvider = "parser-provider")
 106     public void testParse03(SAXParser saxparser) throws SAXException, IOException {
 107         String workingDir = System.getProperty("test.classes") + "../../../../../../..";
 108         setPermissions(new PropertyPermission("user.dir", "read"),
 109                 new FilePermission(workingDir + "/-", "read"));
 110         saxparser.parse("", new HandlerBase());
 111         setPermissions();
 112     }
 113 
 114     /**
 115      * Test with File null, parsing should fail and throw
 116      * IllegalArgumentException.
 117      *
 118      * @param saxparser a SAXParser instance.
 119      * @throws SAXException If any parse errors occur.
 120      * @throws IOException If an IO error occurs interacting with the 
 121      *         InputStream.
 122      */
 123     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
 124     public void testParse04(SAXParser saxparser) throws SAXException, IOException {
 125         File file = null;
 126         saxparser.parse(file, new HandlerBase());





 127     }
 128 
 129     /**
 130      * Test with empty string as File, parsing should fail and throw
 131      * SAXException.
 132      *
 133      * @param saxparser a SAXParser instance.
 134      * @throws SAXException If any parse errors occur.
 135      * @throws IOException If an IO error occurs interacting with the 
 136      *         InputStream.
 137      */
 138     @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
 139     public void testParse05(SAXParser saxparser) throws SAXException, IOException {
 140         String workingDir = System.getProperty("test.classes") + "../../../../../../..";
 141         setPermissions(new PropertyPermission("user.dir", "read"),
 142                 new FilePermission(workingDir + "/-", "read"));
 143         saxparser.parse(new File(""), new HandlerBase());



 144     }
 145 
 146     /**
 147      * Test with input source null, parsing should fail and throw
 148      * IllegalArgumentException.
 149      *
 150      * @param saxparser a SAXParser instance.
 151      * @throws SAXException If any parse errors occur.
 152      * @throws IOException If an IO error occurs interacting with the 
 153      *         InputStream.
 154      */
 155     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
 156     public void testParse06(SAXParser saxparser) throws SAXException, IOException {
 157         InputSource is = null;
 158         saxparser.parse(is, new HandlerBase());





 159     }
 160 
 161     /**
 162      * Test with FileInputStream null, parsing should fail and throw
 163      * IllegalArgumentException.
 164      *
 165      * @param saxparser a SAXParser instance.
 166      * @throws SAXException If any parse errors occur.
 167      * @throws IOException If an IO error occurs interacting with the 
 168      *         InputStream.
 169      */
 170     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
 171     public void testParse07(SAXParser saxparser) throws SAXException, IOException {
 172         FileInputStream instream = null;
 173         saxparser.parse(instream, new DefaultHandler());

















 174     }
 175 
 176     /**
 177      * Test with URI null, parsing should fail and throw
 178      * IllegalArgumentException.
 179      *
 180      * @param saxparser a SAXParser instance.
 181      * @throws SAXException If any parse errors occur.
 182      * @throws IOException If an IO error occurs interacting with the 
 183      *         InputStream.
 184      */
 185     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
 186     public void testParse08(SAXParser saxparser) throws SAXException, IOException {
 187         String uri = null;
 188         saxparser.parse(uri, new DefaultHandler());





 189     }
 190 
 191     /**
 192      * Test with non-existence URI, parsing should fail and throw
 193      * SAXException or IOException.
 194      *
 195      * @param saxparser a SAXParser instance.
 196      * @throws SAXException If any parse errors occur.
 197      * @throws IOException If an IO error occurs interacting with the 
 198      *         InputStream.
 199      */
 200     @Test(expectedExceptions = { SAXException.class, IOException.class }, 
 201             dataProvider = "parser-provider")
 202     public void testParse09(SAXParser saxparser) throws SAXException, IOException {
 203         String workingDir = System.getProperty("test.classes") + "../../../../../../..";
 204         setPermissions(new PropertyPermission("user.dir", "read"),
 205                 new FilePermission(workingDir + "/-", "read"));
 206         String uri = " ";
 207         saxparser.parse(uri, new DefaultHandler());
 208         setPermissions();
 209     }
 210 
 211     /**
 212      * Test with empty string as File, parsing should fail and throw
 213      * SAXException.
 214      *
 215      * @param saxparser a SAXParser instance.
 216      * @throws SAXException If any parse errors occur.
 217      * @throws IOException If an IO error occurs interacting with the 
 218      *         InputStream.
 219      */
 220     @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
 221     public void testParse10(SAXParser saxparser) throws SAXException, IOException {
 222         String workingDir = System.getProperty("test.classes") + "../../../../../../..";
 223         setPermissions(new PropertyPermission("user.dir", "read"),
 224                 new FilePermission(workingDir + "/-", "read"));
 225         File file = new File("");
 226         saxparser.parse(file, new DefaultHandler());


 227     }
 228 
 229     /**
 230      * Test with File null, parsing should fail and throw
 231      * IllegalArgumentException.
 232      *
 233      * @param saxparser a SAXParser instance.
 234      * @throws SAXException If any parse errors occur.
 235      * @throws IOException If an IO error occurs interacting with the 
 236      *         InputStream.
 237      */
 238     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
 239     public void testParse11(SAXParser saxparser) throws SAXException, IOException {
 240         saxparser.parse((File) null, new DefaultHandler());







 241     }
 242 
 243     /**
 244      * Test with input source null, parsing should fail and throw
 245      * IllegalArgumentException.
 246      *
 247      * @param saxparser a SAXParser instance.
 248      * @throws SAXException If any parse errors occur.
 249      * @throws IOException If an IO error occurs interacting with the 
 250      *         InputStream.
 251      */
 252     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
 253     public void testParse12(SAXParser saxparser) throws SAXException, IOException {

 254         InputSource is = null;
 255         saxparser.parse(is, new DefaultHandler());




 256     }
 257 
 258     /**
 259      * Save system property for restoring.



 260      */
 261     @BeforeGroups (groups = {"readLocalFiles"})
 262     public void setFilePermissions() {
 263         setPermissions(new FilePermission(XML_DIR  + "../-", "read"));







 264     }
 265     
 266     /**
 267      * Restore the system property.

 268      */
 269     @AfterGroups (groups = {"readLocalFiles"})
 270     public void restoreFilePermissions() {
 271         setPermissions();







 272     }
 273 
 274     /**
 275      * Test with an error in XML file, parsing should fail and throw
 276      * SAXException.
 277      *
 278      * @param saxparser a SAXParser instance.
 279      * @throws SAXException If any parse errors occur.
 280      * @throws IOException If an IO error occurs interacting with the 
 281      *         InputStream.
 282      */
 283     @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class,
 284             dataProvider = "parser-provider")
 285     public void testParse13(SAXParser saxparser) throws SAXException, IOException {
 286         try (FileInputStream instream = new FileInputStream(new File(
 287                 XML_DIR, "invalid.xml"))) {
 288             saxparser.parse(instream, new HandlerBase());


 289         }
 290     }
 291 
 292     /**
 293      * Test with a valid in XML file, parser should parse the XML document.

 294      *
 295      * @param saxparser a SAXParser instance.
 296      * @throws SAXException If any parse errors occur.
 297      * @throws IOException If an IO error occurs interacting with the 
 298      *         InputStream.
 299      */
 300     @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
 301     public void testParse14(SAXParser saxparser) throws SAXException, IOException {
 302         saxparser.parse(new File(XML_DIR, "parsertest.xml"), 
 303                 new HandlerBase());





 304     }
 305 
 306     /**
 307      * Test with valid input stream, parser should parse the XML document
 308      * successfully.
 309      *
 310      * @param saxparser a SAXParser instance.
 311      * @throws SAXException If any parse errors occur.
 312      * @throws IOException If an IO error occurs interacting with the 
 313      *         InputStream.
 314      */
 315     @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
 316     public void testParse15(SAXParser saxparser) throws SAXException, IOException {
 317         try (FileInputStream instream = new FileInputStream(new File(XML_DIR, 
 318                 "correct.xml"))) {
 319             saxparser.parse(instream, new HandlerBase());


 320         } 
 321     }
 322 
 323     /**
 324      * Test with valid input source, parser should parse the XML document
 325      * successfully.
 326      *
 327      * @param saxparser a SAXParser instance.
 328      * @throws SAXException If any parse errors occur.
 329      * @throws IOException If an IO error occurs interacting with the 
 330      *         InputStream.
 331      */
 332     @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
 333     public void testParse16(SAXParser saxparser) throws SAXException, IOException {
 334         try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "parsertest.xml"))) {
 335             saxparser.parse(instream, new HandlerBase(), 
 336                     new File(XML_DIR).toURI().toASCIIString());



 337         }
 338     }
 339 
 340     /**
 341      * Test with proper URI, parser should parse successfully.
 342      *
 343      * @param saxparser a SAXParser instance.
 344      * @throws SAXException If any parse errors occur.
 345      * @throws IOException If an IO error occurs interacting with the 
 346      *         InputStream.
 347      */
 348     @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
 349     public void testParse17(SAXParser saxparser) throws SAXException, IOException {
 350         File file = new File(XML_DIR, "correct.xml");
 351         saxparser.parse(file.toURI().toASCIIString(), new HandlerBase());




 352     }
 353 
 354     /**
 355      * Test with XML file that has errors parsing should fail and throw
 356      * SAXException.
 357      *
 358      * @param saxparser a SAXParser instance.
 359      * @throws SAXException If any parse errors occur.
 360      * @throws IOException If an IO error occurs interacting with the 
 361      *         InputStream.
 362      */
 363     @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, dataProvider = "parser-provider")
 364     public void testParse18(SAXParser saxparser) throws SAXException, IOException {
 365         saxparser.parse(new File(XML_DIR, "valid.xml"), new HandlerBase());
 366     }
 367 
 368     /**
 369      * Test with XML file that has no errors Parser should successfully
 370      * parse the XML document.
 371      *
 372      * @param saxparser a SAXParser instance.
 373      * @throws SAXException If any parse errors occur.
 374      * @throws IOException If an IO error occurs interacting with the 
 375      *         InputStream.
 376      */
 377     @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
 378     public void testParse19(SAXParser saxparser) throws SAXException, IOException {
 379         saxparser.parse(new File(XML_DIR, "correct.xml"), new HandlerBase());






 380     }
 381 
 382     /**
 383      * Test with input source attached an invalid XML, parsing should fail
 384      * and throw SAXException.
 385      *
 386      * @param saxparser a SAXParser instance.
 387      * @throws SAXException If any parse errors occur.
 388      * @throws IOException If an IO error occurs interacting with the 
 389      *         InputStream.
 390      */
 391     @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, dataProvider = "parser-provider")
 392     public void testParse20(SAXParser saxparser) throws SAXException, IOException {
 393         try(FileInputStream instream = new FileInputStream(new File(XML_DIR, 
 394                 "invalid.xml"))) {
 395             saxparser.parse(new InputSource(instream), new HandlerBase());
 396         }
 397     }
 398 
 399     /**
 400      * Test with input source attached an valid XML, parser should
 401      * successfully parse the XML document.
 402      *
 403      * @param saxparser a SAXParser instance.
 404      * @throws SAXException If any parse errors occur.
 405      * @throws IOException If an IO error occurs interacting with the 
 406      *         InputStream.
 407      */
 408     @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
 409     public void testParse21(SAXParser saxparser) throws SAXException, IOException {
 410         try (FileInputStream instream = new FileInputStream(new File(XML_DIR, 
 411                 "correct.xml"))) {
 412             saxparser.parse(new InputSource(instream), new HandlerBase());




 413         }
 414     }
 415 
 416     /**
 417      * Test with an error in xml file, parsing should fail and throw
 418      * SAXException.
 419      *
 420      * @param saxparser a SAXParser instance.
 421      * @throws SAXException If any parse errors occur.
 422      * @throws IOException If an IO error occurs interacting with the 
 423      *         InputStream.
 424      */
 425     @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, dataProvider = "parser-provider")
 426     public void testParse22(SAXParser saxparser) throws SAXException, IOException {
 427         try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "invalid.xml"))) {
 428             saxparser.parse(instream, new DefaultHandler());



 429         }
 430     }
 431 
 432     /**
 433      * Test with valid input stream, parser should parse the XML document
 434      * successfully.
 435      *
 436      * @param saxparser a SAXParser instance.
 437      * @throws SAXException If any parse errors occur.
 438      * @throws IOException If an IO error occurs interacting with the 
 439      *         InputStream.
 440      */
 441     @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
 442     public void testParse23(SAXParser saxparser) throws SAXException, IOException {

 443         DefaultHandler handler = new DefaultHandler();
 444         saxparser.parse(new File(XML_DIR, "parsertest.xml"), handler);




 445     }
 446 
 447     /**
 448      * Test with valid input stream, parser should parse the XML document
 449      * successfully.
 450      *
 451      * @param saxparser a SAXParser instance.
 452      * @throws SAXException If any parse errors occur.
 453      * @throws IOException If an IO error occurs interacting with the 
 454      *         InputStream.
 455      */
 456     @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
 457     public void testParse24(SAXParser saxparser) throws SAXException, IOException {
 458         try (FileInputStream instream = new FileInputStream(new File(XML_DIR, 
 459                 "correct.xml"))) {
 460             DefaultHandler handler = new DefaultHandler();
 461             saxparser.parse(instream, handler);



 462         }
 463     }
 464 
 465     /**
 466      * Test with valid input source, parser should parse the XML document
 467      * successfully.
 468      *
 469      * @param saxparser a SAXParser instance.
 470      * @throws SAXException If any parse errors occur.
 471      * @throws IOException If an IO error occurs interacting with the 
 472      *         InputStream.
 473      */
 474     @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
 475     public void testParse25(SAXParser saxparser) throws SAXException, IOException {
 476         try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "parsertest.xml"))) {
 477             saxparser.parse(instream, new DefaultHandler(), 
 478                 new File(XML_DIR).toURI().toASCIIString());



 479         }
 480     }
 481 
 482     /**
 483      * Test with proper URI, parser should parse successfully.

 484      *
 485      * @param saxparser a SAXParser instance.
 486      * @throws SAXException If any parse errors occur.
 487      * @throws IOException If an IO error occurs interacting with the 
 488      *         InputStream.
 489      */
 490     @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
 491     public void testParse26(SAXParser saxparser) throws SAXException, IOException {
 492         File file = new File(XML_DIR, "correct.xml");
 493         saxparser.parse(file.toURI().toASCIIString(), new DefaultHandler());




 494     }
 495 
 496     /**
 497      * Test with XML file that has errors, parsing should fail and throw
 498      * SAXException.
 499      *
 500      * @param saxparser a SAXParser instance.
 501      * @throws SAXException If any parse errors occur.
 502      * @throws IOException If an IO error occurs interacting with the 
 503      *         InputStream.
 504      */
 505     @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, dataProvider = "parser-provider")
 506     public void testParse27(SAXParser saxparser) throws SAXException, IOException {
 507         saxparser.parse(new File(XML_DIR, "valid.xml"), new DefaultHandler());
 508     }
 509 
 510     /**
 511      * Test with XML file that has no errors, parser should successfully
 512      * parse the XML document.
 513      *
 514      * @param saxparser a SAXParser instance.
 515      * @throws SAXException If any parse errors occur.
 516      * @throws IOException If an IO error occurs interacting with the 
 517      *         InputStream.
 518      */
 519     @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
 520     public void testParse28(SAXParser saxparser) throws SAXException, IOException {
 521         saxparser.parse(new File(XML_DIR, "correct.xml"), new DefaultHandler());
 522     }
 523 
 524     /**
 525      * Test with an invalid XML file, parser should throw SAXException.
 526      *
 527      * @param saxparser a SAXParser instance.
 528      * @throws SAXException If any parse errors occur.
 529      * @throws IOException If an IO error occurs interacting with the 
 530      *         InputStream.
 531      */
 532     @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, 
 533             dataProvider = "parser-provider")
 534     public void testParse29(SAXParser saxparser) throws SAXException, IOException {
 535         try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "invalid.xml"))) {
 536             saxparser.parse(new InputSource(instream), new DefaultHandler());
 537         }
 538     }
 539 
 540     /**
 541      * Test case to parse an XML file that not use namespaces.
 542      *
 543      * @param saxparser a SAXParser instance.
 544      * @throws SAXException If any parse errors occur.
 545      * @throws IOException If an IO error occurs interacting with the 
 546      *         InputStream.
 547      */
 548     @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
 549     public void testParse30(SAXParser saxparser) throws SAXException, IOException {
 550         try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "correct.xml"))) {
 551             saxparser.parse(new InputSource(instream), new DefaultHandler());





 552         }
 553     }
 554 
 555     /**
 556      * Test case to parse an XML file that uses namespaces.
 557      * 
 558      * @throws SAXException If any parse errors occur.
 559      * @throws IOException If an IO error occurs interacting with the 
 560      *         InputStream.
 561      * @throws ParserConfigurationException if a DocumentBuilder cannot be 
 562      *         created which satisfies the configuration requested.
 563      */
 564     @Test(groups = {"readLocalFiles"})
 565     public void testParse31() throws SAXException, IOException, ParserConfigurationException {
 566         try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "ns4.xml"))) {
 567             SAXParserFactory spf = SAXParserFactory.newInstance();
 568             spf.setNamespaceAware(true);
 569             spf.newSAXParser().parse(instream, new HandlerBase());





 570         }
 571     }
 572 }
< prev index next >