< prev index next >

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

Print this page




   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 jaxp.library.JAXPTestUtilities.failUnexpected;
  27 import static org.testng.Assert.assertFalse;
  28 import static org.testng.Assert.assertTrue;
  29 
  30 import javax.xml.parsers.ParserConfigurationException;
  31 import javax.xml.parsers.SAXParser;
  32 import javax.xml.parsers.SAXParserFactory;
  33 
  34 import org.testng.annotations.Test;
  35 import org.xml.sax.SAXException;
  36 import org.xml.sax.SAXNotRecognizedException;
  37 import org.xml.sax.SAXNotSupportedException;
  38 
  39 /**
  40  * Class containing the test cases for SAXParserFactory API
  41  */
  42 public class SAXParserFactTest {
  43 
  44     private static final String NAMESPACES = "http://xml.org/sax/features/namespaces";
  45     private static final String NAMESPACE_PREFIXES = "http://xml.org/sax/features/namespace-prefixes";
  46     private static final String STRING_INTERNING = "http://xml.org/sax/features/string-interning";
  47     private static final String VALIDATION = "http://xml.org/sax/features/validation";
  48     private static final String EXTERNAL_G_ENTITIES = "http://xml.org/sax/features/external-general-entities";
  49     private static final String EXTERNAL_P_ENTITIES = "http://xml.org/sax/features/external-parameter-entities";
  50 
  51     /**
  52      * Testcase to test if newSAXParser() method returns SAXParser.



  53      */
  54     @Test
  55     public void testParser01() {
  56         try {
  57             SAXParserFactory spf = SAXParserFactory.newInstance();
  58             SAXParser saxparser = spf.newSAXParser();
  59         } catch (ParserConfigurationException | SAXException e) {
  60             failUnexpected(e);
  61         }
  62     }
  63 
  64     /**
  65      * Testcase to test the default functionality (No validation) of the parser.
  66      */
  67     @Test
  68     public void testValidate01() {
  69         SAXParserFactory spf = SAXParserFactory.newInstance();
  70         assertFalse(spf.isValidating());
  71     }
  72 
  73     /**
  74      * Testcase to test the functionality of setValidating and isvalidating
  75      * methods.
  76      */
  77     @Test
  78     public void testValidate02() {
  79         SAXParserFactory spf = SAXParserFactory.newInstance();
  80         spf.setValidating(true);
  81         assertTrue(spf.isValidating());
  82     }
  83 
  84     /**
  85      * Parser should not be namespaceaware by default.
  86      */
  87     @Test
  88     public void testNamespace01() {
  89         SAXParserFactory spf = SAXParserFactory.newInstance();
  90         assertFalse(spf.isNamespaceAware());
  91     }
  92 
  93     /**
  94      * Testcase to test the functionality of setNamespaceAware and
  95      * isNamespaceAware methods.
  96      */
  97     @Test
  98     public void testNamespace02() {
  99         SAXParserFactory spf = SAXParserFactory.newInstance();
 100         spf.setNamespaceAware(true);
 101         assertTrue(spf.isNamespaceAware());
 102     }
 103 
 104     /**
 105      * Testcase to test the functionality of setNamespaceAware and getFeature()
 106      * methods for namespaces property.



 107      */
 108     @Test
 109     public void testFeature01() {
 110         try {
 111             SAXParserFactory spf = SAXParserFactory.newInstance();
 112             assertFalse(spf.getFeature(NAMESPACES));
 113 
 114             spf.setNamespaceAware(true);
 115             assertTrue(spf.getFeature(NAMESPACES));
 116         } catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
 117             failUnexpected(e);
 118         }
 119     }
 120 
 121     /**
 122      * Testcase to test the functionality of setFeature and getFeature methods
 123      * for namespaces property.



 124      */
 125     @Test
 126     public void testFeature02() {
 127         try {
 128             SAXParserFactory spf = SAXParserFactory.newInstance();
 129 
 130             spf.setFeature(NAMESPACES, true);
 131             assertTrue(spf.getFeature(NAMESPACES));
 132 
 133             spf.setFeature(NAMESPACES, false);
 134             assertFalse(spf.getFeature(NAMESPACES));
 135         } catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
 136             failUnexpected(e);
 137         }
 138     }
 139 
 140     /**
 141      * Testcase to test the functionality of setFeature and getFeature methods
 142      * for namespace-prefixes property.



 143      */
 144     @Test
 145     public void testFeature03() {
 146         try {
 147             SAXParserFactory spf = SAXParserFactory.newInstance();
 148 
 149             spf.setFeature(NAMESPACE_PREFIXES, true);
 150             assertTrue(spf.getFeature(NAMESPACE_PREFIXES));
 151 
 152             spf.setFeature(NAMESPACE_PREFIXES, false);
 153             assertFalse(spf.getFeature(NAMESPACE_PREFIXES));
 154         } catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
 155             failUnexpected(e);
 156         }
 157     }
 158 
 159     /**
 160      * Testcase to test the functionality of getFeature method for
 161      * string-interning property.



 162      */
 163     @Test
 164     public void testFeature04() {
 165         try {
 166             SAXParserFactory spf = SAXParserFactory.newInstance();
 167             assertTrue(spf.getFeature(STRING_INTERNING));
 168         } catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
 169             failUnexpected(e);
 170         }
 171     }
 172 
 173     /**
 174      * Testcase to test the functionality of getFeature and setValidating
 175      * methods for validation property.



 176      */
 177     @Test
 178     public void testFeature05() {
 179         try {
 180             SAXParserFactory spf = SAXParserFactory.newInstance();
 181             assertFalse(spf.getFeature(VALIDATION));
 182             spf.setValidating(true);
 183             assertTrue(spf.getFeature(VALIDATION));
 184         } catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
 185             failUnexpected(e);
 186         }
 187 
 188     }
 189 
 190     /**
 191      * Testcase to test the functionality of setFeature and getFeature methods
 192      * for validation property.



 193      */
 194     @Test
 195     public void testFeature06() {
 196         try {
 197             SAXParserFactory spf = SAXParserFactory.newInstance();
 198 
 199             spf.setFeature(VALIDATION, true);
 200             assertTrue(spf.getFeature(VALIDATION));
 201 
 202             spf.setFeature(VALIDATION, false);
 203             assertFalse(spf.getFeature(VALIDATION));
 204         } catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
 205             failUnexpected(e);
 206         }
 207 
 208     }
 209 
 210     /**
 211      * Testcase to test the functionality of getFeature method for
 212      * external-general-entities property.



 213      */
 214     @Test
 215     public void testFeature07() {
 216         try {
 217             SAXParserFactory spf = SAXParserFactory.newInstance();
 218             assertTrue(spf.getFeature(EXTERNAL_G_ENTITIES));
 219         } catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
 220             failUnexpected(e);
 221         }
 222 
 223     }
 224 
 225     /**
 226      * Testcase to test the functionality of setFeature and getFeature methods
 227      * for external-general-entities property.



 228      */
 229     @Test
 230     public void testFeature08() {
 231         try {
 232             SAXParserFactory spf = SAXParserFactory.newInstance();
 233             spf.setFeature(EXTERNAL_G_ENTITIES, false);
 234             assertFalse(spf.getFeature(EXTERNAL_G_ENTITIES));
 235         } catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
 236             failUnexpected(e);
 237         }
 238     }
 239 
 240     /**
 241      * Testcase to test the functionality of getFeature method for
 242      * external-parameter-entities property.



 243      */
 244     @Test
 245     public void testFeature09() {
 246         try {
 247             SAXParserFactory spf = SAXParserFactory.newInstance();
 248             assertTrue(spf.getFeature(EXTERNAL_P_ENTITIES));
 249         } catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
 250             failUnexpected(e);
 251         }
 252     }
 253 
 254     /**
 255      * Testcase to test the functionality of setFeature method for
 256      * external-parameter-entitie property.



 257      */
 258     @Test
 259     public void testFeature10() {
 260         try {
 261             SAXParserFactory spf = SAXParserFactory.newInstance();
 262             spf.setFeature(EXTERNAL_P_ENTITIES, false);
 263         } catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
 264             failUnexpected(e);
 265         }
 266 
 267     }
 268 }


   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 import static org.testng.Assert.assertFalse;
  26 import static org.testng.Assert.assertTrue;

  27 import javax.xml.parsers.ParserConfigurationException;

  28 import javax.xml.parsers.SAXParserFactory;
  29 import jaxp.library.JAXPBaseTest;
  30 import org.testng.annotations.Test;
  31 import org.xml.sax.SAXException;


  32 
  33 /**
  34  * Class containing the test cases for SAXParserFactory API.
  35  */
  36 public class SAXParserFactTest extends JAXPBaseTest {
  37 
  38     private static final String NAMESPACES = "http://xml.org/sax/features/namespaces";
  39     private static final String NAMESPACE_PREFIXES = "http://xml.org/sax/features/namespace-prefixes";
  40     private static final String STRING_INTERNING = "http://xml.org/sax/features/string-interning";
  41     private static final String VALIDATION = "http://xml.org/sax/features/validation";
  42     private static final String EXTERNAL_G_ENTITIES = "http://xml.org/sax/features/external-general-entities";
  43     private static final String EXTERNAL_P_ENTITIES = "http://xml.org/sax/features/external-parameter-entities";
  44 
  45     /**
  46      * Test if newSAXParser() method returns SAXParser.
  47      * @throws ParserConfigurationException if a DocumentBuilder cannot be 
  48      *         created which satisfies the configuration requested.
  49      * @throws SAXException If any parse errors occur.
  50      */
  51     @Test
  52     public void testParser01() throws ParserConfigurationException, 
  53             SAXException {
  54         SAXParserFactory spf = SAXParserFactory.newInstance();
  55         spf.newSAXParser();



  56     }
  57 
  58     /**
  59      * Test the default functionality (No validation) of the parser.
  60      */
  61     @Test
  62     public void testValidate01() {
  63         SAXParserFactory spf = SAXParserFactory.newInstance();
  64         assertFalse(spf.isValidating());
  65     }
  66 
  67     /**
  68      * Test the functionality of setValidating and isvalidating
  69      * methods.
  70      */
  71     @Test
  72     public void testValidate02() {
  73         SAXParserFactory spf = SAXParserFactory.newInstance();
  74         spf.setValidating(true);
  75         assertTrue(spf.isValidating());
  76     }
  77 
  78     /**
  79      * Parser should not be namespace-aware by default.
  80      */
  81     @Test
  82     public void testNamespace01() {
  83         SAXParserFactory spf = SAXParserFactory.newInstance();
  84         assertFalse(spf.isNamespaceAware());
  85     }
  86 
  87     /**
  88      * Test the functionality of setNamespaceAware and
  89      * isNamespaceAware methods.
  90      */
  91     @Test
  92     public void testNamespace02() {
  93         SAXParserFactory spf = SAXParserFactory.newInstance();
  94         spf.setNamespaceAware(true);
  95         assertTrue(spf.isNamespaceAware());
  96     }
  97 
  98     /**
  99      * Test the functionality of setNamespaceAware and getFeature()
 100      * methods for namespaces property.
 101      * @throws ParserConfigurationException if a DocumentBuilder cannot be 
 102      *         created which satisfies the configuration requested.
 103      * @throws SAXException If any parse errors occur.
 104      */
 105     @Test
 106     public void testFeature01() throws ParserConfigurationException, 
 107             SAXException {
 108         SAXParserFactory spf = SAXParserFactory.newInstance();
 109         assertFalse(spf.getFeature(NAMESPACES));
 110 
 111         spf.setNamespaceAware(true);
 112         assertTrue(spf.getFeature(NAMESPACES));



 113     }
 114 
 115     /**
 116      * Test the functionality of setFeature and getFeature methods
 117      * for namespaces property.
 118      * @throws ParserConfigurationException if a DocumentBuilder cannot be 
 119      *         created which satisfies the configuration requested.
 120      * @throws SAXException If any parse errors occur.
 121      */
 122     @Test
 123     public void testFeature02() throws ParserConfigurationException, 
 124             SAXException {
 125         SAXParserFactory spf = SAXParserFactory.newInstance();
 126 
 127         spf.setFeature(NAMESPACES, true);
 128         assertTrue(spf.getFeature(NAMESPACES));
 129 
 130         spf.setFeature(NAMESPACES, false);
 131         assertFalse(spf.getFeature(NAMESPACES));



 132     }
 133 
 134     /**
 135      * Test the functionality of setFeature and getFeature methods
 136      * for namespace-prefixes property.
 137      * @throws ParserConfigurationException if a DocumentBuilder cannot be 
 138      *         created which satisfies the configuration requested.
 139      * @throws SAXException If any parse errors occur.
 140      */
 141     @Test
 142     public void testFeature03() throws ParserConfigurationException, 
 143             SAXException {
 144         SAXParserFactory spf = SAXParserFactory.newInstance();
 145 
 146         spf.setFeature(NAMESPACE_PREFIXES, true);
 147         assertTrue(spf.getFeature(NAMESPACE_PREFIXES));
 148 
 149         spf.setFeature(NAMESPACE_PREFIXES, false);
 150         assertFalse(spf.getFeature(NAMESPACE_PREFIXES));



 151     }
 152 
 153     /**
 154      * Test the functionality of getFeature method for
 155      * string-interning property.
 156      * @throws ParserConfigurationException if a DocumentBuilder cannot be 
 157      *         created which satisfies the configuration requested.
 158      * @throws SAXException If any parse errors occur.
 159      */
 160     @Test
 161     public void testFeature04() throws ParserConfigurationException, 
 162             SAXException {
 163         SAXParserFactory spf = SAXParserFactory.newInstance();
 164         assertTrue(spf.getFeature(STRING_INTERNING));



 165     }
 166 
 167     /**
 168      * Test the functionality of getFeature and setValidating
 169      * methods for validation property.
 170      * @throws ParserConfigurationException if a DocumentBuilder cannot be 
 171      *         created which satisfies the configuration requested.
 172      * @throws SAXException If any parse errors occur.
 173      */
 174     @Test
 175     public void testFeature05() throws ParserConfigurationException, 
 176             SAXException {
 177         SAXParserFactory spf = SAXParserFactory.newInstance();
 178         assertFalse(spf.getFeature(VALIDATION));
 179         spf.setValidating(true);
 180         assertTrue(spf.getFeature(VALIDATION));




 181     }
 182 
 183     /**
 184      * Test the functionality of setFeature and getFeature methods
 185      * for validation property.
 186      * @throws ParserConfigurationException if a DocumentBuilder cannot be 
 187      *         created which satisfies the configuration requested.
 188      * @throws SAXException If any parse errors occur.
 189      */
 190     @Test
 191     public void testFeature06() throws ParserConfigurationException, 
 192             SAXException {
 193         SAXParserFactory spf = SAXParserFactory.newInstance();

 194         spf.setFeature(VALIDATION, true);
 195         assertTrue(spf.getFeature(VALIDATION));

 196         spf.setFeature(VALIDATION, false);
 197         assertFalse(spf.getFeature(VALIDATION));




 198     }
 199 
 200     /**
 201      * Test the functionality of getFeature method for
 202      * external-general-entities property.
 203      * @throws ParserConfigurationException if a DocumentBuilder cannot be 
 204      *         created which satisfies the configuration requested.
 205      * @throws SAXException If any parse errors occur.
 206      */
 207     @Test
 208     public void testFeature07() throws ParserConfigurationException, 
 209             SAXException {
 210             SAXParserFactory spf = SAXParserFactory.newInstance();
 211             assertTrue(spf.getFeature(EXTERNAL_G_ENTITIES));



 212 
 213     }
 214 
 215     /**
 216      * Test the functionality of setFeature and getFeature methods
 217      * for external-general-entities property.
 218      * @throws ParserConfigurationException if a DocumentBuilder cannot be 
 219      *         created which satisfies the configuration requested.
 220      * @throws SAXException If any parse errors occur.
 221      */
 222     @Test
 223     public void testFeature08() throws ParserConfigurationException, 
 224             SAXException {
 225         SAXParserFactory spf = SAXParserFactory.newInstance();
 226         spf.setFeature(EXTERNAL_G_ENTITIES, false);
 227         assertFalse(spf.getFeature(EXTERNAL_G_ENTITIES));



 228     }
 229 
 230     /**
 231      * Test the functionality of getFeature method for
 232      * external-parameter-entities property.
 233      * @throws ParserConfigurationException if a DocumentBuilder cannot be 
 234      *         created which satisfies the configuration requested.
 235      * @throws SAXException If any parse errors occur.
 236      */
 237     @Test
 238     public void testFeature09() throws ParserConfigurationException, 
 239             SAXException {
 240         SAXParserFactory spf = SAXParserFactory.newInstance();
 241         assertTrue(spf.getFeature(EXTERNAL_P_ENTITIES));



 242     }
 243 
 244     /**
 245      * Test the functionality of setFeature method for
 246      * external-parameter-entitie property.
 247      * @throws ParserConfigurationException if a DocumentBuilder cannot be 
 248      *         created which satisfies the configuration requested.
 249      * @throws SAXException If any parse errors occur.
 250      */
 251     @Test
 252     public void testFeature10() throws ParserConfigurationException, 
 253             SAXException {
 254         SAXParserFactory spf = SAXParserFactory.newInstance();
 255         spf.setFeature(EXTERNAL_P_ENTITIES, false);
 256         assertFalse(spf.getFeature(EXTERNAL_P_ENTITIES));



 257     }
 258 }
< prev index next >