< prev index next >

test/javax/xml/jaxp/unittest/transform/TransformerTest.java

Print this page
rev 1063 : 8172974: [JAXP] XALAN: Wrong result when transforming namespace unaware StAX Input
   1 /*
   2  * Copyright (c) 2014, 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 transform;
  25 
  26 import static jaxp.library.JAXPTestUtilities.getSystemProperty;
  27 
  28 import java.io.BufferedReader;
  29 import java.io.ByteArrayInputStream;
  30 import java.io.ByteArrayOutputStream;
  31 import java.io.File;
  32 import java.io.FileNotFoundException;
  33 import java.io.FileReader;
  34 import java.io.IOException;
  35 import java.io.StringReader;
  36 import java.io.StringWriter;
  37 
  38 import javax.xml.parsers.DocumentBuilderFactory;
  39 import javax.xml.parsers.ParserConfigurationException;
  40 import javax.xml.parsers.SAXParserFactory;




  41 import javax.xml.transform.Transformer;

  42 import javax.xml.transform.TransformerException;
  43 import javax.xml.transform.TransformerFactory;
  44 import javax.xml.transform.dom.DOMResult;
  45 import javax.xml.transform.dom.DOMSource;
  46 import javax.xml.transform.sax.SAXSource;

  47 import javax.xml.transform.stream.StreamResult;
  48 import javax.xml.transform.stream.StreamSource;
  49 
  50 import org.testng.Assert;
  51 import org.testng.AssertJUnit;

  52 import org.testng.annotations.Listeners;
  53 import org.testng.annotations.Test;
  54 import org.w3c.dom.Document;
  55 import org.w3c.dom.Element;
  56 import org.w3c.dom.Node;
  57 import org.w3c.dom.NodeList;
  58 import org.xml.sax.ContentHandler;
  59 import org.xml.sax.DTDHandler;
  60 import org.xml.sax.EntityResolver;
  61 import org.xml.sax.ErrorHandler;
  62 import org.xml.sax.InputSource;
  63 import org.xml.sax.SAXException;
  64 import org.xml.sax.SAXNotRecognizedException;
  65 import org.xml.sax.SAXNotSupportedException;
  66 import org.xml.sax.XMLReader;
  67 import org.xml.sax.helpers.AttributesImpl;
  68 
  69 import com.sun.org.apache.xml.internal.serialize.OutputFormat;
  70 import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
  71 
  72 /*
  73  * @test
  74  * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
  75  * @run testng/othervm -DrunSecMngr=true transform.TransformerTest
  76  * @run testng/othervm transform.TransformerTest
  77  * @summary Transformer Tests
  78  * @bug 6272879 6305029 6505031 8150704 8162598 8169112 8169631 8169772
  79  */
  80 @Listeners({jaxp.library.FilePolicy.class})
  81 public class TransformerTest {
  82 
  83     // some global constants
  84     private static final String LINE_SEPARATOR =
  85         getSystemProperty("line.separator");
  86 
  87     private static final String NAMESPACES =
  88         "http://xml.org/sax/features/namespaces";
  89 
  90     private static final String NAMESPACE_PREFIXES =
  91         "http://xml.org/sax/features/namespace-prefixes";
  92 
  93     private static abstract class TestTemplate {
  94         protected void printSnippet(String title, String snippet) {
  95             StringBuilder div = new StringBuilder();
  96             for (int i = 0; i < title.length(); i++)
  97                 div.append("=");
  98             System.out.println(title + "\n" + div + "\n" + snippet + "\n");
  99         }
 100     }
 101 
 102     /**
 103      * Reads the contents of the given file into a string.
 104      * WARNING: this method adds a final line feed even if the last line of the file doesn't contain one.
 105      *
 106      * @param f
 107      * The file to read
 108      * @return The content of the file as a string, with line terminators as \"n"
 109      * for all platforms
 110      * @throws IOException
 111      * If there was an error reading
 112      */
 113     private String getFileContentAsString(File f) throws IOException {
 114         try (BufferedReader reader = new BufferedReader(new FileReader(f))) {


 313         tf.newTransformer().transform(streamSource, new StreamResult(resultWriter));
 314         AssertJUnit.assertEquals("Identity transform of StreamSource", XML_DOCUMENT, resultWriter.toString());
 315     }
 316 
 317     /*
 318      * @bug 6505031
 319      * @summary Test transformer parses keys and their values coming from different xml documents.
 320      */
 321     @Test
 322     public final void testBug6505031() throws TransformerException {
 323         TransformerFactory tf = TransformerFactory.newInstance();
 324         Transformer t = tf.newTransformer(new StreamSource(getClass().getResource("transform.xsl").toString()));
 325         t.setParameter("config", getClass().getResource("config.xml").toString());
 326         t.setParameter("mapsFile", getClass().getResource("maps.xml").toString());
 327         StringWriter sw = new StringWriter();
 328         t.transform(new StreamSource(getClass().getResource("template.xml").toString()), new StreamResult(sw));
 329         String s = sw.toString();
 330         Assert.assertTrue(s.contains("map1key1value") && s.contains("map2key1value"));
 331     }
 332 
 333     private static class Test8169631 extends TestTemplate {
 334         private final static String xsl =
 335             "<?xml version=\"1.0\"?>" + LINE_SEPARATOR +
 336             "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">" + LINE_SEPARATOR +
 337             "  <xsl:template match=\"/\">" + LINE_SEPARATOR +
 338             "    <xsl:variable name=\"Counter\" select=\"count(//row)\"/>" + LINE_SEPARATOR +
 339             "    <xsl:variable name=\"AttribCounter\" select=\"count(//@attrib)\"/>" + LINE_SEPARATOR +
 340             "    <Counter><xsl:value-of select=\"$Counter\"/></Counter>" + LINE_SEPARATOR +
 341             "    <AttribCounter><xsl:value-of select=\"$AttribCounter\"/></AttribCounter>" + LINE_SEPARATOR +
 342             "  </xsl:template>" + LINE_SEPARATOR +
 343             "</xsl:stylesheet>" + LINE_SEPARATOR;
 344 
 345         private final static String sourceXml =
 346             "<?xml version=\"1.0\"?>" + LINE_SEPARATOR +
 347             "<envelope xmlns=\"http://www.sap.com/myns\" xmlns:sap=\"http://www.sap.com/myns\">" + LINE_SEPARATOR +
 348             "  <sap:row sap:attrib=\"a\">1</sap:row>" + LINE_SEPARATOR +
 349             "  <row attrib=\"b\">2</row>" + LINE_SEPARATOR +
 350             "  <row sap:attrib=\"c\">3</row>" + LINE_SEPARATOR +
 351             "</envelope>" + LINE_SEPARATOR;
 352 
 353         /**


 360          * @param elementCount
 361          * Counter of elements to check
 362          * @param attribCount
 363          * Counter of attributes to check
 364          */
 365         private void verifyResult(String type, String result, int elementCount,
 366                                   int attribCount)
 367         {
 368             printSnippet("Result of transformation from " + type + ":",
 369                          result);
 370             Assert.assertEquals(
 371                 result.contains("<Counter>" + elementCount + "</Counter>"),
 372                 true, "Result of transformation from " + type +
 373                 " should have count of " + elementCount + " elements.");
 374             Assert.assertEquals(
 375                 result.contains("<AttribCounter>" + attribCount +
 376                 "</AttribCounter>"), true, "Result of transformation from " +
 377                 type + " should have count of "+ attribCount + " attributes.");
 378         }
 379 
 380         public void run() throws IOException, TransformerException,
 381             SAXException, ParserConfigurationException

 382         {
 383             printSnippet("Source:", sourceXml);



 384 
 385             printSnippet("Stylesheet:", xsl);







 386 
 387             // create default transformer (namespace aware)
 388             TransformerFactory tf1 = TransformerFactory.newInstance();
 389             ByteArrayInputStream bais = new ByteArrayInputStream(xsl.getBytes());
 390             Transformer t1 = tf1.newTransformer(new StreamSource(bais));


 391 
 392             // test transformation from stream source with namespace support
 393             ByteArrayOutputStream baos = new ByteArrayOutputStream();
 394             bais = new ByteArrayInputStream(sourceXml.getBytes());
 395             t1.transform(new StreamSource(bais), new StreamResult(baos));
 396             verifyResult("StreamSource with namespace support", baos.toString(), 0, 1);
 397 
 398             // test transformation from DOM source with namespace support
 399             bais.reset();
 400             baos.reset();


































 401             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

 402             dbf.setNamespaceAware(true);
 403             Document doc = dbf.newDocumentBuilder().parse(new InputSource(bais));
 404             t1.transform(new DOMSource(doc), new StreamResult(baos));
 405             verifyResult("DOMSource with namespace support", baos.toString(), 0, 1);
 406 
 407             // test transformation from DOM source without namespace support
 408             bais.reset();
 409             baos.reset();
 410             dbf.setNamespaceAware(false);
 411             doc = dbf.newDocumentBuilder().parse(new InputSource(bais));
 412             t1.transform(new DOMSource(doc), new StreamResult(baos));
 413             verifyResult("DOMSource without namespace support", baos.toString(), 3, 3);
 414 
 415             // test transformation from SAX source with namespace support
 416             bais.reset();
 417             baos.reset();
 418             SAXParserFactory spf = SAXParserFactory.newInstance();

 419             spf.setNamespaceAware(true);
 420             XMLReader xmlr = spf.newSAXParser().getXMLReader();
 421             SAXSource saxS = new SAXSource(xmlr, new InputSource(bais));
 422             t1.transform(saxS, new StreamResult(baos));
 423             verifyResult("SAXSource with namespace support", baos.toString(), 0, 1);
 424 
 425             // test transformation from SAX source without namespace support
 426             bais.reset();
 427             baos.reset();
 428             spf.setNamespaceAware(false);
 429             xmlr = spf.newSAXParser().getXMLReader();
 430             saxS = new SAXSource(xmlr, new InputSource(bais));
 431             t1.transform(saxS, new StreamResult(baos));
 432             verifyResult("SAXSource without namespace support", baos.toString(), 3, 3);
 433         }
 434     }
 435 
 436     /*
 437      * @bug 8169631
 438      * @summary Test combinations of namespace awareness settings on
 439      *          XSL transformations
 440      */
 441     @Test
 442     public final void testBug8169631() throws IOException, SAXException,
 443         TransformerException, ParserConfigurationException
 444     {
 445         new Test8169631().run();






























 446     }
 447 
 448     /*
 449      * @bug 8150704
 450      * @summary Test that XSL transformation with lots of temporary result
 451      *          trees will not run out of DTM IDs.
 452      */
 453     @Test
 454     public final void testBug8150704() throws TransformerException, IOException {
 455         System.out.println("Testing transformation of Bug8150704-1.xml...");
 456         TransformerFactory tf = TransformerFactory.newInstance();
 457         Transformer t = tf.newTransformer(new StreamSource(getClass().getResource("Bug8150704-1.xsl").toString()));
 458         StringWriter sw = new StringWriter();
 459         t.transform(new StreamSource(getClass().getResource("Bug8150704-1.xml").toString()), new StreamResult(sw));
 460         String resultstring = sw.toString().replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n");
 461         String reference = getFileContentAsString(new File(getClass().getResource("Bug8150704-1.ref").getPath()));
 462         Assert.assertEquals(resultstring, reference, "Output of transformation of Bug8150704-1.xml does not match reference");
 463         System.out.println("Passed.");
 464 
 465         System.out.println("Testing transformation of Bug8150704-2.xml...");


   1 /*
   2  * Copyright (c) 2014, 2017, 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 transform;
  25 
  26 import static jaxp.library.JAXPTestUtilities.getSystemProperty;
  27 
  28 import java.io.BufferedReader;
  29 import java.io.ByteArrayInputStream;
  30 import java.io.ByteArrayOutputStream;
  31 import java.io.File;
  32 import java.io.FileNotFoundException;
  33 import java.io.FileReader;
  34 import java.io.IOException;
  35 import java.io.StringReader;
  36 import java.io.StringWriter;
  37 
  38 import javax.xml.parsers.DocumentBuilderFactory;
  39 import javax.xml.parsers.ParserConfigurationException;
  40 import javax.xml.parsers.SAXParserFactory;
  41 import javax.xml.stream.XMLInputFactory;
  42 import javax.xml.stream.XMLStreamException;
  43 import javax.xml.transform.Source;
  44 import javax.xml.transform.Templates;
  45 import javax.xml.transform.Transformer;
  46 import javax.xml.transform.TransformerConfigurationException;
  47 import javax.xml.transform.TransformerException;
  48 import javax.xml.transform.TransformerFactory;
  49 import javax.xml.transform.dom.DOMResult;
  50 import javax.xml.transform.dom.DOMSource;
  51 import javax.xml.transform.sax.SAXSource;
  52 import javax.xml.transform.stax.StAXSource;
  53 import javax.xml.transform.stream.StreamResult;
  54 import javax.xml.transform.stream.StreamSource;
  55 
  56 import org.testng.Assert;
  57 import org.testng.AssertJUnit;
  58 import org.testng.annotations.DataProvider;
  59 import org.testng.annotations.Listeners;
  60 import org.testng.annotations.Test;
  61 import org.w3c.dom.Document;
  62 import org.w3c.dom.Element;
  63 import org.w3c.dom.Node;
  64 import org.w3c.dom.NodeList;
  65 import org.xml.sax.ContentHandler;
  66 import org.xml.sax.DTDHandler;
  67 import org.xml.sax.EntityResolver;
  68 import org.xml.sax.ErrorHandler;
  69 import org.xml.sax.InputSource;
  70 import org.xml.sax.SAXException;
  71 import org.xml.sax.SAXNotRecognizedException;
  72 import org.xml.sax.SAXNotSupportedException;
  73 import org.xml.sax.XMLReader;
  74 import org.xml.sax.helpers.AttributesImpl;
  75 
  76 import com.sun.org.apache.xml.internal.serialize.OutputFormat;
  77 import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
  78 
  79 /*
  80  * @test
  81  * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
  82  * @run testng/othervm -DrunSecMngr=true transform.TransformerTest
  83  * @run testng/othervm transform.TransformerTest
  84  * @summary Transformer Tests
  85  * @bug 6272879 6305029 6505031 8150704 8162598 8169112 8169631 8169772 8172974
  86  */
  87 @Listeners({jaxp.library.FilePolicy.class})
  88 public class TransformerTest {
  89 
  90     // some global constants
  91     private static final String LINE_SEPARATOR =
  92         getSystemProperty("line.separator");
  93 
  94     private static final String NAMESPACES =
  95         "http://xml.org/sax/features/namespaces";
  96 
  97     private static final String NAMESPACE_PREFIXES =
  98         "http://xml.org/sax/features/namespace-prefixes";
  99 
 100     private static abstract class TestTemplate {
 101         protected static void printSnippet(String title, String snippet) {
 102             StringBuilder div = new StringBuilder();
 103             for (int i = 0; i < title.length(); i++)
 104                 div.append("=");
 105             System.out.println(title + "\n" + div + "\n" + snippet + "\n");
 106         }
 107     }
 108 
 109     /**
 110      * Reads the contents of the given file into a string.
 111      * WARNING: this method adds a final line feed even if the last line of the file doesn't contain one.
 112      *
 113      * @param f
 114      * The file to read
 115      * @return The content of the file as a string, with line terminators as \"n"
 116      * for all platforms
 117      * @throws IOException
 118      * If there was an error reading
 119      */
 120     private String getFileContentAsString(File f) throws IOException {
 121         try (BufferedReader reader = new BufferedReader(new FileReader(f))) {


 320         tf.newTransformer().transform(streamSource, new StreamResult(resultWriter));
 321         AssertJUnit.assertEquals("Identity transform of StreamSource", XML_DOCUMENT, resultWriter.toString());
 322     }
 323 
 324     /*
 325      * @bug 6505031
 326      * @summary Test transformer parses keys and their values coming from different xml documents.
 327      */
 328     @Test
 329     public final void testBug6505031() throws TransformerException {
 330         TransformerFactory tf = TransformerFactory.newInstance();
 331         Transformer t = tf.newTransformer(new StreamSource(getClass().getResource("transform.xsl").toString()));
 332         t.setParameter("config", getClass().getResource("config.xml").toString());
 333         t.setParameter("mapsFile", getClass().getResource("maps.xml").toString());
 334         StringWriter sw = new StringWriter();
 335         t.transform(new StreamSource(getClass().getResource("template.xml").toString()), new StreamResult(sw));
 336         String s = sw.toString();
 337         Assert.assertTrue(s.contains("map1key1value") && s.contains("map2key1value"));
 338     }
 339 
 340     public static class Test8169631And8172974 extends TestTemplate {
 341         private final static String xsl =
 342             "<?xml version=\"1.0\"?>" + LINE_SEPARATOR +
 343             "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">" + LINE_SEPARATOR +
 344             "  <xsl:template match=\"/\">" + LINE_SEPARATOR +
 345             "    <xsl:variable name=\"Counter\" select=\"count(//row)\"/>" + LINE_SEPARATOR +
 346             "    <xsl:variable name=\"AttribCounter\" select=\"count(//@attrib)\"/>" + LINE_SEPARATOR +
 347             "    <Counter><xsl:value-of select=\"$Counter\"/></Counter>" + LINE_SEPARATOR +
 348             "    <AttribCounter><xsl:value-of select=\"$AttribCounter\"/></AttribCounter>" + LINE_SEPARATOR +
 349             "  </xsl:template>" + LINE_SEPARATOR +
 350             "</xsl:stylesheet>" + LINE_SEPARATOR;
 351 
 352         private final static String sourceXml =
 353             "<?xml version=\"1.0\"?>" + LINE_SEPARATOR +
 354             "<envelope xmlns=\"http://www.sap.com/myns\" xmlns:sap=\"http://www.sap.com/myns\">" + LINE_SEPARATOR +
 355             "  <sap:row sap:attrib=\"a\">1</sap:row>" + LINE_SEPARATOR +
 356             "  <row attrib=\"b\">2</row>" + LINE_SEPARATOR +
 357             "  <row sap:attrib=\"c\">3</row>" + LINE_SEPARATOR +
 358             "</envelope>" + LINE_SEPARATOR;
 359 
 360         /**


 367          * @param elementCount
 368          * Counter of elements to check
 369          * @param attribCount
 370          * Counter of attributes to check
 371          */
 372         private void verifyResult(String type, String result, int elementCount,
 373                                   int attribCount)
 374         {
 375             printSnippet("Result of transformation from " + type + ":",
 376                          result);
 377             Assert.assertEquals(
 378                 result.contains("<Counter>" + elementCount + "</Counter>"),
 379                 true, "Result of transformation from " + type +
 380                 " should have count of " + elementCount + " elements.");
 381             Assert.assertEquals(
 382                 result.contains("<AttribCounter>" + attribCount +
 383                 "</AttribCounter>"), true, "Result of transformation from " +
 384                 type + " should have count of "+ attribCount + " attributes.");
 385         }
 386 
 387         // utility to obtain Transformer from TransformerFactory
 388         private static Transformer getTransformer(TransformerFactory tf)
 389             throws TransformerConfigurationException
 390         {
 391             return tf.newTransformer(
 392                 new StreamSource(new ByteArrayInputStream(xsl.getBytes()))
 393             );
 394         }
 395 
 396         // utility to obtain Templates from TransformerFactory
 397         private static Templates getTemplates(TransformerFactory tf)
 398             throws TransformerConfigurationException
 399         {
 400             return tf.newTemplates(
 401                 new StreamSource(new ByteArrayInputStream(xsl.getBytes()))
 402             );
 403         }
 404 
 405         // utility to construct StreamSource
 406         private static StreamSource getStreamSource() {
 407             return new StreamSource(
 408                 new ByteArrayInputStream(sourceXml.getBytes())
 409             );
 410         }
 411 
 412         // utility to construct DOMSource from DocumentBuilderFactory
 413         private static DOMSource getDOMSource(DocumentBuilderFactory dbf)
 414             throws SAXException, IOException, ParserConfigurationException
 415         {
 416             return new DOMSource(
 417                 dbf.newDocumentBuilder().parse(
 418                     new InputSource(
 419                         new ByteArrayInputStream(sourceXml.getBytes())
 420                     )
 421                 )
 422             );
 423         }
 424 
 425         // utility to construct SAXSource from SAXParserFactory
 426         private static SAXSource getSAXSource(SAXParserFactory spf)
 427             throws SAXException, ParserConfigurationException
 428         {
 429             return new SAXSource(
 430                 spf.newSAXParser().getXMLReader(),
 431                 new InputSource(new ByteArrayInputStream(sourceXml.getBytes()))
 432             );
 433         }
 434 
 435         // utility to construct StAXSource from XMLInputFactory
 436         private static StAXSource getStAXSource(XMLInputFactory xif)
 437             throws XMLStreamException
 438         {
 439             return new StAXSource(
 440                 xif.createXMLStreamReader(new StringReader(sourceXml))
 441             );
 442         }
 443 
 444         @DataProvider(name = "testmatrix")
 445         public static Object[][] documentTestData()
 446             throws TransformerConfigurationException, SAXException, IOException,
 447             ParserConfigurationException, XMLStreamException
 448         {
 449             // get Transformers
 450             TransformerFactory tf = TransformerFactory.newInstance();
 451             Transformer t = getTransformer(tf);
 452             Transformer tFromTemplates = getTemplates(tf).newTransformer();
 453 
 454             // get DOMSource objects
 455             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 456             DOMSource domSourceWithoutNS = getDOMSource(dbf);
 457             dbf.setNamespaceAware(true);
 458             DOMSource domSourceWithNS = getDOMSource(dbf);
 459 
 460             // get SAXSource objects












 461             SAXParserFactory spf = SAXParserFactory.newInstance();
 462             SAXSource saxSourceWithoutNS = getSAXSource(spf);
 463             spf.setNamespaceAware(true);
 464             SAXSource saxSourceWithNS = getSAXSource(spf);














 465 
 466             // get StAXSource objects
 467             XMLInputFactory xif = XMLInputFactory.newInstance();
 468             StAXSource staxSourceWithNS = getStAXSource(xif);
 469             xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
 470             StAXSource staxSourceWithoutNS = getStAXSource(xif);
 471 
 472             // print XML/XSL snippets to ease understanding of result
 473             printSnippet("Source:", sourceXml);
 474             printSnippet("Stylesheet:", xsl);
 475 
 476             return new Object[][] {
 477                 // test StreamSource input with all transformers
 478                 // namespace awareness is set by transformer
 479                 {t, getStreamSource(), "StreamSource with namespace support", 0, 1},
 480                 {tFromTemplates, getStreamSource(), "StreamSource with namespace support using templates", 0, 1},
 481                 // now test DOMSource, SAXSource and StAXSource
 482                 // with rotating use of created transformers
 483                 // namespace awareness is set by source objects
 484                 {t, domSourceWithNS, "DOMSource with namespace support", 0, 1},
 485                 {t, domSourceWithoutNS, "DOMSource without namespace support", 3, 3},
 486                 {tFromTemplates, saxSourceWithNS, "SAXSource with namespace support", 0, 1},
 487                 {tFromTemplates, saxSourceWithoutNS, "SAXSource without namespace support", 3, 3},
 488                 {t, staxSourceWithNS, "StAXSource with namespace support", 0, 1},
 489                 {t, staxSourceWithoutNS, "StAXSource without namespace support", 3, 3}
 490             };
 491         }
 492 
 493         /*
 494          * @bug 8169631 8172974
 495          * @summary Test combinations of namespace awareness settings on
 496          *          XSL transformations
 497          */
 498         @Test(dataProvider = "testmatrix")
 499         public void run(Transformer t, Source s, String label, int elementcount, int attributecount)
 500             throws TransformerException
 501         {
 502             ByteArrayOutputStream baos = new ByteArrayOutputStream();
 503             t.transform(s, new StreamResult(baos));
 504             verifyResult(label, baos.toString(), elementcount, attributecount);
 505         }
 506     }
 507 
 508     /*
 509      * @bug 8150704
 510      * @summary Test that XSL transformation with lots of temporary result
 511      *          trees will not run out of DTM IDs.
 512      */
 513     @Test
 514     public final void testBug8150704() throws TransformerException, IOException {
 515         System.out.println("Testing transformation of Bug8150704-1.xml...");
 516         TransformerFactory tf = TransformerFactory.newInstance();
 517         Transformer t = tf.newTransformer(new StreamSource(getClass().getResource("Bug8150704-1.xsl").toString()));
 518         StringWriter sw = new StringWriter();
 519         t.transform(new StreamSource(getClass().getResource("Bug8150704-1.xml").toString()), new StreamResult(sw));
 520         String resultstring = sw.toString().replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n");
 521         String reference = getFileContentAsString(new File(getClass().getResource("Bug8150704-1.ref").getPath()));
 522         Assert.assertEquals(resultstring, reference, "Output of transformation of Bug8150704-1.xml does not match reference");
 523         System.out.println("Passed.");
 524 
 525         System.out.println("Testing transformation of Bug8150704-2.xml...");


< prev index next >