1 package org.jbpm.bpel.def.assign; 2 3 import javax.wsdl.Definition; 4 import javax.xml.namespace.QName ; 5 6 import junit.framework.TestCase; 7 8 import org.w3c.dom.Element ; 9 10 import org.jbpm.graph.exe.ProcessInstance; 11 import org.jbpm.graph.exe.Token; 12 13 import org.jbpm.bpel.data.def.VariableDefinition; 14 import org.jbpm.bpel.data.exe.MessageVariableInstance; 15 import org.jbpm.bpel.def.BpelDefinition; 16 import org.jbpm.bpel.def.ImportsDefinition; 17 import org.jbpm.bpel.wsdl.util.WsdlUtil; 18 import org.jbpm.bpel.xml.BpelConstants; 19 import org.jbpm.bpel.xml.BpelReader; 20 import org.jbpm.bpel.xml.util.NodeUtil; 21 22 26 public class FromPropertyTest extends TestCase { 27 28 private Token token; 29 private MessageVariableInstance messageInstance; 30 private FromProperty from = new FromProperty(); 31 32 private static final String WSDL_TEXT = 33 "<definitions targetNamespace='http://jbpm.org/bpel/examples'" + 34 " xmlns:tns='http://jbpm.org/bpel/examples'" + 35 " xmlns:xsd='http://www.w3.org/2001/XMLSchema'" + 36 " xmlns:bpws='http://schemas.xmlsoap.org/ws/2004/03/business-process/'" + 37 " xmlns='http://schemas.xmlsoap.org/wsdl/'>" + 38 " <message name='request'>" + 39 " <part name='simplePart' type='xsd:string'/>" + 40 " <part name='elementPart' element='tns:surpriseElement'/>" + 41 " </message>" + 42 " <bpws:property name='nameProperty' type='xsd:string'/>" + 43 " <bpws:property name='idProperty' type='xsd:int'/>" + 44 " <bpws:propertyAlias propertyName='tns:nameProperty' messageType='tns:request'>" + 45 " <bpws:query>elementPart/tns:surpriseElement/c/@name</bpws:query>" + 46 " </bpws:propertyAlias>" + 47 " <bpws:propertyAlias propertyName='tns:idProperty' messageType='tns:request'>" + 48 " <bpws:query>elementPart/tns:surpriseElement/e</bpws:query>" + 49 " </bpws:propertyAlias>" + 50 "</definitions>"; 51 private static final String ELEM_PART_TEXT = 52 "<tns:surpriseElement xmlns:tns='http://jbpm.org/bpel/examples'>" + 53 " <b on=\"true\">true</b>" + 54 " <c name=\"venus\"/>" + 55 " <d amount=\"20\"/>" + 56 " <e>30</e>" + 57 "</tns:surpriseElement>"; 58 private static final QName Q_NAME_PROP = new QName (BpelConstants.NS_EXAMPLES, "nameProperty"); 59 60 public FromPropertyTest(String name) { 61 super(name); 62 } 63 64 protected void setUp() throws Exception { 65 BpelDefinition pd = new BpelDefinition(); 67 token = new ProcessInstance(pd).getRootToken(); 68 Definition def = WsdlUtil.readText(WSDL_TEXT); 70 ImportsDefinition imports = pd.getImports(); 71 imports.addImport(WsdlUtil.createImport(def)); 72 BpelReader.getInstance().registerPropertyAliases(imports); 73 VariableDefinition messageDefinition = new VariableDefinition(); 75 messageDefinition.setName("msg"); 76 messageDefinition.setTypeInfo(imports.getMessageTypeInfo(new QName (BpelConstants.NS_EXAMPLES, "request"))); 77 messageInstance = (MessageVariableInstance) messageDefinition.createInstance(token); 78 } 79 80 public void testExtract() throws Exception { 81 Element partValue = NodeUtil.parseElement(ELEM_PART_TEXT); 82 messageInstance.setPart("elementPart", partValue); 83 84 from.setVariable(messageInstance.getDefinition()); 85 from.setProperty(Q_NAME_PROP); 86 assertEquals("venus", from.extract(token)); 87 } 88 } 89 | Popular Tags |