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.*; 25 import org.apache.qetest.trax.*; 26 import org.apache.qetest.xsl.*; 27 28 // Import all relevant TRAX packages 29 import javax.xml.transform.*; 30 import javax.xml.transform.dom.*; 31 import javax.xml.transform.sax.*; 32 import javax.xml.transform.stream.*; 33 import javax.xml.parsers.DocumentBuilder; 34 import javax.xml.parsers.DocumentBuilderFactory; 35 import javax.xml.parsers.SAXParserFactory; 36 37 // Needed SAX, DOM, JAXP classes 38 import org.xml.sax.InputSource; 39 import org.xml.sax.XMLReader; 40 import org.w3c.dom.Node; 41 42 // java classes 43 import java.io.File; 44 import java.io.FilenameFilter; 45 import java.util.Properties; 46 47 48 /** 49 * Testlet for reproducing Bugzilla reported bugs. 50 * 51 * @author [email protected] 52 * @author [email protected] 53 */ 54 public class Bugzilla1266 extends TestletImpl 55 { 56 // Initialize our classname for TestletImpl's main() method - must be updated! 57 static { thisClassName = "Bugzilla1266"; } 58 59 /** 60 * Write Minimal code to reproduce your Bugzilla bug report. 61 * Many Bugzilla tests won't bother with a datalet; they'll 62 * just have the data to reproduce the bug encoded by default. 63 * @param d (optional) Datalet to use as data point for the test. 64 */ execute(Datalet d)65 public void execute(Datalet d) 66 { 67 // Use logger.logMsg(...) instead of System.out.println(...) 68 logger.logMsg(Logger.STATUSMSG, "Reproducing Bugzilla#1266"); 69 LoggingErrorListener loggingErrorListener = new LoggingErrorListener(logger); 70 loggingErrorListener.setThrowWhen(LoggingErrorListener.THROW_NEVER); 71 logger.logMsg(Logger.STATUSMSG, "loggingErrorListener originally setup:" + loggingErrorListener.getQuickCounters()); 72 73 TransformerFactory factory = null; 74 Templates templates = null; 75 Transformer transformer = null; 76 try 77 { 78 factory = TransformerFactory.newInstance(); 79 logger.logMsg(Logger.STATUSMSG, "About to factory.newTemplates(" + QetestUtils.filenameToURL("identity.xsl") + ")"); 80 templates = factory.newTemplates(new StreamSource(QetestUtils.filenameToURL("identity.xsl"))); 81 transformer = templates.newTransformer(); 82 83 // Set the errorListener and validate it 84 transformer.setErrorListener(loggingErrorListener); 85 if (transformer.getErrorListener() == loggingErrorListener) 86 logger.checkPass("set/getErrorListener on transformer"); 87 else 88 logger.checkFail("set/getErrorListener on transformer"); 89 90 logger.logMsg(Logger.STATUSMSG, "Reproduce Bugzilla1266 - warning due to bad output props not propagated"); 91 logger.logMsg(Logger.STATUSMSG, "transformer.setOutputProperty(encoding, illegal-encoding-value)"); 92 transformer.setOutputProperty("encoding", "illegal-encoding-value"); 93 94 logger.logMsg(Logger.STATUSMSG, "about to transform(...)"); 95 transformer.transform(new StreamSource(QetestUtils.filenameToURL("identity.xml")), 96 new StreamResult("Bugzilla1266.out")); 97 logger.logMsg(Logger.STATUSMSG, "after transform(...)"); 98 logger.logMsg(Logger.STATUSMSG, "loggingErrorListener after transform:" + loggingErrorListener.getQuickCounters()); 99 100 // Validate that one warning (about illegal-encoding-value) should have been reported 101 int[] errCtr = loggingErrorListener.getCounters(); 102 if (errCtr[LoggingErrorListener.TYPE_WARNING] > 0) 103 logger.checkPass("At least one Warning listned to for illegal-encoding-value"); 104 else 105 logger.checkFail("At least one Warning listned to for illegal-encoding-value"); 106 107 // Validate the actual output file as well: in this case, 108 // the stylesheet should still work 109 CheckService fileChecker = new XHTFileCheckService(); 110 fileChecker.check(logger, 111 new File("Bugzilla1266.out"), 112 new File("identity.gold"), 113 "transform of good xsl w/bad output props into: " + "Bugzilla1266.out"); 114 115 } 116 catch (Throwable t) 117 { 118 logger.checkFail("Bugzilla1266 unexpectedly threw: " + t.toString()); 119 logger.logThrowable(Logger.ERRORMSG, t, "Bugzilla1266 unexpectedly threw"); 120 } 121 122 } 123 124 /** 125 * <a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1266"> 126 * Link to Bugzilla report</a> 127 * @return Warning Event not being fired from Transformer when using invalid Encoding String. 128 */ getDescription()129 public String getDescription() 130 { 131 return "Warning Event not being fired from Transformer when using invalid Encoding String"; 132 } 133 134 } // end of class Bugzilla1266 135 136