1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 package org.apache.qetest.trax.sax;
  21 
  22 import java.io.File;
  23 import java.io.FileInputStream;
  24 import java.io.FileOutputStream;
  25 import java.io.IOException;
  26 import javax.xml.parsers.DocumentBuilder;
  27 import javax.xml.parsers.DocumentBuilderFactory;
  28 import javax.xml.parsers.ParserConfigurationException;
  29 import javax.xml.parsers.SAXParserFactory;
  30 import javax.xml.transform.Result;
  31 import javax.xml.transform.TransformerConfigurationException;
  32 import javax.xml.transform.TransformerFactory;
  33 import javax.xml.transform.dom.DOMSource;
  34 import javax.xml.transform.sax.SAXSource;
  35 import javax.xml.transform.sax.SAXTransformerFactory;
  36 import javax.xml.transform.sax.TransformerHandler;
  37 import javax.xml.transform.stream.StreamResult;
  38 import javax.xml.transform.stream.StreamSource;
  39 import jaxp.library.JAXPFileBaseTest;
  40 import static jaxp.library.JAXPTestUtilities.FILE_SEP;
  41 import static jaxp.library.JAXPTestUtilities.compareWithGold;
  42 import static jaxp.library.JAXPTestUtilities.filenameToURL;
  43 import org.apache.qetest.trax.CheckingErrorListener;
  44 import static org.apache.qetest.trax.TraxConst.GOLDEN_DIR;
  45 import static org.apache.qetest.trax.TraxConst.XML_DIR;
  46 import static jaxp.library.JAXPTestUtilities.getNextFile;
  47 import static org.testng.Assert.assertTrue;
  48 import org.testng.annotations.DataProvider;
  49 import org.testng.annotations.Test;
  50 import org.w3c.dom.Document;
  51 import org.w3c.dom.Node;
  52 import org.xml.sax.InputSource;
  53 import org.xml.sax.SAXException;
  54 import org.xml.sax.XMLReader;
  55 
  56 /**
  57  * API Coverage test for SAXTransformerFactory.
  58  */
  59 public class SAXTransformerFactoryAPITest extends JAXPFileBaseTest {
  60     /**
  61      * Test XSLT embedded file.
  62      */
  63     private static final String CITIES_INCLUDE_FILE = XML_DIR + "impincl" 
  64                         + FILE_SEP + "citiesinclude.xsl";
  65     
  66     /**
  67      * Test XSLT file.
  68      */
  69     private static final String XSLT_FILE = XML_DIR + "cities.xsl";
  70     
  71     /**
  72      * Test XML file.
  73      */
  74     private static final String XML_FILE = XML_DIR + "cities.xml";
  75     
  76     /**
  77      * Test golden verification file.
  78      */
  79     private static final String GOLDEN_FILE = GOLDEN_DIR + "cities.out";
  80     
  81     @DataProvider
  82     public Object[][] parameters(){
  83         return new Object[][]{
  84             {XML_FILE, XSLT_FILE, GOLDEN_FILE}
  85         };
  86     }
  87 
  88     /**
  89      * This tests newTransformerhandler() method which takes StreamSource as
  90      * argument.
  91      * 
  92      * @param xmlFile XML test file name.
  93      * @param xslFile XSLT test file name.
  94      * @param goldFile golden file name.
  95      * @throws TransformerConfigurationException Thrown in case of 
  96      *         ServiceConfigurationError service configuration error or if the
  97      *         implementation is not available or cannot be instantiated.
  98      * @throws IOException if any I/O operation error.
  99      * @throws SAXException for SAX error.
 100      * @throws ParserConfigurationException if  the implementation is not 
 101      *         available or cannot be instantiated.
 102      */
 103     @Test(dataProvider = "parameters")
 104     public void SAXTFactoryTest001(String xmlFile, String xslFile, String goldFile) 
 105             throws TransformerConfigurationException, IOException, 
 106             SAXException, ParserConfigurationException {
 107         String outputFile = getNextFile(this.getClass());
 108         TransformerFactory tfactory = TransformerFactory.newInstance();
 109         try (FileOutputStream fos = new FileOutputStream(outputFile)) {
 110             XMLReader reader = getJAXPXMLReader();
 111             SAXTransformerFactory saxTFactory = (SAXTransformerFactory) tfactory;
 112             TransformerHandler handler = saxTFactory.newTransformerHandler(
 113                     new StreamSource(filenameToURL(xslFile)));
 114             // Send results out to the next output name
 115             handler.setResult(new StreamResult(fos));
 116             reader.setContentHandler(handler);
 117             // Log what output is about to be created
 118             reader.parse(filenameToURL(xmlFile));
 119         }
 120         assertTrue(compareWithGold(goldFile, outputFile));
 121     }
 122     /**
 123      *  This tests newTransformerhandler() method which takes SAXSource as 
 124      *  argument.
 125      * 
 126      * @param xmlFile XML test file name.
 127      * @param xslFile XSLT test file name.
 128      * @param goldFile golden file name.
 129      * @throws TransformerConfigurationException Thrown in case of 
 130      *         ServiceConfigurationError service configuration error or if the
 131      *         implementation is not available or cannot be instantiated.
 132      * @throws IOException if any I/O operation error.
 133      * @throws SAXException for SAX error.
 134      * @throws ParserConfigurationException if  the implementation is not 
 135      *         available or cannot be instantiated.
 136      */
 137     @Test(dataProvider = "parameters")
 138     public void SAXTFactoryTest002(String xmlFile, String xslFile, String goldFile) 
 139             throws TransformerConfigurationException, IOException, 
 140             SAXException, ParserConfigurationException  {
 141         String outputFile = getNextFile(this.getClass());
 142         TransformerFactory tfactory = TransformerFactory.newInstance();
 143         try (FileOutputStream fos = new FileOutputStream(outputFile);
 144              FileInputStream fis = new FileInputStream(xslFile);) {
 145             XMLReader reader = getJAXPXMLReader();
 146             SAXTransformerFactory saxTFactory = (SAXTransformerFactory) tfactory;
 147             SAXSource ss = new SAXSource();
 148             ss.setInputSource(new InputSource(fis));
 149             TransformerHandler handler =  saxTFactory.newTransformerHandler(ss);
 150 
 151             handler.setResult(new StreamResult(fos));
 152             reader.setContentHandler(handler);
 153             reader.parse(filenameToURL(xmlFile));
 154         }
 155         assertTrue(compareWithGold(goldFile, outputFile));
 156     }
 157     
 158     /**
 159      * This tests newTransformerhandler() method which takes DOMSource as 
 160      * argument. No relative URIs used.
 161      * 
 162      * @param xmlFile XML test file name.
 163      * @param xslFile XSLT test file name.
 164      * @param goldFile golden file name.
 165      * @throws TransformerConfigurationException Thrown in case of 
 166      *         ServiceConfigurationError service configuration error or if the
 167      *         implementation is not available or cannot be instantiated.
 168      * @throws IOException if any I/O operation error.
 169      * @throws SAXException for SAX error.
 170      * @throws ParserConfigurationException if  the implementation is not 
 171      *         available or cannot be instantiated.
 172      */
 173     @Test(dataProvider = "parameters")
 174     public void SAXTFactoryTest003(String xmlFile, String xslFile, String goldFile) 
 175             throws TransformerConfigurationException, IOException, 
 176             SAXException, ParserConfigurationException  {
 177         String outputFile = getNextFile(this.getClass());
 178         TransformerFactory tfactory = TransformerFactory.newInstance();
 179         CheckingErrorListener loggingErrListener = new CheckingErrorListener();
 180         tfactory.setErrorListener(loggingErrListener);
 181         try (FileOutputStream fos = new FileOutputStream(outputFile)) {
 182             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 183             dbf.setNamespaceAware(true); // Ensure we get namespaces! May be required for some Xerces versions
 184             DocumentBuilder docBuilder = dbf.newDocumentBuilder();
 185             DOMSource domSource = new DOMSource((Node)docBuilder.parse(new File(xslFile)));
 186             SAXTransformerFactory saxTFactory = (SAXTransformerFactory)tfactory;
 187             TransformerHandler handler = saxTFactory.newTransformerHandler(domSource);
 188             handler.setResult(new StreamResult(fos));
 189             XMLReader reader = getJAXPXMLReader();
 190             reader.setContentHandler(handler);
 191             reader.parse(filenameToURL(xmlFile));
 192         }
 193         assertTrue(compareWithGold(goldFile, outputFile));
 194     }
 195     /**
 196      * This tests newTransformerhandler() method which takes DOMSource as 
 197      * argument. Here a relative URI is used in citiesinclude.xsl file. 
 198      * setSystemId is not used for DOMSource. It should throw an exception. 
 199      * 
 200      * @param xmlFile XML test file name.
 201      * @param xslFile XSLT test file name.
 202      * @param goldFile golden file name.
 203      * @throws TransformerConfigurationException Thrown in case of 
 204      *         ServiceConfigurationError service configuration error or if the
 205      *         implementation is not available or cannot be instantiated.
 206      * @throws IOException if any I/O operation error.
 207      * @throws SAXException for SAX error.
 208      * @throws ParserConfigurationException if  the implementation is not 
 209      *         available or cannot be instantiated.
 210      */
 211     @Test(dataProvider = "parameters", expectedExceptions = TransformerConfigurationException.class)
 212     public void SAXTFactoryTest004(String xmlFile, String xslFile, String goldFile) 
 213             throws TransformerConfigurationException, IOException, 
 214             SAXException, ParserConfigurationException {
 215         String outputFile = getNextFile(this.getClass());
 216         TransformerFactory tfactory = TransformerFactory.newInstance();
 217         try (FileOutputStream fos = new FileOutputStream(outputFile)) {
 218             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 219             // Ensure we get namespaces! May be required for some Xerces versions
 220             dbf.setNamespaceAware(true); 
 221             DocumentBuilder docBuilder = dbf.newDocumentBuilder();
 222              // note specific file name used
 223             Node node = (Node) docBuilder.parse(new File(CITIES_INCLUDE_FILE));
 224             DOMSource domSource = new DOMSource(node);
 225             // setSystemId is not used for DOMSource. expecting Exception.
 226             SAXTransformerFactory saxTFactory = (SAXTransformerFactory) tfactory;
 227             TransformerHandler handler = saxTFactory.newTransformerHandler(domSource);
 228             handler.setResult(new StreamResult(fos));
 229 
 230             XMLReader reader = getJAXPXMLReader();
 231             reader.setContentHandler(handler);
 232 
 233             // Log what output is about to be created
 234             reader.parse(filenameToURL(xmlFile));
 235         } 
 236     }
 237     
 238     /**
 239      * Tests newTransformerhandler() method which takes DOMSource as argument.  
 240      * Here a relative URI is used in citiesinclude.xsl file. setSystemId is 
 241      * used for DOMSource. It should run well.
 242      * 
 243      * @param xmlFile XML test file name.
 244      * @param xslFile XSLT test file name.
 245      * @param goldFile golden file name.
 246      * @throws TransformerConfigurationException Thrown in case of 
 247      *         ServiceConfigurationError service configuration error or if the
 248      *         implementation is not available or cannot be instantiated.
 249      * @throws IOException if any I/O operation error.
 250      * @throws SAXException for SAX error.
 251      * @throws ParserConfigurationException if  the implementation is not 
 252      *         available or cannot be instantiated.
 253      */
 254     @Test(dataProvider = "parameters")
 255     public void SAXTFactoryTest005(String xmlFile, String xslFile, String goldFile) 
 256             throws TransformerConfigurationException, IOException, 
 257             SAXException, ParserConfigurationException  {
 258         String outputFile = getNextFile(this.getClass());
 259         TransformerFactory tfactory = TransformerFactory.newInstance();
 260         try (FileOutputStream fos = new FileOutputStream(outputFile)) {
 261             SAXTransformerFactory saxTFactory = (SAXTransformerFactory) tfactory;
 262             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 263             dbf.setNamespaceAware(true);
 264             DocumentBuilder docBuilder = dbf.newDocumentBuilder();
 265 
 266             Document document = docBuilder.parse(new File(CITIES_INCLUDE_FILE));
 267             DOMSource domSource = new DOMSource((Node) document);
 268             domSource.setSystemId(filenameToURL(CITIES_INCLUDE_FILE));
 269             TransformerHandler handler = saxTFactory.newTransformerHandler(domSource);
 270             handler.setResult(new StreamResult(fos));
 271             XMLReader reader = getJAXPXMLReader();
 272             reader.setContentHandler(handler);
 273             reader.parse(filenameToURL(xmlFile));
 274         }
 275         // Validate the output by comparing against gold
 276         assertTrue(compareWithGold(goldFile, outputFile));
 277     }
 278     /**
 279      * This tests newTransformerhandler() method which takes StreamSource as
 280      * argument.
 281      * 
 282      * @param xmlFile XML test file name.
 283      * @param xslFile XSLT test file name.
 284      * @param goldFile golden file name.
 285      * @throws TransformerConfigurationException Thrown in case of 
 286      *         ServiceConfigurationError service configuration error or if the
 287      *         implementation is not available or cannot be instantiated.
 288      * @throws IOException if any I/O operation error.
 289      * @throws SAXException for SAX error.
 290      * @throws ParserConfigurationException if  the implementation is not 
 291      *         available or cannot be instantiated.
 292      */
 293     @Test(dataProvider = "parameters")
 294     public void SAXTFactoryTest006(String xmlFile, String xslFile, String goldFile) 
 295             throws TransformerConfigurationException, IOException, 
 296             SAXException, ParserConfigurationException  {
 297         String outputFile = getNextFile(this.getClass());
 298         TransformerFactory tfactory = TransformerFactory.newInstance();
 299         try (FileOutputStream fos = new FileOutputStream(outputFile)) {
 300             XMLReader reader = getJAXPXMLReader();
 301 
 302             SAXTransformerFactory saxTFactory = (SAXTransformerFactory) tfactory;
 303             TransformerHandler handler = saxTFactory.newTransformerHandler(
 304                     new StreamSource(filenameToURL(xslFile)));
 305             // Send results out to the next output name
 306             Result result = new StreamResult(fos);
 307 
 308             handler.setResult(result);
 309             reader.setContentHandler(handler);
 310             reader.parse(filenameToURL(xmlFile));
 311         }
 312         assertTrue(compareWithGold(goldFile, outputFile));
 313     }
 314     
 315     /**
 316      * This tests newTransformerhandler() method which takes StreamSource as
 317      * argument.
 318      * 
 319      * @param xmlFile XML test file name.
 320      * @param xslFile XSLT test file name.
 321      * @param goldFile golden file name.
 322      * @throws TransformerConfigurationException Thrown in case of 
 323      *         ServiceConfigurationError service configuration error or if the
 324      *         implementation is not available or cannot be instantiated.
 325      * @throws IOException if any I/O operation error.
 326      * @throws SAXException for SAX error.
 327      * @throws ParserConfigurationException if  the implementation is not 
 328      *         available or cannot be instantiated.
 329      */
 330     @Test(dataProvider = "parameters")
 331     public void SAXTFactoryTest007(String xmlFile, String xslFile, String goldFile) 
 332             throws TransformerConfigurationException, IOException, 
 333             SAXException, ParserConfigurationException  {
 334         String outputFile = getNextFile(this.getClass());
 335         TransformerFactory tfactory = TransformerFactory.newInstance();
 336         try (FileOutputStream fos = new FileOutputStream(outputFile)) {
 337             XMLReader reader = getJAXPXMLReader();
 338 
 339             SAXTransformerFactory saxTFactory = (SAXTransformerFactory) tfactory;
 340             TransformerHandler handler = saxTFactory.newTransformerHandler(
 341                     new StreamSource(filenameToURL(xslFile)));
 342             // Send results out to the next output name
 343             Result result = new StreamResult(fos);
 344 
 345             handler.setResult(result);
 346             reader.setContentHandler(handler);
 347             reader.parse(filenameToURL(xmlFile));
 348         }
 349         assertTrue(compareWithGold(goldFile, outputFile)); 
 350     }
 351 
 352     /**
 353      * This tests newTransformerhandler() method which takes StreamSource as
 354      * argument.
 355      * 
 356      * @param xmlFile XML test file name.
 357      * @param xslFile XSLT test file name.
 358      * @param goldFile golden file name.
 359      * @throws TransformerConfigurationException Thrown in case of 
 360      *         ServiceConfigurationError service configuration error or if the
 361      *         implementation is not available or cannot be instantiated.
 362      * @throws IOException if any I/O operation error.
 363      * @throws SAXException for SAX error.
 364      * @throws ParserConfigurationException if  the implementation is not 
 365      *         available or cannot be instantiated.
 366      */
 367     @Test(dataProvider = "parameters")
 368     public void SAXTFactoryTest008(String xmlFile, String xslFile, String goldFile) 
 369             throws TransformerConfigurationException, IOException, 
 370             SAXException, ParserConfigurationException  {
 371         String outputFile = getNextFile(this.getClass());
 372         TransformerFactory tfactory = TransformerFactory.newInstance();
 373         try (FileOutputStream fos = new FileOutputStream(outputFile)) {
 374             XMLReader reader = getJAXPXMLReader();
 375 
 376             SAXTransformerFactory saxTFactory = (SAXTransformerFactory) tfactory;
 377             TransformerHandler handler = saxTFactory.newTransformerHandler(
 378                     new StreamSource(filenameToURL(xslFile)));
 379             // Send results out to the next output name
 380             Result result = new StreamResult(fos);
 381 
 382             handler.setResult(result);
 383             reader.setContentHandler(handler);
 384             reader.parse(filenameToURL(xmlFile));
 385         }
 386         assertTrue(compareWithGold(goldFile, outputFile));
 387     }
 388     
 389     /**
 390      * This tests newTransformerhandler() method which takes StreamSource as
 391      * argument.
 392      * 
 393      * @param xmlFile XML test file name.
 394      * @param xslFile XSLT test file name.
 395      * @param goldFile golden file name.
 396      * @throws TransformerConfigurationException Thrown in case of 
 397      *         ServiceConfigurationError service configuration error or if the
 398      *         implementation is not available or cannot be instantiated.
 399      * @throws IOException if any I/O operation error.
 400      * @throws SAXException for SAX error.
 401      * @throws ParserConfigurationException if  the implementation is not 
 402      *         available or cannot be instantiated.
 403      */
 404     @Test(dataProvider = "parameters")
 405     public void SAXTFactoryTest009(String xmlFile, String xslFile, String goldFile) 
 406             throws TransformerConfigurationException, IOException, 
 407             SAXException, ParserConfigurationException  {
 408         String outputFile = getNextFile(this.getClass());
 409         TransformerFactory tfactory = TransformerFactory.newInstance();
 410         try (FileOutputStream fos = new FileOutputStream(outputFile)) {
 411             XMLReader reader = getJAXPXMLReader();
 412 
 413             SAXTransformerFactory saxTFactory = (SAXTransformerFactory) tfactory;
 414             TransformerHandler handler = saxTFactory.newTransformerHandler(
 415                     new StreamSource(filenameToURL(xslFile)));
 416             // Send results out to the next output name
 417             Result result = new StreamResult(fos);
 418 
 419             handler.setResult(result);
 420             reader.setContentHandler(handler);
 421             reader.parse(filenameToURL(xmlFile));
 422         }
 423         assertTrue(compareWithGold(goldFile, outputFile));
 424     }
 425 
 426     /**
 427      * This tests newTransformerhandler() method which takes StreamSource as
 428      * argument.
 429      * 
 430      * @param xmlFile XML test file name.
 431      * @param xslFile XSLT test file name.
 432      * @param goldFile golden file name.
 433      * @throws TransformerConfigurationException Thrown in case of 
 434      *         ServiceConfigurationError service configuration error or if the
 435      *         implementation is not available or cannot be instantiated.
 436      * @throws IOException if any I/O operation error.
 437      * @throws SAXException for SAX error.
 438      * @throws ParserConfigurationException if  the implementation is not 
 439      *         available or cannot be instantiated.
 440      */
 441     @Test(dataProvider = "parameters")
 442     public void SAXTFactoryTest010(String xmlFile, String xslFile, String goldFile) 
 443             throws TransformerConfigurationException, IOException, 
 444             SAXException, ParserConfigurationException  {
 445         String outputFile = getNextFile(this.getClass());
 446         TransformerFactory tfactory = TransformerFactory.newInstance();
 447         try (FileOutputStream fos = new FileOutputStream(outputFile)) {
 448             XMLReader reader = getJAXPXMLReader();
 449 
 450             SAXTransformerFactory saxTFactory = (SAXTransformerFactory) tfactory;
 451             TransformerHandler handler = saxTFactory.newTransformerHandler(
 452                     new StreamSource(filenameToURL(xslFile)));
 453             // Send results out to the next output name
 454             Result result = new StreamResult(fos);
 455 
 456             handler.setResult(result);
 457             reader.setContentHandler(handler);
 458             reader.parse(filenameToURL(xmlFile));
 459         }
 460         assertTrue(compareWithGold(goldFile, outputFile));
 461     }
 462     
 463     /**
 464      * This tests newTransformerhandler() method which takes StreamSource as
 465      * argument.
 466      * 
 467      * @param xmlFile XML test file name.
 468      * @param xslFile XSLT test file name.
 469      * @param goldFile golden file name.
 470      * @throws TransformerConfigurationException Thrown in case of 
 471      *         ServiceConfigurationError service configuration error or if the
 472      *         implementation is not available or cannot be instantiated.
 473      * @throws IOException if any I/O operation error.
 474      * @throws SAXException for SAX error.
 475      * @throws ParserConfigurationException if  the implementation is not 
 476      *         available or cannot be instantiated.
 477      */
 478     @Test(dataProvider = "parameters")
 479     public void SAXTFactoryTest011(String xmlFile, String xslFile, String goldFile) 
 480             throws TransformerConfigurationException, IOException, 
 481             SAXException, ParserConfigurationException  {
 482         String outputFile = getNextFile(this.getClass());
 483         TransformerFactory tfactory = TransformerFactory.newInstance();
 484         try (FileOutputStream fos = new FileOutputStream(outputFile)) {
 485             XMLReader reader = getJAXPXMLReader();
 486 
 487             SAXTransformerFactory saxTFactory = (SAXTransformerFactory) tfactory;
 488             TransformerHandler handler = saxTFactory.newTransformerHandler(
 489                     new StreamSource(filenameToURL(xslFile)));
 490             // Send results out to the next output name
 491             Result result = new StreamResult(fos);
 492 
 493             handler.setResult(result);
 494             reader.setContentHandler(handler);
 495             reader.parse(filenameToURL(xmlFile));
 496         }
 497         assertTrue(compareWithGold(goldFile, outputFile));  
 498     }
 499 
 500     /**
 501      * This tests newTransformerhandler() method which takes StreamSource as
 502      * argument.
 503      * 
 504      * @param xmlFile XML test file name.
 505      * @param xslFile XSLT test file name.
 506      * @param goldFile golden file name.
 507      * @throws TransformerConfigurationException Thrown in case of 
 508      *         ServiceConfigurationError service configuration error or if the
 509      *         implementation is not available or cannot be instantiated.
 510      * @throws IOException if any I/O operation error.
 511      * @throws SAXException for SAX error.
 512      * @throws ParserConfigurationException if  the implementation is not 
 513      *         available or cannot be instantiated.
 514      */
 515     @Test(dataProvider = "parameters")
 516     public void SAXTFactoryTest012(String xmlFile, String xslFile, String goldFile) 
 517             throws TransformerConfigurationException, IOException, 
 518             SAXException, ParserConfigurationException  {
 519         String outputFile = getNextFile(this.getClass());
 520         TransformerFactory tfactory = TransformerFactory.newInstance();
 521         try (FileOutputStream fos = new FileOutputStream(outputFile)) {
 522             XMLReader reader = getJAXPXMLReader();
 523 
 524             SAXTransformerFactory saxTFactory = (SAXTransformerFactory) tfactory;
 525             TransformerHandler handler = saxTFactory.newTransformerHandler(
 526                     new StreamSource(filenameToURL(xslFile)));
 527             // Send results out to the next output name
 528             Result result = new StreamResult(fos);
 529 
 530             handler.setResult(result);
 531             reader.setContentHandler(handler);
 532             reader.parse(filenameToURL(xmlFile));
 533         } 
 534         assertTrue(compareWithGold(goldFile, outputFile));
 535     }
 536     
 537     /**
 538      * This tests newTransformerhandler() method which takes StreamSource as
 539      * argument.
 540      * 
 541      * @param xmlFile XML test file name.
 542      * @param xslFile XSLT test file name.
 543      * @param goldFile golden file name.
 544      * @throws TransformerConfigurationException Thrown in case of 
 545      *         ServiceConfigurationError service configuration error or if the
 546      *         implementation is not available or cannot be instantiated.
 547      * @throws IOException if any I/O operation error.
 548      * @throws SAXException for SAX error.
 549      * @throws ParserConfigurationException if  the implementation is not 
 550      *         available or cannot be instantiated.
 551      */
 552     @Test(dataProvider = "parameters")
 553     public void SAXTFactoryTest013(String xmlFile, String xslFile, String goldFile) 
 554             throws TransformerConfigurationException, IOException, 
 555             SAXException, ParserConfigurationException  {
 556         String outputFile = getNextFile(this.getClass());
 557         TransformerFactory tfactory = TransformerFactory.newInstance();
 558         try (FileOutputStream fos = new FileOutputStream(outputFile)) {
 559             XMLReader reader = getJAXPXMLReader();
 560 
 561             SAXTransformerFactory saxTFactory = (SAXTransformerFactory) tfactory;
 562             TransformerHandler handler = saxTFactory.newTransformerHandler(
 563                     new StreamSource(filenameToURL(xslFile)));
 564             // Send results out to the next output name
 565             Result result = new StreamResult(fos);
 566 
 567             handler.setResult(result);
 568             reader.setContentHandler(handler);
 569             reader.parse(filenameToURL(xmlFile));
 570         }
 571         assertTrue(compareWithGold(goldFile, outputFile)); 
 572     }
 573    
 574     /**
 575      * Worker method to get an XMLReader.
 576      *
 577      * @return a new XMLReader for use, with setNamespaceAware(true)
 578      * @throws ParserConfigurationException if a parser cannot be created which
 579      * satisfies the requested configuration.
 580      * @throws SAXException for SAX errors.
 581      */
 582     private XMLReader getJAXPXMLReader()
 583             throws SAXException, ParserConfigurationException {
 584         // Be sure to use the JAXP methods only!
 585         SAXParserFactory factory = SAXParserFactory.newInstance();
 586         factory.setNamespaceAware(true);
 587         return factory.newSAXParser().getXMLReader();
 588     } 
 589 }