1 package org.jbpm.bpel.data.xpath; 2 3 import java.util.Map ; 4 5 import javax.wsdl.Definition; 6 import javax.xml.namespace.QName ; 7 8 import junit.framework.TestCase; 9 10 import org.jaxen.Context; 11 import org.jaxen.ContextSupport; 12 import org.jaxen.FunctionCallException; 13 import org.jaxen.SimpleNamespaceContext; 14 import org.jaxen.dom.DocumentNavigator; 15 import org.w3c.dom.Attr ; 16 import org.w3c.dom.Element ; 17 18 import org.jbpm.graph.exe.ProcessInstance; 19 import org.jbpm.graph.exe.Token; 20 21 import org.jbpm.bpel.data.def.VariableDefinition; 22 import org.jbpm.bpel.data.exe.MessageVariableInstance; 23 import org.jbpm.bpel.def.BpelDefinition; 24 import org.jbpm.bpel.def.ImportsDefinition; 25 import org.jbpm.bpel.wsdl.util.WsdlUtil; 26 import org.jbpm.bpel.xml.BpelConstants; 27 import org.jbpm.bpel.xml.util.NodeUtil; 28 29 33 public class GetVariableDataTest extends TestCase { 34 35 private MessageVariableInstance messageInstance; 36 private Context context; 37 private Map namespaceDeclarations; 38 39 private static final String WSDL_TEXT = 40 "<definitions targetNamespace='http://jbpm.org/bpel/examples'" + 41 " xmlns:tns='http://jbpm.org/bpel/examples'" + 42 " xmlns:xsd='http://www.w3.org/2001/XMLSchema'" + 43 " xmlns='http://schemas.xmlsoap.org/wsdl/'>" + 44 " <message name='request'>" + 45 " <part name='simplePart' type='xsd:string'/>" + 46 " <part name='elementPart' element='tns:surpriseElement'/>" + 47 " </message>" + 48 "</definitions>"; 49 private static final String ELEM_PART_TEXT = 50 "<tns:surpriseElement xmlns:tns='http://jbpm.org/bpel/examples'>" + 51 " <b on=\"true\">true</b>" + 52 " <c name=\"venus\"/>" + 53 " <d amount=\"20\"/>" + 54 " <e>30</e>" + 55 "</tns:surpriseElement>"; 56 57 public GetVariableDataTest(String name) { 58 super(name); 59 } 60 61 protected void setUp() throws Exception { 62 BpelDefinition pd = new BpelDefinition(); 64 ProcessInstance pi = new ProcessInstance(pd); 65 Token token = pi.getRootToken(); 66 Definition def = WsdlUtil.readText(WSDL_TEXT); 68 ImportsDefinition imports = pd.getImports(); 69 imports.addImport(WsdlUtil.createImport(def)); 70 VariableDefinition messageDefinition = new VariableDefinition(); 72 messageDefinition.setName("msg"); 73 messageDefinition.setTypeInfo(imports.getMessageTypeInfo(new QName (BpelConstants.NS_EXAMPLES, "request"))); 74 messageInstance = (MessageVariableInstance) messageDefinition.createInstance(token); 75 namespaceDeclarations = def.getNamespaces(); 77 namespaceDeclarations.remove(""); 78 ContextSupport sup = new ContextSupport(new SimpleNamespaceContext(namespaceDeclarations), 80 null, new ScopeVariables(token), DocumentNavigator.getInstance()); 81 context = new Context(sup); 82 } 83 84 public void testEvaluateVariable() throws FunctionCallException { 85 messageInstance.setMessage(MessageVariableInstance.createMessageElement()); 86 assertSame(messageInstance.getValue(), GetVariableDataFunction.evaluate("msg", context)); 87 } 88 89 public void testEvaluateSimplePart() throws FunctionCallException { 90 Element simplePart = messageInstance.getOrCreatePart("simplePart"); 91 assertSame(simplePart, GetVariableDataFunction.evaluate("msg", "simplePart", context)); 92 } 93 94 public void testEvaluateElementPart() throws FunctionCallException { 95 Element elementPart = messageInstance.getOrCreatePart("elementPart"); 96 assertSame(elementPart, GetVariableDataFunction.evaluate("msg", "elementPart", context)); 97 } 98 99 public void testEvaluateAttributeLocation() throws Exception { 100 Element partValue = NodeUtil.parseElement(ELEM_PART_TEXT); 101 messageInstance.setPart("elementPart", partValue); 102 Element c = NodeUtil.getElement(messageInstance.getPart("elementPart"), "c"); 103 Attr nameAttr = c.getAttributeNode("name"); 104 Object data = GetVariableDataFunction.evaluate("msg", "elementPart", "/tns:surpriseElement/c/@name", context); 105 assertSame(nameAttr, data); 106 } 107 108 public void testEvaluateElementLocation() throws Exception { 109 Element partValue = NodeUtil.parseElement(ELEM_PART_TEXT); 110 messageInstance.setPart("elementPart", partValue); 111 Element e = NodeUtil.getElement(messageInstance.getPart("elementPart"), "e"); 112 Object data = GetVariableDataFunction.evaluate("msg", "elementPart", "/tns:surpriseElement/e", context); 113 assertSame(e, data); 114 } 115 } 116 | Popular Tags |