< prev index next >

test/javax/xml/jaxp/functional/org/xml/sax/ptests/NSTableTest.java

Print this page


   1 /*
   2  * Copyright (c) 2014, 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 package org.xml.sax.ptests;
  24 
  25 import javax.xml.parsers.ParserConfigurationException;
  26 import javax.xml.parsers.SAXParser;
  27 import javax.xml.parsers.SAXParserFactory;
  28 import static jaxp.library.JAXPTestUtilities.failUnexpected;
  29 import static org.testng.Assert.assertFalse;
  30 import static org.testng.Assert.assertTrue;
  31 import org.testng.annotations.Test;
  32 import org.xml.sax.SAXException;
  33 import org.xml.sax.SAXNotRecognizedException;
  34 import org.xml.sax.SAXNotSupportedException;
  35 import org.xml.sax.XMLReader;
  36 
  37 /**
  38  * Class containing the test cases for Namespace Table defined at
  39  * http://www.megginson.com/SAX/Java/namespaces.html
  40  */
  41 public class NSTableTest01 {
  42     private static final String NAMESPACES =
  43                         "http://xml.org/sax/features/namespaces";
  44     private static final String NAMESPACE_PREFIXES =
  45                         "http://xml.org/sax/features/namespace-prefixes";
  46 
  47     /**
  48      * Here namespace processing and namespace-prefixes are enabled.
  49      * The testcase tests XMLReader for this.


  50      */
  51     @Test
  52     public void xrNSTable01() {
  53         try {
  54             SAXParserFactory spf = SAXParserFactory.newInstance();
  55             spf.setNamespaceAware(true);
  56             SAXParser saxParser = spf.newSAXParser();
  57 
  58             XMLReader xmlReader = saxParser.getXMLReader();
  59             xmlReader.setFeature(NAMESPACE_PREFIXES, true);
  60 
  61             assertTrue(xmlReader.getFeature(NAMESPACES));
  62             assertTrue(xmlReader.getFeature(NAMESPACE_PREFIXES));
  63         } catch (ParserConfigurationException | SAXException ex) {
  64             failUnexpected(ex);
  65         }
  66     }
  67 
  68     /**
  69      * Here namespace processing is enabled. This will make namespace-prefixes
  70      * disabled. The testcase tests XMLReader for this.


  71      */
  72     @Test
  73     public void xrNSTable02() {
  74         try {
  75             SAXParserFactory spf = SAXParserFactory.newInstance();
  76             spf.setNamespaceAware(true);
  77             SAXParser saxParser = spf.newSAXParser();
  78 
  79             XMLReader xmlReader = saxParser.getXMLReader();
  80             assertTrue(xmlReader.getFeature(NAMESPACES));
  81             assertFalse(xmlReader.getFeature(NAMESPACE_PREFIXES));
  82         } catch (ParserConfigurationException | SAXException ex) {
  83             failUnexpected(ex);
  84         }
  85 
  86     }
  87 
  88     /**
  89      * Here namespace processing is disabled. This will make namespace-prefixes
  90      * enabled. The testcase tests XMLReader for this.


  91      */
  92     @Test
  93     public void xrNSTable03() {
  94         try {
  95             SAXParserFactory spf = SAXParserFactory.newInstance();
  96             SAXParser saxParser = spf.newSAXParser();
  97             XMLReader xmlReader = saxParser.getXMLReader();
  98             assertFalse(xmlReader.getFeature(NAMESPACES));
  99             assertTrue(xmlReader.getFeature(NAMESPACE_PREFIXES));
 100         } catch (ParserConfigurationException | SAXException ex) {
 101             failUnexpected(ex);
 102         }
 103     }
 104 
 105     /**
 106      * Here namespace processing is disabled, and namespace-prefixes is
 107      * disabled. This will make namespace processing on.The testcase tests
 108      * XMLReader for this.  This behavior only apply to crimson, not
 109      * xerces


 110      */
 111     @Test
 112     public void xrNSTable04() {
 113         try {
 114             SAXParserFactory spf = SAXParserFactory.newInstance();
 115             SAXParser saxParser = spf.newSAXParser();
 116             XMLReader xmlReader = saxParser.getXMLReader();
 117             xmlReader.setFeature(NAMESPACE_PREFIXES, false);
 118 
 119             assertFalse(xmlReader.getFeature(NAMESPACE_PREFIXES));
 120         } catch (ParserConfigurationException | SAXException ex) {
 121             failUnexpected(ex);
 122         }
 123     }
 124 
 125     /**
 126      * Here namespace processing and namespace-prefixes are enabled.
 127      * The testcase tests SAXParserFactory for this.


 128      */
 129     @Test
 130     public void spNSTable01() {
 131         try {
 132             SAXParserFactory spf = SAXParserFactory.newInstance();
 133             spf.setNamespaceAware(true);
 134             spf.setFeature(NAMESPACE_PREFIXES,true);
 135             assertTrue(spf.getFeature(NAMESPACES));
 136             assertTrue(spf.getFeature(NAMESPACE_PREFIXES));
 137         } catch (ParserConfigurationException | SAXNotRecognizedException
 138                 | SAXNotSupportedException ex) {
 139             failUnexpected(ex);
 140         }
 141     }
 142 
 143     /**
 144      * Here namespace processing is enabled. This will make namespace-prefixes
 145      * disabled. The testcase tests SAXParserFactory for this.


 146      */
 147     @Test
 148     public void spNSTable02() {
 149         try {
 150             SAXParserFactory spf = SAXParserFactory.newInstance();
 151             spf.setNamespaceAware(true);
 152             assertTrue(spf.getFeature(NAMESPACES));
 153             assertFalse(spf.getFeature(NAMESPACE_PREFIXES));
 154         } catch (ParserConfigurationException | SAXNotRecognizedException
 155                 | SAXNotSupportedException ex) {
 156             failUnexpected(ex);
 157         }
 158     }
 159 
 160     /**
 161      * Here namespace processing is disabled. This will make namespace-prefixes
 162      * enabled. The testcase tests SAXParserFactory for this.


 163      */
 164     @Test
 165     public void spNSTable03() {
 166         try {
 167             SAXParserFactory spf = SAXParserFactory.newInstance();
 168             assertFalse(spf.getFeature(NAMESPACES));
 169             assertTrue(spf.getFeature(NAMESPACE_PREFIXES));
 170         } catch (ParserConfigurationException | SAXNotRecognizedException
 171                 | SAXNotSupportedException ex) {
 172             failUnexpected(ex);
 173         }
 174     }
 175     /**
 176      * Here namespace processing is disabled, and namespace-prefixes is
 177      * disabled. This will make namespace processing on.The testcase tests
 178      * SAXParserFactory for this.  This behavior only apply to crimson,
 179      * not xerces.


 180      */
 181     @Test
 182     public void spNSTable04() {
 183         try {
 184             SAXParserFactory spf = SAXParserFactory.newInstance();
 185             spf.setFeature(NAMESPACE_PREFIXES, false);
 186 
 187             assertFalse(spf.getFeature(NAMESPACE_PREFIXES));
 188         } catch (ParserConfigurationException | SAXNotRecognizedException
 189                 | SAXNotSupportedException ex) {
 190             failUnexpected(ex);
 191         }
 192     }
 193 }
   1 /*
   2  * Copyright (c) 2003, 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 package org.xml.sax.ptests;
  24 

  25 import javax.xml.parsers.SAXParser;
  26 import javax.xml.parsers.SAXParserFactory;
  27 import jaxp.library.JAXPBaseTest;
  28 import static org.testng.Assert.assertFalse;
  29 import static org.testng.Assert.assertTrue;
  30 import org.testng.annotations.Test;



  31 import org.xml.sax.XMLReader;
  32 
  33 /**
  34  * Class containing the test cases for Namespace Table defined at
  35  * http://www.megginson.com/SAX/Java/namespaces.html
  36  */
  37 public class NSTableTest extends JAXPBaseTest {
  38     private static final String NAMESPACES =
  39                         "http://xml.org/sax/features/namespaces";
  40     private static final String NAMESPACE_PREFIXES =
  41                         "http://xml.org/sax/features/namespace-prefixes";
  42 
  43     /**
  44      * Here namespace processing and namespace-prefixes are enabled.
  45      * The testcase tests XMLReader for this.
  46      * 
  47      * @throws Exception If any errors occur.
  48      */
  49     @Test
  50     public void xrNSTable01() throws Exception {

  51         SAXParserFactory spf = SAXParserFactory.newInstance();
  52         spf.setNamespaceAware(true);
  53         SAXParser saxParser = spf.newSAXParser();
  54 
  55         XMLReader xmlReader = saxParser.getXMLReader();
  56         xmlReader.setFeature(NAMESPACE_PREFIXES, true);
  57 
  58         assertTrue(xmlReader.getFeature(NAMESPACES));
  59         assertTrue(xmlReader.getFeature(NAMESPACE_PREFIXES));



  60     }
  61 
  62     /**
  63      * Here namespace processing is enabled. This will make namespace-prefixes
  64      * disabled. The testcase tests XMLReader for this.
  65      * 
  66      * @throws Exception If any errors occur.
  67      */
  68     @Test
  69     public void xrNSTable02() throws Exception {

  70         SAXParserFactory spf = SAXParserFactory.newInstance();
  71         spf.setNamespaceAware(true);

  72 
  73         XMLReader xmlReader = spf.newSAXParser().getXMLReader();
  74         assertTrue(xmlReader.getFeature(NAMESPACES));
  75         assertFalse(xmlReader.getFeature(NAMESPACE_PREFIXES));




  76     }
  77 
  78     /**
  79      * Here namespace processing is disabled. This will make namespace-prefixes
  80      * enabled. The testcase tests XMLReader for this.
  81      * 
  82      * @throws Exception If any errors occur.
  83      */
  84     @Test
  85     public void xrNSTable03() throws Exception {
  86         XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();



  87         assertFalse(xmlReader.getFeature(NAMESPACES));
  88         assertTrue(xmlReader.getFeature(NAMESPACE_PREFIXES));



  89     }
  90 
  91     /**
  92      * Here namespace processing is disabled, and namespace-prefixes is
  93      * disabled. This will make namespace processing on.The testcase tests
  94      * XMLReader for this.  This behavior only apply to crimson, not
  95      * XERCES.
  96      * 
  97      * @throws Exception If any errors occur.
  98      */
  99     @Test
 100     public void xrNSTable04() throws Exception {
 101         XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();



 102         xmlReader.setFeature(NAMESPACE_PREFIXES, false);

 103         assertFalse(xmlReader.getFeature(NAMESPACE_PREFIXES));



 104     }
 105 
 106     /**
 107      * Here namespace processing and namespace-prefixes are enabled.
 108      * The testcase tests SAXParserFactory for this.
 109      * 
 110      * @throws Exception If any errors occur.
 111      */
 112     @Test
 113     public void spNSTable01() throws Exception {

 114         SAXParserFactory spf = SAXParserFactory.newInstance();
 115         spf.setNamespaceAware(true);
 116         spf.setFeature(NAMESPACE_PREFIXES,true);
 117         assertTrue(spf.getFeature(NAMESPACES));
 118         assertTrue(spf.getFeature(NAMESPACE_PREFIXES));




 119     }
 120 
 121     /**
 122      * Here namespace processing is enabled. This will make namespace-prefixes
 123      * disabled. The testcase tests SAXParserFactory for this.
 124      * 
 125      * @throws Exception If any errors occur.
 126      */
 127     @Test
 128     public void spNSTable02() throws Exception {

 129         SAXParserFactory spf = SAXParserFactory.newInstance();
 130         spf.setNamespaceAware(true);
 131         assertTrue(spf.getFeature(NAMESPACES));
 132         assertFalse(spf.getFeature(NAMESPACE_PREFIXES));




 133     }
 134 
 135     /**
 136      * Here namespace processing is disabled. This will make namespace-prefixes
 137      * enabled. The testcase tests SAXParserFactory for this.
 138      * 
 139      * @throws Exception If any errors occur.
 140      */
 141     @Test
 142     public void spNSTable03() throws Exception {

 143         SAXParserFactory spf = SAXParserFactory.newInstance();
 144         assertFalse(spf.getFeature(NAMESPACES));
 145         assertTrue(spf.getFeature(NAMESPACE_PREFIXES));




 146     }
 147     /**
 148      * Here namespace processing is disabled, and namespace-prefixes is
 149      * disabled. This will make namespace processing on.The testcase tests
 150      * SAXParserFactory for this.  This behavior only apply to crimson,
 151      * not xerces.
 152      * 
 153      * @throws Exception If any errors occur.
 154      */
 155     @Test
 156     public void spNSTable04() throws Exception {

 157         SAXParserFactory spf = SAXParserFactory.newInstance();
 158         spf.setFeature(NAMESPACE_PREFIXES, false);

 159         assertFalse(spf.getFeature(NAMESPACE_PREFIXES));




 160     }
 161 }
< prev index next >