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.w3c.dom.Document ; 15 import org.w3c.dom.Element ; 16 17 import org.jbpm.graph.exe.ProcessInstance; 18 import org.jbpm.graph.exe.Token; 19 20 import org.jbpm.bpel.data.def.MessageTypeInfo; 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.BpelReader; 28 29 33 public class GetVariablePropertyTest extends TestCase { 34 35 private MessageVariableInstance messageInstance; 36 private Context context; 37 38 private static final String WSDL_TEXT = 39 "<definitions targetNamespace='http://jbpm.org/bpel/examples'" + 40 " xmlns:tns='http://jbpm.org/bpel/examples'" + 41 " xmlns:xsd='http://www.w3.org/2001/XMLSchema'" + 42 " xmlns:bpws='http://schemas.xmlsoap.org/ws/2004/03/business-process/'" + 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 " <bpws:property name='nameProperty' type='xsd:string'/>" + 49 " <bpws:property name='idProperty' type='xsd:int'/>" + 50 " <bpws:propertyAlias propertyName='tns:nameProperty' messageType='tns:request'>" + 51 " <bpws:query>elementPart/tns:surpriseElement/c/@name</bpws:query>" + 52 " </bpws:propertyAlias>" + 53 " <bpws:propertyAlias propertyName='tns:idProperty' messageType='tns:request'>" + 54 " <bpws:query>elementPart/tns:surpriseElement/e</bpws:query>" + 55 " </bpws:propertyAlias>" + 56 "</definitions>"; 57 58 public GetVariablePropertyTest(String name) { 59 super(name); 60 } 61 62 protected void setUp() throws Exception { 63 BpelDefinition pd = new BpelDefinition(); 65 Token token = new ProcessInstance(pd).getRootToken(); 66 Definition def = WsdlUtil.readText(WSDL_TEXT); 68 ImportsDefinition imports = pd.getImports(); 69 imports.addImport(WsdlUtil.createImport(def)); 70 BpelReader.getInstance().registerPropertyAliases(imports); 71 MessageTypeInfo typeInfo = imports.getMessageTypeInfo(new QName (BpelConstants.NS_EXAMPLES, "request")); 73 VariableDefinition messageDefinition = new VariableDefinition(); 74 messageDefinition.setName("msg"); 75 messageDefinition.setTypeInfo(typeInfo); 76 messageInstance = (MessageVariableInstance) messageDefinition.createInstance(token); 77 ContextSupport sup = new ContextSupport(); 79 sup.setVariableContext(new ScopeVariables(token)); 80 Map namespaceDeclarations = def.getNamespaces(); 82 namespaceDeclarations.remove(""); 84 sup.setNamespaceContext(new SimpleNamespaceContext(namespaceDeclarations)); 85 context = new Context(sup); 86 } 87 88 public void testEvaluateAttribute() throws FunctionCallException { 89 Element elementPart = messageInstance.getOrCreatePart("elementPart"); 90 Document doc = elementPart.getOwnerDocument(); 91 Element elemC = (Element ) elementPart.appendChild(doc.createElementNS(null, "c")); 92 elemC.setAttribute("name", "wazabi"); 93 assertEquals("wazabi", GetVariablePropertyFunction.evaluate("msg", "tns:nameProperty", context)); 94 } 95 96 public void testEvaluateElement() throws FunctionCallException { 97 Element elementPart = messageInstance.getOrCreatePart("elementPart"); 98 Document doc = elementPart.getOwnerDocument(); 99 Element elemE = (Element ) elementPart.appendChild(doc.createElementNS(null, "e")); 100 elemE.appendChild(doc.createTextNode("30")); 101 assertEquals("30", GetVariablePropertyFunction.evaluate("msg", "tns:idProperty", context)); 102 } 103 } 104 | Popular Tags |