package org.activiti.designer.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.test.ActivitiRule;
import org.junit.Rule;
import org.junit.Test;
public class ProcessTestNoUserSet {
private String filename = "/Users/henryyan/work/projects/activiti/activiti-study/src/test/resources/diagrams/NoUserSet.bpmn";
@Rule
public ActivitiRule activitiRule = new ActivitiRule();
@Test
public void startProcess() throws Exception {
RepositoryService repositoryService = activitiRule.getRepositoryService();
repositoryService.createDeployment().addInputStream("NoUserSet.bpmn20.xml", new FileInputStream(filename)).deploy();
RuntimeService runtimeService = activitiRule.getRuntimeService();
Map<String, Object> variableMap = new HashMap<String, Object>();
variableMap.put("name", "Activiti");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("NoUserSet", variableMap);
assertNotNull(processInstance.getId());
System.out.println("id " + processInstance.getId() + " " + processInstance.getProcessDefinitionId());
TaskService taskService = activitiRule.getTaskService();
Task task = taskService.createTaskQuery().singleResult();
variableMap = new HashMap<String, Object>();
variableMap.put("task2Users", new ArrayList<String>());
taskService.complete(task.getId(), variableMap);
task = taskService.createTaskQuery().singleResult();
variableMap = new HashMap<String, Object>();
variableMap.put("multiUsers", new ArrayList<String>());
taskService.complete(task.getId(), variableMap);
HistoryService historyService = activitiRule.getHistoryService();
long count = historyService.createHistoricProcessInstanceQuery().finished().count();
assertEquals(1, count);
}
}