package com.amway.test; import org.jbpm.JbpmConfiguration; import org.jbpm.JbpmContext; import org.jbpm.context.exe.ContextInstance; import org.jbpm.graph.def.ProcessDefinition; import org.jbpm.graph.exe.ProcessInstance; import org.jbpm.graph.exe.Token; import junit.framework.TestCase; public class TestProcessVariable extends TestCase { public void testProcessVaribles(){ StringBuffer sb = new StringBuffer(); sb.append("<process-definition name='hello'>"); sb.append("<start-state name='start'>"); sb.append("<transition to='s'/>"); sb.append("</start-state>"); sb.append("<state name='s'>"); sb.append("<transition to='end'/>"); sb.append("</state>"); sb.append("<end-state name='end'/>"); sb.append("</process-definition>"); //流程定义 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(sb.toString()); //流程实列 ProcessInstance instance = new ProcessInstance(processDefinition); //获取流程的上下文 ContextInstance contextInstance = instance.getContextInstance(); //在上下文对象设置内容,就像session contextInstance.setVariable("amount", new Integer(500)); contextInstance.setVariable("reason", "I met my deadLine"); //流程流转 //类似 Token token = instance.getRootToken(); //token.signal(); instance.signal(); this.assertEquals("s", instance.getRootToken().getNode().getName()); this.assertEquals(500, contextInstance.getVariable("amount")); this.assertEquals("I met my deadLine", contextInstance.getVariable("reason")); } }