Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/jaxp/common/8144593/TransformationWarningsTest.java
38860 views
1
/*
2
* Copyright (c) 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
import java.io.StringReader;
25
import java.io.StringWriter;
26
import javax.xml.transform.Source;
27
import javax.xml.transform.Transformer;
28
import javax.xml.transform.TransformerFactory;
29
import javax.xml.transform.stream.StreamResult;
30
import javax.xml.transform.stream.StreamSource;
31
import org.testng.annotations.Test;
32
import org.testng.annotations.BeforeClass;
33
34
/*
35
* @test
36
* @bug 8144593
37
* @summary Check that warnings about unsupported properties from parsers
38
* are suppressed during the transformation process.
39
* @compile -XDignore.symbol.file TestSAXDriver.java
40
* @run testng/othervm TransformationWarningsTest
41
*/
42
public class TransformationWarningsTest extends WarningsTestBase {
43
44
@BeforeClass
45
public void setup() {
46
//Set test SAX driver implementation.
47
System.setProperty("org.xml.sax.driver", "TestSAXDriver");
48
}
49
50
@Test
51
public void testTransformation() throws Exception {
52
startTest();
53
}
54
55
//One iteration of xml transformation test case. It will be called from each
56
//TestWorker task defined in WarningsTestBase class.
57
void doOneTestIteration() throws Exception {
58
// Prepare output stream
59
StringWriter xmlResultString = new StringWriter();
60
StreamResult xmlResultStream = new StreamResult(xmlResultString);
61
// Prepare xml source stream
62
Source src = new StreamSource(new StringReader(xml));
63
Transformer t = createTransformer();
64
//Transform the xml
65
t.transform(src, xmlResultStream);
66
}
67
68
//Create transformer from xsl test string
69
Transformer createTransformer() throws Exception {
70
// Prepare sources for transormation
71
Source xslsrc = new StreamSource(new StringReader(xsl));
72
73
// Create factory and transformer
74
TransformerFactory tf = TransformerFactory.newInstance();
75
Transformer t = tf.newTransformer(xslsrc);
76
77
// Set URI Resolver to return the newly constructed xml
78
// stream source object from xml test string
79
t.setURIResolver((String href, String base) -> new StreamSource(new StringReader(xml)));
80
return t;
81
}
82
83
//Xsl and Xml contents used in the transformation test
84
private static final String xsl = "<xsl:stylesheet version='2.0'"
85
+ " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>"
86
+ " <xsl:output method='xml' indent='yes' omit-xml-declaration='yes'/>"
87
+ " <xsl:template match='/'>"
88
+ " <test>Simple Transformation Result. No warnings should be printed to console</test>"
89
+ " </xsl:template>"
90
+ "</xsl:stylesheet>";
91
private static final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>";
92
}
93
94