Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/jaxp/common/8144593/TransformationWarningsTest.java
38860 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.StringReader;24import java.io.StringWriter;25import javax.xml.transform.Source;26import javax.xml.transform.Transformer;27import javax.xml.transform.TransformerFactory;28import javax.xml.transform.stream.StreamResult;29import javax.xml.transform.stream.StreamSource;30import org.testng.annotations.Test;31import org.testng.annotations.BeforeClass;3233/*34* @test35* @bug 814459336* @summary Check that warnings about unsupported properties from parsers37* are suppressed during the transformation process.38* @compile -XDignore.symbol.file TestSAXDriver.java39* @run testng/othervm TransformationWarningsTest40*/41public class TransformationWarningsTest extends WarningsTestBase {4243@BeforeClass44public void setup() {45//Set test SAX driver implementation.46System.setProperty("org.xml.sax.driver", "TestSAXDriver");47}4849@Test50public void testTransformation() throws Exception {51startTest();52}5354//One iteration of xml transformation test case. It will be called from each55//TestWorker task defined in WarningsTestBase class.56void doOneTestIteration() throws Exception {57// Prepare output stream58StringWriter xmlResultString = new StringWriter();59StreamResult xmlResultStream = new StreamResult(xmlResultString);60// Prepare xml source stream61Source src = new StreamSource(new StringReader(xml));62Transformer t = createTransformer();63//Transform the xml64t.transform(src, xmlResultStream);65}6667//Create transformer from xsl test string68Transformer createTransformer() throws Exception {69// Prepare sources for transormation70Source xslsrc = new StreamSource(new StringReader(xsl));7172// Create factory and transformer73TransformerFactory tf = TransformerFactory.newInstance();74Transformer t = tf.newTransformer(xslsrc);7576// Set URI Resolver to return the newly constructed xml77// stream source object from xml test string78t.setURIResolver((String href, String base) -> new StreamSource(new StringReader(xml)));79return t;80}8182//Xsl and Xml contents used in the transformation test83private static final String xsl = "<xsl:stylesheet version='2.0'"84+ " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>"85+ " <xsl:output method='xml' indent='yes' omit-xml-declaration='yes'/>"86+ " <xsl:template match='/'>"87+ " <test>Simple Transformation Result. No warnings should be printed to console</test>"88+ " </xsl:template>"89+ "</xsl:stylesheet>";90private static final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>";91}929394