1 package org.jbpm.bpel.def.assign; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 import javax.xml.namespace.QName ; 7 8 import junit.framework.TestCase; 9 10 import org.w3c.dom.Element ; 11 12 import org.jbpm.context.def.ContextDefinition; 13 import org.jbpm.graph.def.ProcessDefinition; 14 import org.jbpm.graph.exe.ProcessInstance; 15 import org.jbpm.graph.exe.Token; 16 17 import org.jbpm.bpel.data.def.ElementTypeInfo; 18 import org.jbpm.bpel.data.def.Snippet; 19 import org.jbpm.bpel.data.def.VariableDefinition; 20 import org.jbpm.bpel.xml.BpelConstants; 21 import org.jbpm.bpel.xml.BpelException; 22 import org.jbpm.bpel.xml.util.NodeUtil; 23 24 28 public class FromExpressionTest extends TestCase { 29 30 private FromExpression from = new FromExpression(); 31 private Token token; 32 private Map namespaceDeclarations; 33 34 private static final String ELEM1_TEXT = 35 "<a>" + 36 " <b on=\"true\">true</b>" + 37 " <c name=\"venus\"/>" + 38 " <d amount=\"20\"/>" + 39 " <e>30</e>" + 40 "</a>"; 41 private static final String ELEM2_TEXT = 42 "<a>" + 43 " <b on=\"\"/>" + 44 " <c name=\"mars\"/>" + 45 " <d amount=\"30\"/>" + 46 " <e>40</e>" + 47 "</a>"; 48 49 public FromExpressionTest(String name) { 50 super(name); 51 } 52 53 protected void setUp() throws Exception { 54 ProcessDefinition pd = new ProcessDefinition(); 56 pd.addDefinition(new ContextDefinition()); 57 ProcessInstance pi = new ProcessInstance(pd); 58 token = pi.getRootToken(); 59 Element elem1 = NodeUtil.parseElement(ELEM1_TEXT); 61 VariableDefinition var1 = new VariableDefinition(); 62 var1.setName("var1"); 63 var1.setTypeInfo(new ElementTypeInfo(new QName (elem1.getNamespaceURI(), elem1.getLocalName()))); 64 var1.createInstance(token).setValue(elem1); 65 Element elem2 = NodeUtil.parseElement(ELEM2_TEXT); 66 VariableDefinition var2 = new VariableDefinition(); 67 var2.setName("var2"); 68 var2.setTypeInfo(new ElementTypeInfo(new QName (elem2.getNamespaceURI(), elem2.getLocalName()))); 69 var2.createInstance(token).setValue(elem2); 70 namespaceDeclarations = new HashMap (); 72 namespaceDeclarations.put("bpws", BpelConstants.NS_BPWS_1_1); 73 } 74 75 public void testExtract() { 76 try { 77 Snippet expr = new Snippet(); 78 expr.setText("concat(bpws:getVariableData('var1')/c/@name, 'and', bpws:getVariableData('var2')/c/@name)"); 79 expr.setUse(Snippet.Use.EXPRESSION); 80 expr.setNamespaces(namespaceDeclarations); 81 expr.parseScript(); 82 from.setExpression(expr); 83 assertEquals("venusandmars", from.extract(token)); 84 } 85 catch (BpelException e) { 86 fail(e.getMessage()); 87 } 88 } 89 } 90 | Popular Tags |