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 import javax.xml.transform.*; 24 import javax.xml.transform.stream.*; 25 import java.io.File; 26 import java.io.StringWriter; 27 28 /** 29 * For not well formed XML document, the Transformer hangs(May be due to threading issues) 30 * @author [email protected] 31 * @author [email protected] 32 */ 33 public class Bugzilla4286 extends TestletImpl 34 { 35 // Initialize our classname for TestletImpl's main() method - must be updated! 36 static { thisClassName = "Bugzilla4286"; } 37 38 /** 39 * @param d (optional) Datalet to use as data point for the test. 40 */ execute(Datalet d)41 public void execute(Datalet d) 42 { 43 logger.logMsg(Logger.STATUSMSG, "Reproducing Bugzilla#4286 For not well formed XML document, the Transformer hangs"); 44 logger.logMsg(Logger.CRITICALMSG, "WARNING! THIS TEST MAY HANG! (i.e. don't run in automation)"); 45 try 46 { 47 TransformerFactory transformerFactory = TransformerFactory.newInstance(); 48 Transformer transformer = transformerFactory.newTransformer(new StreamSource("identity.xsl")); 49 StringWriter stringWriter = new StringWriter(); 50 logger.logMsg(Logger.STATUSMSG, "About to transform error.xml into StringWriter"); 51 transformer.transform(new StreamSource(new File("error.xml")), 52 new StreamResult(stringWriter)); 53 logger.checkPass("Transform completed and returned (crash test)"); 54 logger.logMsg(Logger.STATUSMSG, "To-do: validate output!"); 55 logger.logMsg(Logger.STATUSMSG, "StringWriter is: " + stringWriter.toString()); 56 } 57 catch (TransformerException te) 58 { 59 // Since the XML is invalid, we should get a TransformerException 60 logger.logThrowable(Logger.ERRORMSG, te, "Transform threw expected"); 61 logger.checkPass("Transform threw expected: " + te.toString()); 62 } 63 catch (Exception e) 64 { 65 logger.logThrowable(Logger.ERRORMSG, e, "Transform threw non-expected"); 66 logger.checkFail("Transform threw non-expected: " + e.toString()); 67 } 68 logger.logMsg(Logger.CRITICALMSG, "Bug occours now: system hangs"); 69 } 70 71 /** 72 * <a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4286"> 73 * Link to Bugzilla report</a> 74 * @return For not well formed XML document, the Transformer hangs. 75 */ getDescription()76 public String getDescription() 77 { 78 return "#4286 For not well formed XML document, the Transformer hangs"; 79 } 80 81 } // end of class Bugzilla4286 82