xref: /aosp_15_r20/external/apache-xml/test/tests/bugzilla/Bugzilla5609.java (revision 1212f9a0ffdc28482b8821715d2222bf16dc14e2)
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the  "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 // Common Qetest / Xalan testing imports
19 import org.apache.qetest.Datalet;
20 import org.apache.qetest.Logger;
21 import org.apache.qetest.TestletImpl;
22 
23 // REPLACE_imports needed for reproducing the bug
24 import org.apache.qetest.CheckService;
25 import org.apache.qetest.xsl.XHTFileCheckService;
26 
27 import javax.xml.transform.*;
28 import javax.xml.transform.stream.*;
29 import java.io.File;
30 
31 /**
32  * Testlet for reproducing Bugzilla reported bugs.
33  * @author [email protected]
34  * @author [email protected]
35  */
36 public class Bugzilla5609 extends TestletImpl
37 {
38     // Initialize our classname for TestletImpl's main() method - must be updated!
39     static { thisClassName = "Bugzilla5609"; }
40 
41     /**
42      * Write Minimal code to reproduce your Bugzilla bug report.
43      * Many Bugzilla tests won't bother with a datalet; they'll
44      * just have the data to reproduce the bug encoded by default.
45      * @param d (optional) Datalet to use as data point for the test.
46      */
execute(Datalet d)47     public void execute(Datalet d)
48 	{
49         // Use logger.logMsg(...) instead of System.out.println(...)
50         logger.logMsg(Logger.STATUSMSG, "Reproducing Bugzilla#5609: Global Variable Initialization across Multiple Transformations");
51         CheckService fileChecker = new XHTFileCheckService();
52         try
53         {
54             // Reproduce bug as-is: re-using transformer with global variable decl uses wrong value
55             TransformerFactory factory = TransformerFactory.newInstance();
56             logger.logMsg(Logger.STATUSMSG, "About to newTransformer(Bugzilla5609.xsl)");
57             Transformer transformer = factory.newTransformer(new StreamSource(new File("Bugzilla5609.xsl")));
58             logger.logMsg(Logger.STATUSMSG, "About to transform#1 Bugzilla5609.xml into .out");
59             transformer.transform(new StreamSource(new File("Bugzilla5609.xml")),
60                                   new StreamResult(new File("Bugzilla5609.out")));
61             fileChecker.check(logger,
62                     new File("Bugzilla5609.out"),
63                     new File("Bugzilla5609.gold"),
64                     "transform#1 into Bugzilla5609.out");
65 
66 
67             logger.logMsg(Logger.STATUSMSG, "About to transform#2 ParamBugzilla5609a.xml into .out");
68             transformer.transform(new StreamSource(new File("Bugzilla5609a.xml")),
69                                   new StreamResult(new File("Bugzilla5609a.out")));
70             fileChecker.check(logger,
71                     new File("Bugzilla5609a.out"),
72                     new File("Bugzilla5609a.gold"),
73                     "transform#2 into Bugzilla5609a.out; but is wrong var num is used");
74 
75         }
76         catch (Throwable t)
77         {
78             logger.logThrowable(Logger.WARNINGMSG, t, "Bugzilla#5609 threw");
79             logger.checkErr("Bugzilla#5609 threw " + t.toString());
80         }
81 
82         try
83         {
84             // Reproduce bug when getting single transformer from templates
85             TransformerFactory factory = TransformerFactory.newInstance();
86             logger.logMsg(Logger.STATUSMSG, "About to newTemplates(Bugzilla5609.xsl)");
87             Templates templates = factory.newTemplates(new StreamSource(new File("Bugzilla5609.xsl")));
88             logger.logMsg(Logger.STATUSMSG, "About to Templates.newTransformer()");
89             Transformer transformer = templates.newTransformer();
90             logger.logMsg(Logger.STATUSMSG, "About to transform#1 Bugzilla5609.xml into .out");
91             transformer.transform(new StreamSource(new File("Bugzilla5609.xml")),
92                                   new StreamResult(new File("Bugzilla5609.out")));
93             fileChecker.check(logger,
94                     new File("Bugzilla5609.out"),
95                     new File("Bugzilla5609.gold"),
96                     "transform#1 into Bugzilla5609.out");
97 
98 
99             logger.logMsg(Logger.STATUSMSG, "About to transform#2 Bugzilla5609a.xml into .out");
100             transformer.transform(new StreamSource(new File("Bugzilla5609a.xml")),
101                                   new StreamResult(new File("Bugzilla5609a.out")));
102             fileChecker.check(logger,
103                     new File("Bugzilla5609a.out"),
104                     new File("Bugzilla5609a.gold"),
105                     "transform#2 into Bugzilla5609a.out; but is wrong var num is used");
106 
107         }
108         catch (Throwable t)
109         {
110             logger.logThrowable(Logger.WARNINGMSG, t, "Bugzilla#5609 threw");
111             logger.checkErr("Bugzilla#5609 threw " + t.toString());
112         }
113 	}
114 
115     /**
116      * <a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5609">
117      * Link to Bugzilla report</a>
118      * @return Global Variable Initialization across Multiple Transformations.
119      */
getDescription()120     public String getDescription()
121     {
122         return "Global Variable Initialization across Multiple Transformations";
123     }
124 
125 }  // end of class Bugzilla5609
126 
127