/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: XSLT.java 2326 2007-03-27 21:59:44Z mlipp $
*
* $Log$
* Revision 1.3 2006/09/29 12:32:08 drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.2 2006/03/08 14:46:43 drmlipp
* Synchronized with 1.3.3p5.
*
* Revision 1.1.1.3.6.2 2005/12/14 09:57:12 drmlipp
* Added support in XSLTTool for all basic out types.
*
* Revision 1.1.1.3.6.1 2005/12/13 17:51:54 drmlipp
* Added support for datetime parameters fo XSLTTool.
*
* Revision 1.1.1.3 2004/08/18 15:17:39 drmlipp
* Update to 1.2
*
* Revision 1.24 2004/02/19 13:10:32 lipp
* Clarified start-/endDocument usage in SAXEventBuffers.
*
* Revision 1.23 2004/02/17 17:12:16 montag
* new testcase for returning a not wellformed element.
*
* Revision 1.22 2004/02/17 16:25:36 montag
* testcase 12 corrected.
*
* Revision 1.21 2004/02/17 15:29:07 lipp
* Several fixes.
*
* Revision 1.20 2004/02/17 08:07:41 montag
* test12 for List return
*
* Revision 1.19 2004/01/28 15:21:44 montag
* test asserts corrected.
*
* Revision 1.18 2004/01/28 09:25:49 montag
* additional testcase added.
*
* Revision 1.17 2004/01/28 08:34:33 montag
* new functionality for merging multiple xml documents in one.
*
* Revision 1.16 2004/01/27 17:44:47 montag
* stateReached() instead of Thread.sleep() used.
*
* Revision 1.15 2004/01/27 17:26:05 montag
* test cases adapted. stylesheet as property
* of the prcess description.
*
* Revision 1.14 2004/01/27 13:08:07 lipp
* Added tests.
*
* Revision 1.13 2004/01/27 12:11:08 montag
* XSLTTool now implements ResultProvider interface.
*
* Revision 1.12 2003/10/21 21:00:45 lipp
* Moved EJBClientTest to new junit sub-package.
*
* Revision 1.11 2003/10/08 12:39:40 huaiyang
* make test weblogic compatible.
*
* Revision 1.10 2003/07/14 09:01:19 montag
* error corrected setting the result type
* if there is no output mapping defined.
*
* Revision 1.9 2003/07/11 14:07:09 montag
* return SAXEventBufferImpl if no output
* mapping is defined.
*
* Revision 1.8 2003/07/10 14:42:13 montag
* xlst transformation als SAXEventBuffer.
*
* Revision 1.7 2003/07/04 09:09:09 montag
* debug logging inserted.
*
* Revision 1.6 2003/07/03 12:53:50 montag
* url handling corrected.
*
* Revision 1.5 2003/07/02 13:50:09 montag
* Property XSLT no longer mandatory.
*
* Revision 1.4 2003/07/02 11:53:13 montag
* Support for additional IN parameters.
*
* Revision 1.3 2003/07/02 09:30:38 montag
* handling of complex out parameters
* with no defined mapping fixed.
*
* Revision 1.2 2003/07/02 07:33:50 montag
* first workng version of the XSLTTool.
* Next steps:
* - handling of not well-formed transformation results.
* - support for additional parameters.
* - adapt logging messages.
*
* Revision 1.1 2003/07/01 14:28:43 montag
* initial of XSLTTool.
*
*
*/
package tools;
import java.util.Iterator;
import java.util.Map;
import java.util.Date;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.dom.DOMResult;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
import org.jaxen.XPath;
import org.jaxen.dom.DOMXPath;
import org.jaxen.jdom.JDOMXPath;
import org.jdom.input.SAXHandler;
import org.jdom.output.XMLOutputter;
import junit.framework.Test;
import junit.framework.TestSuite;
import process.WfMOpenTestCase;
import de.danet.an.util.junit.EJBClientTest;
import de.danet.an.util.sax.BodyFilter;
import de.danet.an.util.XMLUtil;
import de.danet.an.workflow.util.SAXEventBufferImpl;
import de.danet.an.workflow.api.ProcessDefinitionDirectory;
import de.danet.an.workflow.api.ProcessMgr;
import de.danet.an.workflow.omgcore.WfProcess;
/**
* Test the tool of XSLTDynamicInvocationTool.
* @author <a href="mailto:weidauer@danet.de">Christian Weidauer</a>
* @version 1.0
*/
public class XSLT extends WfMOpenTestCase {
private ProcessDefinitionDirectory pdd = null;
/**
* Constructor of this TestCase
* @param name a <code>String</code> value
*/
public XSLT(String name) {
super (name);
}
/**
* Construct this test suite.
* @return a <code>Test</code> value
*/
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new XSLT("importProcessDefinitions"));
suite.addTest(new XSLT("invokeTest1"));
suite.addTest(new XSLT("invokeTest2"));
suite.addTest(new XSLT("invokeTest3"));
suite.addTest(new XSLT("invokeTest4"));
suite.addTest(new XSLT("invokeTest5"));
suite.addTest(new XSLT("invokeTest6"));
suite.addTest(new XSLT("invokeTest7"));
suite.addTest(new XSLT("invokeTest8"));
suite.addTest(new XSLT("invokeTest9"));
suite.addTest(new XSLT("invokeTest10"));
suite.addTest(new XSLT("invokeTest11"));
suite.addTest(new XSLT("invokeTest12"));
suite.addTest(new XSLT("invokeTest13"));
suite.addTest(new XSLT("invokeTest15"));
suite.addTest(new XSLT("removeProcessDefinition"));
return new EJBClientTest (plc, suite);
}
/**
* Initialisation.
* The <code>setUp</code> method defines the way a state change is
* realized. Override this method to change this way.
* @exception Exception if an error occurs
*/
protected void setUp() throws Exception {
super.setUp();
xpdlFile = "/tools/testXSLT.xml";
pdd = workflowService().processDefinitionDirectory();
}
/**
* Test a xslt tool invocation which returns a complex data type of DOM
* element.
* @exception Exception if an error occurs
*/
public void invokeTest1() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT1");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
assertTrue(stateReached(process, "closed.completed"));
Map map = (Map)process.result();
for (Iterator it = map.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
if (name.equals("result")) {
String returnResult = (String)map.get(name);
// check testXSLT.xml for the expected result
assertTrue(returnResult.equals("Matisse, Henri"));
}
}
}
/**
* Test a xslt tool invocation which returns a complex data type of DOM
* element.
* @exception Exception if an error occurs
*/
public void invokeTest2() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT2");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
assertTrue(stateReached(process, "closed.completed"));
Map map = (Map)process.result();
for (Iterator it = map.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
if (name.equals("result")) {
String returnResult = (String)map.get(name);
// check testXSLT.xml for the expected result
assertTrue(returnResult.equals("Matisse, Henri"));
}
}
}
/**
* Test a xslt tool invocation which returns a complex data type of DOM
* element.
* @exception Exception if an error occurs
*/
public void invokeTest3() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT3");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
assertTrue(stateReached(process, "closed.completed"));
Map map = (Map)process.result();
for (Iterator it = map.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
if (name.equals("result")) {
String returnResult = (String)map.get(name);
// check testXSLT.xml for the expected result
assertTrue(returnResult.equals("Matisse, Henri"));
}
if (name.equals("complexResult")) {
SAXEventBufferImpl myBuffer
= (SAXEventBufferImpl)map.get(name);
TransformerFactory tf
= TransformerFactory.newInstance();
SAXTransformerFactory saxTransFact = null;
if (tf.getFeature(SAXTransformerFactory.FEATURE)) {
saxTransFact = (SAXTransformerFactory)tf;
}
TransformerHandler transHand = null;
transHand = saxTransFact.newTransformerHandler();
DOMResult domResult = new DOMResult();
transHand.setResult(domResult);
myBuffer.emit(transHand);
Element returnResult = ((Document)domResult.getNode())
.getDocumentElement();
// org.w3c.dom.Element returnResult
// = (org.w3c.dom.Element)map.get(name);
// javax.xml.transform.stream.StreamResult streamResult
// = new javax.xml.transform.stream.StreamResult(System.out);
// javax.xml.transform.TransformerFactory tf
// = javax.xml.transform.TransformerFactory.newInstance();
// javax.xml.transform.Transformer serializer
// = tf.newTransformer();
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.ENCODING,"ISO-8859-1");
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.DOCTYPE_SYSTEM,
// "users.dtd");
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.INDENT,"yes");
// serializer.transform
// (new javax.xml.transform.dom.DOMSource(returnResult),
// streamResult);
XPath xpath = new DOMXPath("/table/record[1]/painter");
String value = xpath.stringValueOf(returnResult);
// check testXSLT.xml for the expected result
assertTrue(value.equals("Matisse, Henri"));
}
}
}
/**
* Test a xslt tool invocation which returns a complex data type of DOM
* element.
* @exception Exception if an error occurs
*/
public void invokeTest4() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT4");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
assertTrue(stateReached(process, "closed.completed"));
Map map = (Map)process.result();
for (Iterator it = map.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
if (name.equals("result")) {
String returnResult = (String)map.get(name);
// check testXSLT.xml for the expected result
assertTrue(returnResult.equals("Matisse, Henri"));
}
if (name.equals("complexResult")) {
SAXEventBufferImpl myBuffer
= (SAXEventBufferImpl)map.get(name);
TransformerFactory tf
= TransformerFactory.newInstance();
SAXTransformerFactory saxTransFact = null;
if (tf.getFeature(SAXTransformerFactory.FEATURE)) {
saxTransFact = (SAXTransformerFactory)tf;
}
TransformerHandler transHand = null;
transHand = saxTransFact.newTransformerHandler();
DOMResult domResult = new DOMResult();
transHand.setResult(domResult);
myBuffer.emit(transHand);
Element returnResult = ((Document)domResult.getNode())
.getDocumentElement();
// javax.xml.transform.stream.StreamResult streamResult
// = new javax.xml.transform.stream.StreamResult(System.out);
// javax.xml.transform.TransformerFactory tf
// = javax.xml.transform.TransformerFactory.newInstance();
// javax.xml.transform.Transformer serializer
// = tf.newTransformer();
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.ENCODING,"ISO-8859-1");
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.DOCTYPE_SYSTEM,
// "users.dtd");
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.INDENT,"yes");
// serializer.transform
// (new javax.xml.transform.dom.DOMSource(returnResult),
// streamResult);
XPath xpath = new DOMXPath("/table/record[1]/city");
String value = xpath.stringValueOf(returnResult);
// check testXSLT.xml for the expected result
assertTrue(value.equals("Weiterstadt"));
}
}
}
/**
* Test a xslt tool invocation which returns a complex data type of DOM
* element.
* @exception Exception if an error occurs
*/
public void invokeTest5() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT5");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
assertTrue(stateReached(process, "closed.completed"));
Map map = (Map)process.result();
for (Iterator it = map.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
if (name.equals("result")) {
String returnResult = (String)map.get(name);
// check testXSLT.xml for the expected result
assertTrue(returnResult.equals("Matisse, Henri"));
}
if (name.equals("complexResult")) {
SAXEventBufferImpl myBuffer
= (SAXEventBufferImpl)map.get(name);
TransformerFactory tf
= TransformerFactory.newInstance();
SAXTransformerFactory saxTransFact = null;
if (tf.getFeature(SAXTransformerFactory.FEATURE)) {
saxTransFact = (SAXTransformerFactory)tf;
}
TransformerHandler transHand = null;
transHand = saxTransFact.newTransformerHandler();
DOMResult domResult = new DOMResult();
transHand.setResult(domResult);
myBuffer.emit(transHand);
Element returnResult = ((Document)domResult.getNode())
.getDocumentElement();
// javax.xml.transform.stream.StreamResult streamResult
// = new javax.xml.transform.stream.StreamResult(System.out);
// javax.xml.transform.TransformerFactory tf =
// javax.xml.transform.TransformerFactory.newInstance();
// javax.xml.transform.Transformer serializer
// = tf.newTransformer();
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.ENCODING,"ISO-8859-1");
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.DOCTYPE_SYSTEM,
// "users.dtd");
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.INDENT,"yes");
// serializer.transform
// (new javax.xml.transform.dom.DOMSource(returnResult),
// streamResult);
XPath xpath = new DOMXPath("/table/row[1]/@painter");
String value = xpath.stringValueOf(returnResult);
// check testXSLT.xml for the expected result
assertTrue(value.equals("Matisse, Henri"));
}
}
}
/**
* Test a xslt tool invocation which returns a complex data type of DOM
* element.
* @exception Exception if an error occurs
*/
public void invokeTest6() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT6");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
// There should be a server error, because the result
// of the transformation is not wellformed.
assertTrue(stateReached(process, "closed.completed"));
}
/**
* Test a xslt tool invocation which returns a complex data type of DOM
* element.
* @exception Exception if an error occurs
*/
public void invokeTest7() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT7");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
assertTrue(stateReached(process, "closed.completed"));
Map map = (Map)process.result();
for (Iterator it = map.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
if (name.equals("result")) {
String returnResult = (String)map.get(name);
// check testXSLT.xml for the expected result
assertTrue(returnResult.equals("Hallo"));
}
}
}
/**
* Test a xslt tool invocation which returns a complex data type of DOM
* element.
* @exception Exception if an error occurs
*/
public void invokeTest8() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT8");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
// There should be a server error, because
// the transformation produces no xml.
assertTrue(stateReached(process, "closed.terminated"));
}
/**
* Test a xslt tool invocation which returns a complex data type of DOM
* element.
* @exception Exception if an error occurs
*/
public void invokeTest9() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT9");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
assertTrue(stateReached(process, "closed.completed"));
Map map = (Map)process.result();
for (Iterator it = map.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
if (name.equals("result")) {
String returnResult = (String)map.get(name);
// check testXSLT.xml for the expected result
assertTrue(returnResult.equals("Matisse, Henri"));
}
if (name.equals("complexResult")) {
SAXEventBufferImpl myBuffer
= (SAXEventBufferImpl)map.get(name);
TransformerFactory tf
= TransformerFactory.newInstance();
SAXTransformerFactory saxTransFact = null;
if (tf.getFeature(SAXTransformerFactory.FEATURE)) {
saxTransFact = (SAXTransformerFactory)tf;
}
TransformerHandler transHand = null;
transHand = saxTransFact.newTransformerHandler();
DOMResult domResult = new DOMResult();
transHand.setResult(domResult);
myBuffer.emit(transHand);
Element returnResult = ((Document)domResult.getNode())
.getDocumentElement();
// javax.xml.transform.stream.StreamResult streamResult
// = new javax.xml.transform.stream.StreamResult(System.out);
// javax.xml.transform.TransformerFactory tf
// = javax.xml.transform.TransformerFactory.newInstance();
// javax.xml.transform.Transformer serializer
// = tf.newTransformer();
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.ENCODING,"ISO-8859-1");
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.DOCTYPE_SYSTEM,
// "users.dtd");
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.INDENT,"yes");
// serializer.transform
// (new javax.xml.transform.dom.DOMSource(returnResult),
// streamResult);
XPath xpath = new DOMXPath("/table/record[1]/city");
String value = xpath.stringValueOf(returnResult);
// check testXSLT.xml for the expected result
assertTrue(value.equals("Darmstadt"));
}
}
}
/**
* Test a xslt tool invocation which returns a complex data type of DOM
* element.
* @exception Exception if an error occurs
*/
public void invokeTest10() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT10");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
assertTrue(stateReached(process, "closed.completed"));
Map map = (Map)process.result();
for (Iterator it = map.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
if (name.equals("result")) {
String returnResult = (String)map.get(name);
// check testXSLT.xml for the expected result
assertTrue(returnResult.equals("Matisse, Henri"));
}
if (name.equals("complexResult")) {
SAXEventBufferImpl myBuffer
= (SAXEventBufferImpl)map.get(name);
TransformerFactory tf
= TransformerFactory.newInstance();
SAXTransformerFactory saxTransFact = null;
if (tf.getFeature(SAXTransformerFactory.FEATURE)) {
saxTransFact = (SAXTransformerFactory)tf;
}
TransformerHandler transHand = null;
transHand = saxTransFact.newTransformerHandler();
DOMResult domResult = new DOMResult();
transHand.setResult(domResult);
myBuffer.emit(transHand);
Element returnResult = ((Document)domResult.getNode())
.getDocumentElement();
XPath xpath1 = new DOMXPath("/painters/table[1]/row[1]");
Element painter1
= (Element)xpath1.selectSingleNode(returnResult);
String value1 = painter1.getAttribute("painter");
// check testXSLT.xml for the expected result
assertTrue(value1.equals("Matisse, Henri"));
XPath xpath2 = new DOMXPath("/painters/table[2]/row[2]");
Element painter2
= (Element)xpath2.selectSingleNode(returnResult);
String value2 = painter2.getAttribute("painter");
// check testXSLT.xml for the expected result
assertTrue(value2.equals("Monet, Claude"));
}
}
}
/**
* Test a xslt tool invocation which returns a complex data type of DOM
* element.
* @exception Exception if an error occurs
*/
public void invokeTest11() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT11");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
assertTrue(stateReached(process, "closed.completed"));
Map map = (Map)process.result();
for (Iterator it = map.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
if (name.equals("result")) {
String returnResult = (String)map.get(name);
// check testXSLT.xml for the expected result
assertTrue(returnResult.equals("Matisse, Henri"));
}
if (name.equals("complexResult")) {
SAXEventBufferImpl myBuffer
= (SAXEventBufferImpl)map.get(name);
TransformerFactory tf
= TransformerFactory.newInstance();
SAXTransformerFactory saxTransFact = null;
if (tf.getFeature(SAXTransformerFactory.FEATURE)) {
saxTransFact = (SAXTransformerFactory)tf;
}
TransformerHandler transHand = null;
transHand = saxTransFact.newTransformerHandler();
DOMResult domResult = new DOMResult();
transHand.setResult(domResult);
myBuffer.emit(transHand);
Element returnResult = ((Document)domResult.getNode())
.getDocumentElement();
XPath xpath = new DOMXPath("/painters/table[3]/row[3]");
Element painter
= (Element)xpath.selectSingleNode(returnResult);
String value = painter.getAttribute("title");
// check testXSLT.xml for the expected result
assertTrue(value.equals("Poplars along the River Epte, Autumn"));
}
}
}
/**
* Test a xslt tool invocation which returns a complex data type of DOM
* element.
* @exception Exception if an error occurs
*/
public void invokeTest12() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT12");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
assertTrue(stateReached(process, "closed.completed"));
Map map = (Map)process.result();
for (Iterator it = map.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
if (name.equals("complexResult")) {
SAXEventBufferImpl myBuffer
= (SAXEventBufferImpl)map.get(name);
TransformerFactory tf
= TransformerFactory.newInstance();
SAXTransformerFactory saxTransFact = null;
if (tf.getFeature(SAXTransformerFactory.FEATURE)) {
saxTransFact = (SAXTransformerFactory)tf;
}
TransformerHandler transHand = null;
transHand = saxTransFact.newTransformerHandler();
DOMResult domResult = new DOMResult();
transHand.setResult(domResult);
myBuffer.emit(transHand);
Element returnResult = ((Document)domResult.getNode())
.getDocumentElement();
// javax.xml.transform.stream.StreamResult streamResult
// = new javax.xml.transform.stream.StreamResult(System.out);
// tf
// = javax.xml.transform.TransformerFactory.newInstance();
// javax.xml.transform.Transformer serializer
// = tf.newTransformer();
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.ENCODING,"ISO-8859-1");
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.DOCTYPE_SYSTEM,
// "users.dtd");
// serializer.setOutputProperty
// (javax.xml.transform.OutputKeys.INDENT,"yes");
// serializer.transform
// (new javax.xml.transform.dom.DOMSource(returnResult),
// streamResult);
XPath xpath = new DOMXPath("/row");
Element painter
= (Element)xpath.selectSingleNode(returnResult);
String value = painter.getAttribute("title");
// check testXSLT.xml for the expected result
assertTrue(value.equals("La Musique"));
}
}
}
/**
* Test a xslt tool invocation which returns a complex data type of DOM
* element.
* @exception Exception if an error occurs
*/
public void invokeTest13() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT13");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
assertTrue(stateReached(process, "closed.completed"));
Map map = (Map)process.result();
for (Iterator it = map.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
if (name.equals("complexResult")) {
SAXEventBufferImpl myBuffer
= (SAXEventBufferImpl)map.get(name);
SAXHandler sh = new SAXHandler ();
sh.startDocument();
sh.startElement
("", "temporary-root", "temporary-root", new AttributesImpl());
myBuffer.emit(sh, (LexicalHandler)sh);
sh.endElement ("", "temporary-root", "temporary-root");
sh.endDocument();
org.jdom.Element temporaryRoot = sh.getDocument().getRootElement();
XPath xpath = new JDOMXPath("/temporary-root/row[2]");
org.jdom.Element painter
= (org.jdom.Element)xpath.selectSingleNode(temporaryRoot);
String value = painter.getAttribute("title").getValue();
// check testXSLT.xml for the expected result
assertTrue(value.equals("The Artist's Garden at Vetheuil"));
}
}
}
/**
* @exception Exception if an error occurs
*/
public void invokeTest15() throws Exception {
ProcessMgr pmgr = pdd.processMgr("st-testXSLT", "testXSLT15");
WfProcess process = pmgr.createProcess(defaultRequester());
process.start();
assertTrue(stateReached(process, "closed.completed"));
Map map = (Map)process.result();
Date dt = (Date)map.get("datetime");
assertTrue
(dt.equals(XMLUtil.parseXsdDateTime("2005-12-14T14:15:16")));
Double fv = (Double)map.get("floatval");
assertTrue(fv.doubleValue() == 2005);
Long iv = (Long)map.get("intval");
assertTrue(iv.intValue() == 41);
Boolean bv = (Boolean)map.get("boolval");
assertTrue(bv.booleanValue());
}
/**
* Test a simple process definition with a simple soap tool invocation.
* @exception Exception if an error occurs
*/
public void removeProcessDefinition() throws Exception {
removeProcessDefinition("st-testXSLT", "testXSLT1");
removeProcessDefinition("st-testXSLT", "testXSLT2");
removeProcessDefinition("st-testXSLT", "testXSLT3");
removeProcessDefinition("st-testXSLT", "testXSLT4");
removeProcessDefinition("st-testXSLT", "testXSLT5");
removeProcessDefinition("st-testXSLT", "testXSLT6");
removeProcessDefinition("st-testXSLT", "testXSLT7");
removeProcessDefinition("st-testXSLT", "testXSLT8");
removeProcessDefinition("st-testXSLT", "testXSLT9");
removeProcessDefinition("st-testXSLT", "testXSLT10");
removeProcessDefinition("st-testXSLT", "testXSLT11");
removeProcessDefinition("st-testXSLT", "testXSLT12");
removeProcessDefinition("st-testXSLT", "testXSLT13");
removeProcessDefinition("st-testXSLT", "testXSLT15");
}
public static class BodyFiller extends org.xml.sax.helpers.XMLFilterImpl {
private boolean hasStartDocument = false;
private boolean hasEndDocument = false;
/**
* Create a new BodyFiller.
* @param contentHandler the given content handler.
*/
public BodyFiller(ContentHandler contentHandler) {
this.setContentHandler(contentHandler);
}
/**
* @throws SAXException if any SAX processing error ocurred.
*/
public void startDocument() throws SAXException {
this.getContentHandler().startDocument();
hasStartDocument = true;
}
/**
* @throws SAXException if any SAX processing error ocurred.
*/
public void endDocument () throws SAXException {
if (!hasEndDocument) {
this.getContentHandler().endDocument();
hasEndDocument = true;
}
}
/**
* @throws SAXException if any SAX processing error ocurred.
*/
public void startElement(String uri, String localName,
String qName, Attributes atts)
throws SAXException {
if (!hasStartDocument) {
this.getContentHandler().startDocument();
hasStartDocument = true;
}
this.getContentHandler().startElement(uri, localName, qName, atts);
}
/**
* @throws SAXException if any SAX processing error ocurred.
*/
public void endPrefixMapping(String prefix) throws SAXException {
if (!hasEndDocument) {
this.getContentHandler().endDocument();
hasEndDocument = true;
}
this.getContentHandler().endPrefixMapping(prefix);
}
}
public static class MyContentHandler
implements org.xml.sax.ContentHandler {
private static final org.apache.commons.logging.Log logger
= org.apache.commons.logging.LogFactory.getLog
(MyContentHandler.class);
public void characters(char[] ch, int start, int length) {
logger.info
("characters(" + ch + ", " + start + ", "+ length + ")");
}
public void endDocument() {
logger.info("endDocument()");
}
public void endElement
(String namespaceURI, String localName, String qName) {
logger.info
("endElement(" + namespaceURI + ", "
+ localName + ", "+ qName + ")");
}
public void endPrefixMapping(String prefix) {
logger.info("endPrefixMapping(" + prefix + ")");
}
public void ignorableWhitespace(char[] ch, int start, int length) {
logger.info
("ignorableWhitespace(" + ch + ", " + start + ", "
+ length + ")");
}
public void processingInstruction(String target, String data) {
logger.info("processingInstruction(" + target + ", " + data + ")");
}
public void setDocumentLocator(org.xml.sax.Locator locator) {
logger.info("setDocumentLocator(" + locator + ")");
}
public void skippedEntity(String name) {
logger.info("skippedEntity(" + name + ")");
}
public void startDocument() {
logger.info("startDocument()");
}
public void startElement(String namespaceURI, String localName,
String qName, org.xml.sax.Attributes atts) {
logger.info("startElement(" + namespaceURI + ", " + localName
+ ", " + qName + ")");
}
public void startPrefixMapping(String prefix, String uri) {
logger.info("startPrefixMapping(" + prefix + ", " + uri + ")");
}
}
private boolean stateReached(WfProcess proc,
String procState)
throws Exception {
boolean test = true;
boolean stateReached = false;
int maxRetries = 100;
while (test){
if (maxRetries-- > 0) {
if (proc.state().startsWith(procState)) {
stateReached = true;
test = false;
} else {
Thread.sleep(500);
}
} else {
test = false;
}
}
return stateReached;
}
}