< prev index next >

test/javax/xml/jaxp/unittest/common/TransformationWarningsTest.java

Print this page




  25 
  26 import static jaxp.library.JAXPTestUtilities.setSystemProperty;
  27 
  28 import java.io.StringReader;
  29 import java.io.StringWriter;
  30 
  31 import javax.xml.transform.Source;
  32 import javax.xml.transform.Transformer;
  33 import javax.xml.transform.TransformerFactory;
  34 import javax.xml.transform.stream.StreamResult;
  35 import javax.xml.transform.stream.StreamSource;
  36 
  37 import org.testng.annotations.BeforeClass;
  38 import org.testng.annotations.Listeners;
  39 import org.testng.annotations.Test;
  40 
  41 /*
  42  * @test
  43  * @bug 8144593
  44  * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest

  45  * @run testng/othervm -DrunSecMngr=true common.TransformationWarningsTest
  46  * @run testng/othervm common.TransformationWarningsTest
  47  * @summary Check that warnings about unsupported properties from parsers
  48  * are suppressed during the transformation process.
  49  */
  50 @Listeners({jaxp.library.BasePolicy.class})
  51 public class TransformationWarningsTest extends WarningsTestBase {
  52 
  53     @BeforeClass
  54     public void setup() {
  55         //Set test SAX driver implementation.
  56         setSystemProperty("org.xml.sax.driver", "common.TestSAXDriver");
  57     }
  58 
  59     @Test
  60     public void testTransformation() throws Exception {
  61         startTest();
  62     }
  63 
  64     //One iteration of xml transformation test case. It will be called from each
  65     //TestWorker task defined in WarningsTestBase class.
  66     void doOneTestIteration() throws Exception {
  67         // Prepare output stream
  68         StringWriter xmlResultString = new StringWriter();
  69         StreamResult xmlResultStream = new StreamResult(xmlResultString);
  70         // Prepare xml source stream
  71         Source src = new StreamSource(new StringReader(xml));
  72         Transformer t = createTransformer();
  73         //Transform the xml
  74         t.transform(src, xmlResultStream);
  75     }
  76 
  77     //Create transformer from xsl test string
  78     Transformer createTransformer() throws Exception {
  79         // Prepare sources for transormation
  80         Source xslsrc = new StreamSource(new StringReader(xsl));
  81 
  82         // Create factory and transformer
  83         TransformerFactory tf = TransformerFactory.newInstance();





  84         Transformer t = tf.newTransformer(xslsrc);
  85 
  86         // Set URI Resolver to return the newly constructed xml
  87         // stream source object from xml test string
  88         t.setURIResolver((String href, String base) -> new StreamSource(new StringReader(xml)));
  89         return t;
  90     }
  91 
  92     //Xsl and Xml contents used in the transformation test
  93     private static final String xsl = "<xsl:stylesheet version='2.0'"
  94             + " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>"
  95             + " <xsl:output method='xml' indent='yes' omit-xml-declaration='yes'/>"
  96             + " <xsl:template match='/'>"
  97             + " <test>Simple Transformation Result. No warnings should be printed to console</test>"
  98             + " </xsl:template>"
  99             + "</xsl:stylesheet>";
 100     private static final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>";
 101 }
 102 


  25 
  26 import static jaxp.library.JAXPTestUtilities.setSystemProperty;
  27 
  28 import java.io.StringReader;
  29 import java.io.StringWriter;
  30 
  31 import javax.xml.transform.Source;
  32 import javax.xml.transform.Transformer;
  33 import javax.xml.transform.TransformerFactory;
  34 import javax.xml.transform.stream.StreamResult;
  35 import javax.xml.transform.stream.StreamSource;
  36 
  37 import org.testng.annotations.BeforeClass;
  38 import org.testng.annotations.Listeners;
  39 import org.testng.annotations.Test;
  40 
  41 /*
  42  * @test
  43  * @bug 8144593
  44  * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
  45  * @compile -XDignore.symbol.file TestSAXDriver.java
  46  * @run testng/othervm -DrunSecMngr=true common.TransformationWarningsTest
  47  * @run testng/othervm common.TransformationWarningsTest
  48  * @summary Check that warnings about unsupported properties from parsers
  49  * are suppressed during the transformation process.
  50  */
  51 @Listeners({jaxp.library.BasePolicy.class, jaxp.library.InternalAPIPolicy.class})
  52 public class TransformationWarningsTest extends WarningsTestBase {
  53 
  54     @BeforeClass
  55     public void setup() {
  56         //Set test SAX driver implementation.
  57         setSystemProperty("org.xml.sax.driver", "common.TestSAXDriver");
  58     }
  59 
  60     @Test
  61     public void testTransformation() throws Exception {
  62         startTest();
  63     }
  64 
  65     //One iteration of xml transformation test case. It will be called from each
  66     //TestWorker task defined in WarningsTestBase class.
  67     void doOneTestIteration() throws Exception {
  68         // Prepare output stream
  69         StringWriter xmlResultString = new StringWriter();
  70         StreamResult xmlResultStream = new StreamResult(xmlResultString);
  71         // Prepare xml source stream
  72         Source src = new StreamSource(new StringReader(xml));
  73         Transformer t = createTransformer();
  74         //Transform the xml
  75         t.transform(src, xmlResultStream);
  76     }
  77 
  78     //Create transformer from xsl test string
  79     Transformer createTransformer() throws Exception {
  80         // Prepare sources for transormation
  81         Source xslsrc = new StreamSource(new StringReader(xsl));
  82 
  83         // Create factory and transformer
  84         TransformerFactory tf;
  85         // newTransformer() method doc states that different transformer
  86         // factories can be used concurrently by different Threads.
  87         synchronized (TransformerFactory.class) {
  88             tf = TransformerFactory.newInstance();
  89         }
  90         Transformer t = tf.newTransformer(xslsrc);
  91 
  92         // Set URI Resolver to return the newly constructed xml
  93         // stream source object from xml test string
  94         t.setURIResolver((String href, String base) -> new StreamSource(new StringReader(xml)));
  95         return t;
  96     }
  97 
  98     //Xsl and Xml contents used in the transformation test
  99     private static final String xsl = "<xsl:stylesheet version='2.0'"
 100             + " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>"
 101             + " <xsl:output method='xml' indent='yes' omit-xml-declaration='yes'/>"
 102             + " <xsl:template match='/'>"
 103             + " <test>Simple Transformation Result. No warnings should be printed to console</test>"
 104             + " </xsl:template>"
 105             + "</xsl:stylesheet>";
 106     private static final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>";
 107 }
 108 
< prev index next >