WEB开发网
开发学院软件开发Java 基于JBPM的简单报销实例 阅读

基于JBPM的简单报销实例

 2009-09-21 00:00:00 来源:WEB开发网   
核心提示: 6. 结束任务 在Junit中进行测试: Java代码packagecn.senta.test;importjava.util.List;importorg.jbpm.JbpmConfiguration;importorg.jbpm.JbpmContext;importorg.jbpm.db.G

6. 结束任务

在Junit中进行测试:

Java代码  

package cn.senta.test; 
 
import java.util.List; 
import org.jbpm.JbpmConfiguration; 
import org.jbpm.JbpmContext; 
import org.jbpm.db.GraphSession; 
import org.jbpm.graph.def.ProcessDefinition; 
import org.jbpm.graph.exe.ProcessInstance; 
import org.jbpm.taskmgmt.exe.TaskInstance; 
import junit.framework.TestCase; 
 
public class TestJBPM extends TestCase { 
 
 /** 
 * 创建表结构 
 */ 
 public void testCreateSchema() { 
 JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance(); 
 jbpmConfiguration.createSchema(); 
 System.out.println("the database is created successfully!"); 
 } 
 
 /** 
 * 部署流程定义 
 */ 
 public void testDeployProcessDifinition() { 
 JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance(); 
 JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext(); 
 try { 
  ProcessDefinition pd = ProcessDefinition 
   .parseXmlResource("cn/senta/bx/processdefinition.xml"); 
  jbpmContext.deployProcessDefinition(pd); 
 } finally { 
  if (jbpmContext != null) { 
  jbpmContext.close(); 
  } 
 } 
 System.out.println("the deploy is successful!"); 
 } 
 
 /** 
 * 启动流程实例 
 */ 
 public void testStartProcessInstance() { 
 JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance(); 
 JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext(); 
 try { 
  GraphSession graphSession = jbpmContext.getGraphSession(); 
  ProcessDefinition processDefinition = graphSession 
   .findLatestProcessDefinition("test"); 
  ProcessInstance processInstance = new ProcessInstance( 
   processDefinition); 
  jbpmContext.save(processInstance); 
  processInstance.signal(); 
 } finally { 
  if (jbpmContext != null) { 
  jbpmContext.close(); 
  } 
 } 
 System.out.println("the startProcess is successful !"); 
 } 
 
 /** 
 * 获取任务列表 
 */ 
 @SuppressWarnings("unchecked") 
 public void testGetTaskList() { 
 String actorId = "employee"; 
 JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance(); 
 JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext(); 
 try { 
  List<TaskInstance> tasks = jbpmContext.getTaskList(actorId); 
  for (TaskInstance ti : tasks) { 
  System.out.println("id=" + ti.getId() + ", name=" 
   + ti.getName() + ", create=" + ti.getCreate() 
   + ", start=" + ti.getStart() + ", end=" + ti.getEnd()); 
  } 
 } finally { 
  if (jbpmContext != null) { 
  jbpmContext.close(); 
  } 
 } 
 System.out.println("you get the tasklist successfully!"); 
 } 
 
 /** 
 * 执行任务 
 */ 
 public void testStartTask() { 
 long taskInstanceId = 1; 
 JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance(); 
 JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext(); 
 try { 
  TaskInstance taskInstance = jbpmContext 
   .getTaskInstance(taskInstanceId); 
  taskInstance.start(); 
  jbpmContext.save(taskInstance); 
 
 } finally { 
  if (jbpmContext != null) { 
  jbpmContext.close(); 
  } 
 } 
 System.out.println("the task is started successfully!"); 
 } 
 /** 
 * 结束任务 
 */ 
 public void testEndTask(){ 
 long taskInstanceId=1; 
 JbpmConfiguration jbpmConfiguration=JbpmConfiguration.getInstance(); 
 JbpmContext jbpmContext=jbpmConfiguration.createJbpmContext(); 
 try{ 
  TaskInstance taskInstance=jbpmContext.getTaskInstance(taskInstanceId); 
  taskInstance.end(); 
  jbpmContext.save(taskInstance); 
 }finally{ 
  if(jbpmContext!=null){ 
  jbpmContext.close(); 
  } 
 } 
 System.out.println("the task is ended successfully!"); 
 } 
 
} 
 

工程目录结构

基于JBPM的简单报销实例

上一页  1 2 3 

Tags:基于 JBPM 简单

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接