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.dom.*; 25 import javax.xml.transform.stream.*; 26 import org.apache.xalan.stree.DocumentImpl; 27 import org.apache.xalan.extensions.ExpressionContext; 28 import org.xml.sax.InputSource; 29 import org.w3c.dom.Document; 30 import org.w3c.dom.Element; 31 import org.w3c.dom.Node; 32 import java.io.File; 33 34 /** 35 * Testlet for reproducing Bugzilla reported bugs. 36 * @author [email protected] (Vladimir Rylsky) 37 * @author [email protected] 38 */ 39 public class Bugzilla1288 extends TestletImpl 40 { 41 // Initialize our classname for TestletImpl's main() method - must be updated! 42 static { thisClassName = "Bugzilla1288"; } 43 44 /** 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#1288 TreeWalker.traverse goes to infinite loop (with extension)"); 51 // Just transform the stylesheet: 52 logger.logMsg(Logger.CRITICALMSG, "WARNING! THIS TEST MAY HANG! (i.e. don't run in automation)"); 53 try 54 { 55 TransformerFactory transformerFactory = TransformerFactory.newInstance(); 56 Source transformerSource = new StreamSource(new File("Bugzilla1288.xsl")); 57 Transformer transformer = transformerFactory.newTransformer(transformerSource); 58 Source input = new StreamSource(new File("identity.xml")); 59 Result output = new StreamResult(new File("Bugzilla1288.out")); 60 logger.logMsg(Logger.STATUSMSG, "About to transform error.xml into Bugzilla1288.out"); 61 transformer.transform(input, output); 62 logger.checkPass("Transform completed and returned (crash test)"); 63 logger.logMsg(Logger.STATUSMSG, "To-do: validate output!"); 64 } 65 catch (Exception e) 66 { 67 logger.checkFail("Transform threw: " + e.toString()); 68 logger.logThrowable(Logger.ERRORMSG, e, "Transform threw"); 69 } 70 logger.checkAmbiguous("Bug occours now: system hangs"); 71 } 72 73 /** 74 * <a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1288"> 75 * Link to Bugzilla report</a> 76 * @return TreeWalker.traverse goes to infinite loop (with extension). 77 */ getDescription()78 public String getDescription() 79 { 80 return "TreeWalker.traverse goes to infinite loop (with extension)"; 81 } 82 83 /* Extension function used in stylesheet */ run(ExpressionContext processor, Node context)84 public Node run(ExpressionContext processor, Node context) 85 { 86 Document x_doc = null; 87 Element n_tool; 88 89 // Note must call public constructor! -sc 90 x_doc = new DocumentImpl(1024); 91 92 n_tool = (Element)x_doc.appendChild(x_doc.createElement("TOOL_NAME")); 93 n_tool.setAttribute("date", "date-string-here" /* new Date().toString() */); 94 95 Node n_result = n_tool.appendChild(x_doc.createElement("result")); 96 97 if (context != null) 98 { 99 try 100 { 101 Transformer copier = TransformerFactory.newInstance().newTransformer(); 102 copier.transform(new DOMSource(n_tool), new DOMResult(context)); 103 } 104 catch (TransformerException ex) 105 { 106 ex.printStackTrace(); 107 } 108 } 109 110 return n_tool; 111 } 112 } // end of class Bugzilla1288 113