简单报销实例(3)
时间:2011-01-04 javaeye lqw8668
在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;
JbpmCo
|