< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1999, 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 javax.xml.parsers.ptests;
  25 

  26 import static org.testng.Assert.assertFalse;
  27 import static org.testng.Assert.assertTrue;


  28 import java.io.File;
  29 import java.io.FilePermission;
  30 import javax.xml.parsers.SAXParser;
  31 import javax.xml.parsers.SAXParserFactory;
  32 import static javax.xml.parsers.ptests.ParserTestConst.XML_DIR;
  33 import jaxp.library.JAXPFileReadOnlyBaseTest;
  34 import static org.testng.Assert.fail;
  35 import org.testng.annotations.AfterGroups;
  36 import org.testng.annotations.BeforeGroups;
  37 import org.testng.annotations.DataProvider;

  38 import org.testng.annotations.Test;
  39 import org.xml.sax.SAXException;
  40 
  41 /**
  42  * Class contains the test cases for SAXParser API
  43  */
  44 public class SAXParserTest03 extends JAXPFileReadOnlyBaseTest {

  45 
  46     /**
  47      * Provide SAXParserFactory.
  48      *
  49      * @return a dimensional contains.
  50      */
  51     @DataProvider(name = "input-provider")
  52     public Object[][] getFactory() {
  53         SAXParserFactory spf = SAXParserFactory.newInstance();
  54         spf.setValidating(true);
  55         return new Object[][] { { spf, MyErrorHandler.newInstance() } };
  56     }
  57 
  58     /**
  59      * parsertest.xml holds a valid document. This method tests the validating
  60      * parser.
  61      *
  62      * @param spf a Parser factory.
  63      * @param handler an error handler for capturing events.
  64      * @throws Exception If any errors occur.
  65      */
  66     @Test(groups = {"readLocalFiles"}, dataProvider = "input-provider")
  67     public void testParseValidate01(SAXParserFactory spf, MyErrorHandler handler)
  68             throws Exception {
  69             spf.newSAXParser().parse(new File(XML_DIR, "parsertest.xml"), handler);
  70             assertFalse(handler.isErrorOccured());
  71     }
  72 
  73     /**
  74      * validns.xml holds a valid document with XML namespaces in it. This method
  75      * tests the Validating parser with namespace processing on.
  76      *
  77      * @param spf a Parser factory.
  78      * @param handler an error handler for capturing events.
  79      * @throws Exception If any errors occur.
  80      */
  81     @Test(groups = {"readLocalFiles"}, dataProvider = "input-provider")
  82     public void testParseValidate02(SAXParserFactory spf, MyErrorHandler handler)
  83             throws Exception {
  84             spf.setNamespaceAware(true);
  85             spf.newSAXParser().parse(new File(XML_DIR, "validns.xml"), handler);
  86             assertFalse(handler.isErrorOccured());
  87     }
  88 
  89     /**
  90      * invalidns.xml holds an invalid document with XML namespaces in it. This
  91      * method tests the validating parser with namespace processing on. It
  92      * should throw validation error.
  93      *
  94      * @param spf a Parser factory.
  95      * @param handler an error handler for capturing events.
  96      * @throws Exception If any errors occur.
  97      */
  98     @Test(groups = {"readLocalFiles"}, dataProvider = "input-provider")
  99     public void testParseValidate03(SAXParserFactory spf, MyErrorHandler handler)
 100             throws Exception {
 101         try {
 102             spf.setNamespaceAware(true);
 103             SAXParser saxparser = spf.newSAXParser();
 104             saxparser.parse(new File(XML_DIR, "invalidns.xml"), handler);
 105             fail("Expecting SAXException here");
 106         } catch (SAXException e) {
 107             assertTrue(handler.isErrorOccured());
 108         }
 109     }
 110 
 111 }
   1 /*
   2  * Copyright (c) 1999, 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 javax.xml.parsers.ptests;
  25 
  26 import static javax.xml.parsers.ptests.ParserTestConst.XML_DIR;
  27 import static org.testng.Assert.assertFalse;
  28 import static org.testng.Assert.assertTrue;
  29 import static org.testng.Assert.fail;
  30 
  31 import java.io.File;
  32 
  33 import javax.xml.parsers.SAXParser;
  34 import javax.xml.parsers.SAXParserFactory;
  35 




  36 import org.testng.annotations.DataProvider;
  37 import org.testng.annotations.Listeners;
  38 import org.testng.annotations.Test;
  39 import org.xml.sax.SAXException;
  40 
  41 /**
  42  * Class contains the test cases for SAXParser API
  43  */
  44 @Listeners({jaxp.library.FilePolicy.class})
  45 public class SAXParserTest03 {
  46 
  47     /**
  48      * Provide SAXParserFactory.
  49      *
  50      * @return a dimensional contains.
  51      */
  52     @DataProvider(name = "input-provider")
  53     public Object[][] getFactory() {
  54         SAXParserFactory spf = SAXParserFactory.newInstance();
  55         spf.setValidating(true);
  56         return new Object[][] { { spf, MyErrorHandler.newInstance() } };
  57     }
  58 
  59     /**
  60      * parsertest.xml holds a valid document. This method tests the validating
  61      * parser.
  62      *
  63      * @param spf a Parser factory.
  64      * @param handler an error handler for capturing events.
  65      * @throws Exception If any errors occur.
  66      */
  67     @Test(dataProvider = "input-provider")
  68     public void testParseValidate01(SAXParserFactory spf, MyErrorHandler handler)
  69             throws Exception {
  70             spf.newSAXParser().parse(new File(XML_DIR, "parsertest.xml"), handler);
  71             assertFalse(handler.isErrorOccured());
  72     }
  73 
  74     /**
  75      * validns.xml holds a valid document with XML namespaces in it. This method
  76      * tests the Validating parser with namespace processing on.
  77      *
  78      * @param spf a Parser factory.
  79      * @param handler an error handler for capturing events.
  80      * @throws Exception If any errors occur.
  81      */
  82     @Test(dataProvider = "input-provider")
  83     public void testParseValidate02(SAXParserFactory spf, MyErrorHandler handler)
  84             throws Exception {
  85             spf.setNamespaceAware(true);
  86             spf.newSAXParser().parse(new File(XML_DIR, "validns.xml"), handler);
  87             assertFalse(handler.isErrorOccured());
  88     }
  89 
  90     /**
  91      * invalidns.xml holds an invalid document with XML namespaces in it. This
  92      * method tests the validating parser with namespace processing on. It
  93      * should throw validation error.
  94      *
  95      * @param spf a Parser factory.
  96      * @param handler an error handler for capturing events.
  97      * @throws Exception If any errors occur.
  98      */
  99     @Test(dataProvider = "input-provider")
 100     public void testParseValidate03(SAXParserFactory spf, MyErrorHandler handler)
 101             throws Exception {
 102         try {
 103             spf.setNamespaceAware(true);
 104             SAXParser saxparser = spf.newSAXParser();
 105             saxparser.parse(new File(XML_DIR, "invalidns.xml"), handler);
 106             fail("Expecting SAXException here");
 107         } catch (SAXException e) {
 108             assertTrue(handler.isErrorOccured());
 109         }
 110     }
 111 
 112 }
< prev index next >