< prev index next >

test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TfClearParamTest.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 javax.xml.transform.ptests;
  24 
  25 import java.io.File;
  26 import java.io.FileInputStream;
  27 import java.io.FileNotFoundException;
  28 import java.io.IOException;
  29 import javax.xml.parsers.DocumentBuilder;
  30 import javax.xml.parsers.DocumentBuilderFactory;
  31 import javax.xml.parsers.ParserConfigurationException;
  32 import javax.xml.transform.Transformer;
  33 import javax.xml.transform.TransformerConfigurationException;
  34 import javax.xml.transform.TransformerFactory;
  35 import javax.xml.transform.dom.DOMSource;
  36 import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR;
  37 import javax.xml.transform.sax.SAXSource;
  38 import javax.xml.transform.stream.StreamSource;
  39 import static jaxp.library.JAXPTestUtilities.failUnexpected;
  40 import static org.testng.Assert.assertEquals;
  41 import static org.testng.Assert.assertNull;
  42 import org.testng.annotations.Test;
  43 import org.w3c.dom.Document;
  44 import org.w3c.dom.Node;
  45 import org.xml.sax.InputSource;
  46 import org.xml.sax.SAXException;
  47 
  48 /**
  49  * Class containing the test cases for SAXParserFactory API
  50  */
  51 public class TfClearParamTest {
  52     /**
  53      * Test xslt file.
  54      */
  55     private final String XSL_FILE = XML_DIR + "cities.xsl";
  56 
  57     /**
  58      * Long parameter name embedded with a URI.
  59      */
  60     private final String LONG_PARAM_NAME = "{http://xyz.foo.com/yada/baz.html}foo";
  61 
  62     /**
  63      * Short parameter name.
  64      */
  65     private final String SHORT_PARAM_NAME = "foo";
  66 
  67     /**
  68      * Parameter value.
  69      */
  70     private final String PARAM_VALUE = "xyz";
  71 
  72     /**
  73      * Obtains transformer's parameter with the same name that set before. Value
  74      * should be same as set one.


  75      */
  76     @Test
  77     public void clear01() {
  78         try {
  79             Transformer transformer = TransformerFactory.newInstance().newTransformer();
  80             transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
  81             assertEquals(transformer.getParameter(LONG_PARAM_NAME).toString(), PARAM_VALUE);
  82         } catch (TransformerConfigurationException ex) {
  83             failUnexpected(ex);
  84         }
  85 
  86     }
  87 
  88     /**
  89      * Obtains transformer's parameter with the a name that wasn't set before.
  90      * Null is expected.


  91      */
  92     @Test
  93     public void clear02() {
  94         try {
  95             Transformer transformer = TransformerFactory.newInstance().newTransformer();
  96             transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
  97             transformer.clearParameters();
  98             assertNull(transformer.getParameter(LONG_PARAM_NAME));
  99         } catch (TransformerConfigurationException ex){
 100             failUnexpected(ex);
 101         }





























 102     }
 103 
 104     /**
 105      * Obtains transformer's parameter whose initiated with a stream source with
 106      * the a name that set before. Value should be same as set one.


 107      */
 108     @Test
 109     public void clear03() {
 110         try {
 111             Transformer transformer = TransformerFactory.newInstance().
 112                     newTransformer(new StreamSource(new File(XSL_FILE)));
 113 
 114             transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
 115             assertEquals(transformer.getParameter(LONG_PARAM_NAME), PARAM_VALUE);
 116         } catch (TransformerConfigurationException ex){
 117             failUnexpected(ex);
 118         }
 119     }
 120 
 121     /**
 122      * Obtains transformer's parameter whose initiated with a stream source with
 123      * the a name that wasn't set before. Null is expected.


 124      */
 125     @Test
 126     public void clear04() {
 127         try {
 128             Transformer transformer = TransformerFactory.newInstance().
 129                     newTransformer(new StreamSource(new File(XSL_FILE)));
 130             transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
 131             transformer.clearParameters();
 132             assertNull(transformer.getParameter(LONG_PARAM_NAME));
 133         } catch (TransformerConfigurationException ex){
 134             failUnexpected(ex);
 135         }
 136 
 137     }
 138 
 139     /**
 140      * Obtains transformer's parameter whose initiated with a sax source with
 141      * the a name that set before. Value should be same as set one.

 142      */
 143     @Test
 144     public void clear05() {
 145         try {
 146             InputSource is = new InputSource(new FileInputStream(XSL_FILE));
 147             SAXSource saxSource = new SAXSource();
 148             saxSource.setInputSource(is);
 149 
 150             Transformer transformer = TransformerFactory.newInstance().newTransformer(saxSource);
 151 
 152             transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
 153             assertEquals(transformer.getParameter(LONG_PARAM_NAME), PARAM_VALUE);
 154         } catch (FileNotFoundException | TransformerConfigurationException ex){
 155             failUnexpected(ex);
 156         }
 157     }
 158 
 159     /**
 160      * Obtains transformer's parameter whose initiated with a sax source with
 161      * the a name that wasn't set before. Null is expected.

 162      */
 163     @Test
 164     public void clear06() {
 165         try {
 166             InputSource is = new InputSource(new FileInputStream(XSL_FILE));
 167             SAXSource saxSource = new SAXSource();
 168             saxSource.setInputSource(is);
 169 
 170             Transformer transformer = TransformerFactory.newInstance().newTransformer(saxSource);
 171 
 172             transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
 173             transformer.clearParameters();
 174             assertNull(transformer.getParameter(LONG_PARAM_NAME));
 175         } catch (FileNotFoundException | TransformerConfigurationException ex){
 176             failUnexpected(ex);
 177         }
 178     }
 179 
 180     /**
 181      * Obtains transformer's parameter whose initiated with a dom source with
 182      * the a name that set before. Value should be same as set one.

 183      */
 184     @Test
 185     public void clear07() {
 186         try {
 187             TransformerFactory tfactory = TransformerFactory.newInstance();
 188 
 189             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 190             dbf.setNamespaceAware(true);
 191             DocumentBuilder db = dbf.newDocumentBuilder();
 192             Document document = db.parse(new File(XSL_FILE));
 193             DOMSource domSource = new DOMSource((Node)document);
 194 
 195             Transformer transformer = tfactory.newTransformer(domSource);
 196 
 197             transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
 198             assertEquals(transformer.getParameter(LONG_PARAM_NAME), PARAM_VALUE);
 199         } catch (IOException | ParserConfigurationException
 200                 | TransformerConfigurationException | SAXException ex){
 201             failUnexpected(ex);
 202         }
 203     }
 204 
 205     /**
 206      * Obtains transformer's parameter whose initiated with a dom source with
 207      * the a name that wasn't set before. Null is expected.

 208      */
 209     @Test
 210     public void clear08() {
 211         try {
 212             TransformerFactory tfactory = TransformerFactory.newInstance();
 213 
 214             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 215             dbf.setNamespaceAware(true);
 216             DocumentBuilder db = dbf.newDocumentBuilder();
 217             Document document = db.parse(new File(XSL_FILE));
 218             DOMSource domSource = new DOMSource((Node)document);
 219 
 220             Transformer transformer = tfactory.newTransformer(domSource);
 221             transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
 222             transformer.clearParameters();
 223             assertNull(transformer.getParameter(LONG_PARAM_NAME));
 224         } catch (IOException | ParserConfigurationException
 225                 | TransformerConfigurationException | SAXException ex){
 226             failUnexpected(ex);
 227         }
 228     }
 229 
 230     /**
 231      * Obtains transformer's parameter with a short name that set before. Value
 232      * should be same as set one.
 233      */
 234     @Test
 235     public void clear09() {
 236         try {
 237             TransformerFactory tfactory = TransformerFactory.newInstance();
 238             Transformer transformer = tfactory.newTransformer();
 239 
 240             transformer.setParameter(SHORT_PARAM_NAME, PARAM_VALUE);
 241             assertEquals(transformer.getParameter(SHORT_PARAM_NAME).toString(), PARAM_VALUE);
 242         } catch (TransformerConfigurationException ex){
 243             failUnexpected(ex);
 244         }
 245     }
 246 
 247     /**
 248      * Obtains transformer's parameter with a short name that set with an integer
 249      * object before. Value should be same as the set integer object.
 250      */
 251     @Test
 252     public void clear10() {
 253         try {
 254             TransformerFactory tfactory = TransformerFactory.newInstance();
 255             Transformer transformer = tfactory.newTransformer();
 256 
 257             int intObject = 5;
 258             transformer.setParameter(SHORT_PARAM_NAME, intObject);
 259             assertEquals(transformer.getParameter(SHORT_PARAM_NAME), intObject);
 260         } catch (TransformerConfigurationException ex){
 261             failUnexpected(ex);
 262         }
 263     }
 264 }
   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 javax.xml.transform.ptests;
  24 
  25 import java.io.File;
  26 import java.io.FileInputStream;


  27 import javax.xml.parsers.DocumentBuilder;
  28 import javax.xml.parsers.DocumentBuilderFactory;

  29 import javax.xml.transform.Transformer;
  30 import javax.xml.transform.TransformerConfigurationException;
  31 import javax.xml.transform.TransformerFactory;
  32 import javax.xml.transform.dom.DOMSource;
  33 import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR;
  34 import javax.xml.transform.sax.SAXSource;
  35 import javax.xml.transform.stream.StreamSource;
  36 import jaxp.library.JAXPFileReadOnlyBaseTest;
  37 import static org.testng.Assert.assertEquals;
  38 import static org.testng.Assert.assertNull;
  39 import org.testng.annotations.Test;
  40 import org.w3c.dom.Document;
  41 import org.w3c.dom.Node;
  42 import org.xml.sax.InputSource;

  43 
  44 /**
  45  * Class containing the test cases for SAXParserFactory API
  46  */
  47 public class TfClearParamTest extends JAXPFileReadOnlyBaseTest {
  48     /**
  49      * Test style-sheet file name.
  50      */
  51     private final String XSL_FILE = XML_DIR + "cities.xsl";
  52 
  53     /**
  54      * Long parameter name embedded with a URI.
  55      */
  56     private final String LONG_PARAM_NAME = "{http://xyz.foo.com/yada/baz.html}foo";
  57 
  58     /**
  59      * Short parameter name.
  60      */
  61     private final String SHORT_PARAM_NAME = "foo";
  62 
  63     /**
  64      * Parameter value.
  65      */
  66     private final String PARAM_VALUE = "xyz";
  67 
  68     /**
  69      * Obtains transformer's parameter with the same name that set before. Value
  70      * should be same as set one.
  71      * @throws TransformerConfigurationException If for some reason the
  72      *         TransformerHandler can not be created.
  73      */
  74     @Test
  75     public void clear01() throws TransformerConfigurationException {

  76         Transformer transformer = TransformerFactory.newInstance().newTransformer();
  77         transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
  78         assertEquals(transformer.getParameter(LONG_PARAM_NAME).toString(), PARAM_VALUE);




  79     }
  80 
  81     /**
  82      * Obtains transformer's parameter with the a name that wasn't set before.
  83      * Null is expected.
  84      * @throws TransformerConfigurationException If for some reason the
  85      *         TransformerHandler can not be created.
  86      */
  87     @Test
  88     public void clear02() throws TransformerConfigurationException {

  89         Transformer transformer = TransformerFactory.newInstance().newTransformer();
  90         transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
  91         transformer.clearParameters();
  92         assertNull(transformer.getParameter(LONG_PARAM_NAME));


  93     }
  94 
  95     /**
  96      * Obtains transformer's parameter with a short name that set before. Value
  97      * should be same as set one.
  98      * @throws TransformerConfigurationException If for some reason the
  99      *         TransformerHandler can not be created.
 100      */
 101     @Test
 102     public void clear03() throws TransformerConfigurationException {
 103         TransformerFactory tfactory = TransformerFactory.newInstance();
 104         Transformer transformer = tfactory.newTransformer();
 105 
 106         transformer.setParameter(SHORT_PARAM_NAME, PARAM_VALUE);
 107         assertEquals(transformer.getParameter(SHORT_PARAM_NAME).toString(), PARAM_VALUE);
 108     }
 109 
 110     /**
 111      * Obtains transformer's parameter with a short name that set with an integer
 112      * object before. Value should be same as the set integer object.
 113      * @throws TransformerConfigurationException If for some reason the
 114      *         TransformerHandler can not be created.
 115      */
 116     @Test
 117     public void clear04() throws TransformerConfigurationException {
 118         Transformer transformer = TransformerFactory.newInstance().newTransformer();
 119 
 120         int intObject = 5;
 121         transformer.setParameter(SHORT_PARAM_NAME, intObject);
 122         assertEquals(transformer.getParameter(SHORT_PARAM_NAME), intObject);
 123     }
 124 
 125     /**
 126      * Obtains transformer's parameter whose initiated with a stream source with
 127      * the a name that set before. Value should be same as set one.
 128      * @throws TransformerConfigurationException If for some reason the
 129      *         TransformerHandler can not be created.
 130      */
 131     @Test (groups = {"readLocalFiles"})
 132     public void clear05() throws TransformerConfigurationException {

 133         Transformer transformer = TransformerFactory.newInstance().
 134                 newTransformer(new StreamSource(new File(XSL_FILE)));
 135 
 136         transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
 137         assertEquals(transformer.getParameter(LONG_PARAM_NAME), PARAM_VALUE);



 138     }
 139 
 140     /**
 141      * Obtains transformer's parameter whose initiated with a stream source with
 142      * the a name that wasn't set before. Null is expected.
 143      * @throws TransformerConfigurationException If for some reason the
 144      *         TransformerHandler can not be created.
 145      */
 146     @Test (groups = {"readLocalFiles"})
 147     public void clear06() throws TransformerConfigurationException {

 148         Transformer transformer = TransformerFactory.newInstance().
 149                 newTransformer(new StreamSource(new File(XSL_FILE)));
 150         transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
 151         transformer.clearParameters();
 152         assertNull(transformer.getParameter(LONG_PARAM_NAME));




 153     }
 154 
 155     /**
 156      * Obtains transformer's parameter whose initiated with a sax source with
 157      * the a name that set before. Value should be same as set one.
 158      * @throws Exception If any errors occur.
 159      */
 160     @Test (groups = {"readLocalFiles"})
 161     public void clear07() throws Exception {
 162         try (FileInputStream fis = new FileInputStream(XSL_FILE)) {

 163             SAXSource saxSource = new SAXSource();
 164             saxSource.setInputSource(new InputSource(fis));
 165 
 166             Transformer transformer = TransformerFactory.newInstance().newTransformer(saxSource);

 167             transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
 168             assertEquals(transformer.getParameter(LONG_PARAM_NAME), PARAM_VALUE);


 169         }
 170     }
 171 
 172     /**
 173      * Obtains transformer's parameter whose initiated with a sax source with
 174      * the a name that wasn't set before. Null is expected.
 175      * @throws Exception If any errors occur.
 176      */
 177     @Test (groups = {"readLocalFiles"})
 178     public void clear08() throws Exception {
 179         try (FileInputStream fis = new FileInputStream(XSL_FILE)) {

 180             SAXSource saxSource = new SAXSource();
 181             saxSource.setInputSource(new InputSource(fis));
 182 
 183             Transformer transformer = TransformerFactory.newInstance().newTransformer(saxSource);

 184             transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
 185             transformer.clearParameters();
 186             assertNull(transformer.getParameter(LONG_PARAM_NAME));


 187         }
 188     }
 189 
 190     /**
 191      * Obtains transformer's parameter whose initiated with a dom source with
 192      * the a name that set before. Value should be same as set one.
 193      * @throws Exception If any errors occur.
 194      */
 195     @Test (groups = {"readLocalFiles"})
 196     public void clear09() throws Exception {

 197         TransformerFactory tfactory = TransformerFactory.newInstance();
 198 
 199         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 200         dbf.setNamespaceAware(true);
 201         DocumentBuilder db = dbf.newDocumentBuilder();
 202         Document document = db.parse(new File(XSL_FILE));
 203         DOMSource domSource = new DOMSource((Node)document);
 204 
 205         Transformer transformer = tfactory.newTransformer(domSource);
 206 
 207         transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
 208         assertEquals(transformer.getParameter(LONG_PARAM_NAME), PARAM_VALUE);




 209     }
 210 
 211     /**
 212      * Obtains transformer's parameter whose initiated with a dom source with
 213      * the a name that wasn't set before. Null is expected.
 214      * @throws Exception If any errors occur.
 215      */
 216     @Test (groups = {"readLocalFiles"})
 217     public void clear10() throws Exception {

 218         TransformerFactory tfactory = TransformerFactory.newInstance();
 219 
 220         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 221         dbf.setNamespaceAware(true);
 222         DocumentBuilder db = dbf.newDocumentBuilder();
 223         Document document = db.parse(new File(XSL_FILE));
 224         DOMSource domSource = new DOMSource((Node)document);
 225 
 226         Transformer transformer = tfactory.newTransformer(domSource);
 227         transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
 228         transformer.clearParameters();
 229         assertNull(transformer.getParameter(LONG_PARAM_NAME));







































 230     }
 231 }
< prev index next >