1 /*
2 * Copyright (c) 2015, 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 */
29 import javax.xml.transform.Source;
30 import javax.xml.transform.Transformer;
31 import javax.xml.transform.TransformerException;
32 import javax.xml.transform.TransformerFactory;
33 import javax.xml.transform.URIResolver;
34 import javax.xml.transform.stream.StreamResult;
35 import javax.xml.transform.stream.StreamSource;
36
37 import org.testng.annotations.DataProvider;
38 import org.testng.annotations.Test;
39
40 import static org.testng.Assert.assertEquals;
41
42 /*
43 * @summary This class contains tests for XSLT functions.
44 */
45
46 public class XSLTFunctionsTest {
47
48 /**
49 * @bug 8062518
50 * Verifies that a reference to the DTM created by XSLT document function is
51 * actually read from the DTM by an extension function.
52 * @param xml Content of xml file to process
53 * @param xsl stylesheet content that loads external document {@code externalDoc}
54 * with XSLT 'document' function and then reads it with
55 * DocumentExtFunc.test() function
56 * @param externalDoc Content of the external xml document
57 * @param expectedResult Expected transformation result
58 **/
59 @Test(dataProvider = "document")
60 public void testDocument(final String xml, final String xsl,
61 final String externalDoc, final String expectedResult) throws Exception {
62 // Prepare sources for transormation
63 Source src = new StreamSource(new StringReader(xml));
64 Source xslsrc = new StreamSource(new StringReader(xsl));
65
66 // Create factory and transformer
67 TransformerFactory tf = TransformerFactory.newInstance();
68 Transformer t = tf.newTransformer( xslsrc );
69 t.setErrorListener(tf.getErrorListener());
|
1 /*
2 * Copyright (c) 2015, 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 */
29 import javax.xml.transform.Source;
30 import javax.xml.transform.Transformer;
31 import javax.xml.transform.TransformerException;
32 import javax.xml.transform.TransformerFactory;
33 import javax.xml.transform.URIResolver;
34 import javax.xml.transform.stream.StreamResult;
35 import javax.xml.transform.stream.StreamSource;
36
37 import org.testng.annotations.DataProvider;
38 import org.testng.annotations.Test;
39
40 import static org.testng.Assert.assertEquals;
41
42 /*
43 * @summary This class contains tests for XSLT functions.
44 */
45
46 public class XSLTFunctionsTest {
47
48 /**
49 * @bug 8062518 8153082
50 * Verifies that a reference to the DTM created by XSLT document function is
51 * actually read from the DTM by an extension function.
52 * @param xml Content of xml file to process
53 * @param xsl stylesheet content that loads external document {@code externalDoc}
54 * with XSLT 'document' function and then reads it with
55 * DocumentExtFunc.test() function
56 * @param externalDoc Content of the external xml document
57 * @param expectedResult Expected transformation result
58 **/
59 @Test(dataProvider = "document")
60 public void testDocument(final String xml, final String xsl,
61 final String externalDoc, final String expectedResult) throws Exception {
62 // Prepare sources for transormation
63 Source src = new StreamSource(new StringReader(xml));
64 Source xslsrc = new StreamSource(new StringReader(xsl));
65
66 // Create factory and transformer
67 TransformerFactory tf = TransformerFactory.newInstance();
68 Transformer t = tf.newTransformer( xslsrc );
69 t.setErrorListener(tf.getErrorListener());
|