3.Activiti6.0.0+Spring+Junit

环境及主要框架版本

JDK 1.8.0_112
maven 3.3.9
springframework 4.3.10.RELEASE
druid 1.1.2
junit 4.12

1.注意要加入spring-test及junit


  org.springframework
  spring-test
  4.3.10.RELEASE
  test


  junit
  junit
  ${junit.version}
  test

2.加入测试资源文件夹 设置为Test Sources Root
加入流程文件及配置文件applicationConfig.xml,数据库连接池根据需要自行配置




    
    
    
        
        

        
        
        
        

        
        
        
        

        
        

        
        

        
        

        
        
        
        
    

    
    
        
    

    
    
        
    
    
        
        
        
    

    
    
    
    
    
    

    
    
        
    


3.加入测试类ActivitiSpringTest

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationConfig.xml")
public class ActivitiSpringTest {

    @Autowired
    private ProcessEngine processEngine;
    @Autowired
    private RepositoryService repositoryService;
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private RuntimeService historyService;
    @Autowired
    private TaskService managementService;

    @Test
    public void deploy() {
        Deployment deployment = repositoryService.createDeployment().name("MyProcess")
                .addClasspathResource("diagrams/MyProcess.bpmn").addClasspathResource("diagrams/MyProcess.png")
                .deploy();

        ProcessInstance pi = runtimeService.startProcessInstanceByKey("myProcess");
        System.out.println("流程实例" + pi.getId());

        List list = taskService.createTaskQuery().taskAssignee("张三").list();
        System.out.println("任务个数" + list.size());
        if (list != null && list.size() > 0) {
            for (Task t : list) {
                System.out.print(t.getId() + ",");
                System.out.print(t.getName() + ",");
                System.out.print(t.getAssignee() + ",");
                System.out.println(t.getProcessInstanceId());
            }
        }
    }

}

最终目录及文件如下


3.Activiti6.0.0+Spring+Junit_第1张图片

你可能感兴趣的:(3.Activiti6.0.0+Spring+Junit)