public ActivitiRule activitiRule = new ActivitiRule();
@Test
public void startProcess() throws Exception {
TaskService taskService = activitiRule.getTaskService();
RuntimeService runtimeService = activitiRule.getRuntimeService();
RepositoryService repositoryService = activitiRule.getRepositoryService();
// 部署两个流程
repositoryService.createDeployment().addInputStream("master.bpmn20.xml", new FileInputStream(filename)).deploy();
repositoryService.createDeployment().addInputStream("business.bpmn20.xml", new FileInputStream(filename1)).deploy();
// 准备变量
Map<String, Object> variableMap = new HashMap<String, Object>();
List<String> users = new ArrayList<String>();
users.add("user1");
users.add("user2");
users.add("user3");
variableMap.put("users", users);
// 启动时用123456作为业务ID
String businessKey = "123456";
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("master", businessKey, variableMap);
assertNotNull(processInstance.getId());
System.out.println("id " + processInstance.getId() + " " + processInstance.getProcessDefinitionId());
assertNotNull(runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(businessKey).singleResult());
// 根据主流程的流程实例ID查询子流程(调用活动的多个实例,每一个都是一个独立的流程)
List<ProcessInstance> subProcessInstances = runtimeService.createProcessInstanceQuery()
.superProcessInstanceId(processInstance.getProcessInstanceId()).list();
assertEquals(3, subProcessInstances.size());
for (ProcessInstance subProcessInstance : subProcessInstances) {
assertNull(subProcessInstance.getBusinessKey());
}