Java Code Examples for org.activiti.engine.TaskService#complete()

The following examples show how to use org.activiti.engine.TaskService#complete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBPMN001.java    From bamboobsc with Apache License 2.0 6 votes vote down vote up
@Test
public void completeTask() throws Exception {
	
	String assignee = "張三";
	//String assignee = "王經理";
			
	TaskService taskService = (TaskService) AppContext.getBean("taskService");
	List<Task> tasks = taskService.createTaskQuery().list();
	if (tasks == null || tasks.size()<1 ) {
		System.out.println("no task.");
		return;
	}
	for (Task task : tasks) {
		taskService.setAssignee(task.getId(), assignee);
		taskService.complete(task.getId());
		this.printTask(task);
	}
	
}
 
Example 2
Source File: TaskHistoryResourceRepositoryTest.java    From crnk-framework with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    super.setup();

    task = addTask("testTask", 12);

    TaskService taskService = processEngine.getTaskService();
    taskService.complete(task.getId());

    isolatedTask = addTask("isolatedTask", 12);
    isolatedTask.setDescription("doesNotMatchRepositoryFilter");
    taskService.saveTask(isolatedTask);

    ActivitiModule activitiModule = boot.getModuleRegistry().getModule(ActivitiModule.class).get();
    historicTaskRepository = activitiModule.getHistoricTaskRepository(HistoricApproveTask.class);
    processInstanceRepository = activitiModule.getProcessInstanceRepository(ScheduleApprovalProcessInstance.class);
}
 
Example 3
Source File: ComplaintUserInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 6 votes vote down vote up
public boolean completeTask(@RequestBody ComplaintDto complaintDto) {
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.createTaskQuery().taskId(complaintDto.getTaskId()).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    Authentication.setAuthenticatedUserId(complaintDto.getCurrentUserId());
    taskService.addComment(complaintDto.getTaskId(), processInstanceId, complaintDto.getAuditMessage());
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("auditCode", complaintDto.getAuditCode());
    variables.put("currentUserId", complaintDto.getCurrentUserId());
    variables.put("flag", "1200".equals(complaintDto.getAuditCode()) ? "false" : "true");
    variables.put("startUserId", complaintDto.getStartUserId());
    //taskService.setAssignee(complaintDto.getTaskId(),complaintDto.getCurrentUserId());
    //taskService.addCandidateUser(complaintDto.getTaskId(), complaintDto.getCurrentUserId());
    //taskService.claim(complaintDto.getTaskId(), complaintDto.getCurrentUserId());
    taskService.complete(complaintDto.getTaskId(), variables);

    ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    if (pi == null) {
        return true;
    }
    return false;
}
 
Example 4
Source File: PurchaseApplyUserInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 6 votes vote down vote up
public boolean completeTask(@RequestBody PurchaseApplyDto purchaseApplyDto) {
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.createTaskQuery().taskId(purchaseApplyDto.getTaskId()).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    Authentication.setAuthenticatedUserId(purchaseApplyDto.getCurrentUserId());
    taskService.addComment(purchaseApplyDto.getTaskId(), processInstanceId, purchaseApplyDto.getAuditMessage());
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("auditCode", purchaseApplyDto.getAuditCode());
    variables.put("currentUserId", purchaseApplyDto.getCurrentUserId());
    variables.put("nextAuditStaffId",purchaseApplyDto.getStaffId());
    //taskService.setAssignee(complaintDto.getTaskId(),complaintDto.getCurrentUserId());
    //taskService.addCandidateUser(complaintDto.getTaskId(), complaintDto.getCurrentUserId());
    //taskService.claim(complaintDto.getTaskId(), complaintDto.getCurrentUserId());
    taskService.complete(purchaseApplyDto.getTaskId(), variables);
    //taskService.setVariable(purchaseApplyDto.getTaskId(), "purchaseApplyDto", purchaseApplyDto);

    ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    if (pi == null) {
        return true;
    }
    return false;
}
 
Example 5
Source File: App.java    From CrazyWorkflowHandoutsActiviti6 with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	// 新建流程引擎
	ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
	// 存储服务
	RepositoryService repositoryService = engine.getRepositoryService();
	// 运行时服务
	RuntimeService runtimeService = engine.getRuntimeService();
	// 任务服务
	TaskService taskService =engine.getTaskService();
	// 部署服务
	repositoryService.createDeployment().addClasspathResource("MyFirstProcess.bpmn").deploy();
	// process的id属性
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess");
	
	// 普通员工完成请假的任务
	Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("当前流程节点:" + task.getName());
	taskService.complete(task.getId());
	
	// 经理审批任务
	task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("当前流程节点:" + task.getName());
	taskService.complete(task.getId());
	
	// 流程结束
	task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("流程结束:" + task);
	// 关闭流程引擎
	engine.close();
}
 
Example 6
Source File: AbstractProcessEngineTest.java    From openwebflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 测试后加签
 */
@Test
public void testInsertTasksAfter() throws Exception
{
	ProcessInstance instance = _processEngine.getRuntimeService().startProcessInstanceByKey("test2");
	TaskService taskService = _processEngine.getTaskService();
	TaskFlowControlService tfcs = _taskFlowControlServiceFactory.create(instance.getId());
	//到了step2
	Assert.assertEquals("step2", taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	//在前面加两个节点
	Authentication.setAuthenticatedUserId("kermit");
	ActivityImpl[] as = tfcs.insertTasksAfter("step2", "bluejoe", "alex");
	//应该执行到了第一个节点
	Assert.assertEquals(as[0].getId(), taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	Assert.assertEquals("kermit", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals(as[1].getId(), taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	Assert.assertEquals("bluejoe", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals(as[2].getId(), taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	Assert.assertEquals("alex", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals("step3", taskService.createTaskQuery().singleResult().getTaskDefinitionKey());

	//确认历史轨迹里已保存
	//step1,step2,step2,step2-1,step2-2,step3
	List<HistoricActivityInstance> activities = _processEngine.getHistoryService()
			.createHistoricActivityInstanceQuery().processInstanceId(instance.getId()).list();
	Assert.assertEquals(6, activities.size());

	//删掉流程
	_processEngine.getRuntimeService().deleteProcessInstance(instance.getId(), "test");
}
 
Example 7
Source File: ProcessExecutionIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenProcessInstance_whenCompleteTask_thenProcessExecutionContinues() {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    repositoryService.createDeployment()
      .addClasspathResource("org/activiti/test/vacationRequest.bpmn20.xml")
      .deploy();

    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("employeeName", "Kermit");
    variables.put("numberOfDays", new Integer(4));
    variables.put("vacationMotivation", "I'm really tired!");

    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService
      .startProcessInstanceByKey("vacationRequest", variables);

    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();

    Task task = tasks.get(0);

    Map<String, Object> taskVariables = new HashMap<String, Object>();
    taskVariables.put("vacationApproved", "false");
    taskVariables.put("comments", "We have a tight deadline!");
    taskService.complete(task.getId(), taskVariables);

    Task currentTask = taskService.createTaskQuery().taskName("Modify vacation request").singleResult();
    assertNotNull(currentTask);
}
 
Example 8
Source File: ProcessInstanceHistoryRepositoryTest.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
private ProcessInstance addCompletedProcessInstance() {
    ScheduleApprovalValues newValues = new ScheduleApprovalValues();
    newValues.setName("newName");

    ScheduleApprovalProcessInstance resource = new ScheduleApprovalProcessInstance();
    resource.setResourceId("12");
    resource.setResourceType("schedules");
    resource.setNewValues(newValues);

    Map<String, Object> processVariables = resourceMapper.mapToVariables(resource);
    runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("scheduleChange",
            "testBusinessKey", processVariables);
    runtimeService.setProcessInstanceName(processInstance.getId(), "testName");


    processInstance = runtimeService.createProcessInstanceQuery()
            .processInstanceId(processInstance.getId())
            .includeProcessVariables()
            .singleResult();

    // complete process
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.createTaskQuery().list().get(0);
    Assert.assertEquals(task.getProcessInstanceId(), processInstance.getId());
    Map<String, Object> variables = new HashMap<>();
    variables.put("approved", false);
    taskService.complete(task.getId(), variables);
    return processInstance;
}
 
Example 9
Source File: ResourceEntryStoreInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/**
 * 审核 当前任务
 *
 * @param resourceOrderDto 资源订单
 * @return
 */
public boolean complete(@RequestBody ResourceOrderDto resourceOrderDto) {
    TaskService taskService = processEngine.getTaskService();

    taskService.complete(resourceOrderDto.getTaskId());
    return true;
}
 
Example 10
Source File: ResourceEntryStoreInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
public boolean refuteCompleteTask(@RequestBody ResourceOrderDto resourceOrderDto) {
    TaskService taskService = processEngine.getTaskService();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("auditCode", resourceOrderDto.getAuditCode());
    taskService.complete(resourceOrderDto.getTaskId(), variables);
    return true;
}
 
Example 11
Source File: ResourceEntryStoreInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
public boolean agreeCompleteTask(@RequestBody ResourceOrderDto resourceOrderDto) {
    TaskService taskService = processEngine.getTaskService();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("auditCode", resourceOrderDto.getAuditCode());
    taskService.complete(resourceOrderDto.getTaskId(), variables);
    return true;
}
 
Example 12
Source File: ActivitiRuleJunit4Test.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void ruleUsageExample() {
  RuntimeService runtimeService = activitiRule.getRuntimeService();
  runtimeService.startProcessInstanceByKey("ruleUsage");
  
  TaskService taskService = activitiRule.getTaskService();
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("My Task", task.getName());
  
  taskService.complete(task.getId());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
 
Example 13
Source File: ReplayRunTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessInstanceStartEvents() throws Exception {
  ProcessEngineImpl processEngine = initProcessEngine();

  TaskService taskService = processEngine.getTaskService();
  RuntimeService runtimeService = processEngine.getRuntimeService();

  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put(TEST_VARIABLE, TEST_VALUE);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(USERTASK_PROCESS, BUSINESS_KEY, variables);

  Task task = taskService.createTaskQuery().taskDefinitionKey("userTask").singleResult();
  TimeUnit.MILLISECONDS.sleep(50);
  taskService.complete(task.getId());

  final SimulationDebugger simRun = new ReplaySimulationRun(processEngine, getReplayHandlers(processInstance.getId()));

  simRun.init(new NoExecutionVariableScope());

  // original process is finished - there should not be any running process instance/task
  assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
  assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

  simRun.step();

  // replay process was started
  assertEquals(1, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
  // there should be one task
  assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

  simRun.step();

  // userTask was completed - replay process was finished
  assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
  assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

  simRun.close();
  processEngine.close();
  ProcessEngines.destroy();
}
 
Example 14
Source File: ActivitiRuleJunit4Test.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void ruleUsageExample() {
  RuntimeService runtimeService = activitiRule.getRuntimeService();
  runtimeService.startProcessInstanceByKey("ruleUsage");

  TaskService taskService = activitiRule.getTaskService();
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("My Task", task.getName());

  taskService.complete(task.getId());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
 
Example 15
Source File: Application.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Bean
CommandLineRunner startProcess(final RuntimeService runtimeService, final TaskService taskService) {
    return new CommandLineRunner() {
        @Override
        public void run(String... strings) throws Exception {
            for (int i = 0; i < 10; i++)
                runtimeService.startProcessInstanceByKey("waiter", Collections.singletonMap("customerId", (Object) i ));

            for (int i=0; i<7; i++)
                taskService.complete(taskService.createTaskQuery().list().get(0).getId());
        }
    };
}
 
Example 16
Source File: App.java    From CrazyWorkflowHandoutsActiviti6 with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	// 新建流程引擎
	ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
	// 存储服务
	RepositoryService repositoryService = engine.getRepositoryService();
	// 运行时服务
	RuntimeService runtimeService = engine.getRuntimeService();
	// 任务服务
	TaskService taskService =engine.getTaskService();
	// 部署服务
	repositoryService.createDeployment().addClasspathResource("MyFirstProcess.bpmn").deploy();
	// process的id属性
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess");
	
	// 普通员工完成请假的任务
	Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("当前流程节点:" + task.getName());
	taskService.complete(task.getId());
	
	// 经理审批任务
	task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("当前流程节点:" + task.getName());
	taskService.complete(task.getId());
	
	// 流程结束
	task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("流程结束:" + task);
	// 关闭流程引擎
	engine.close();
}
 
Example 17
Source File: ProcessDefinitionCacheTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testStartProcessInstanceByIdAfterReboot() {

    // In case this test is run in a test suite, previous engines might
    // have been initialized and cached. First we close the
    // existing process engines to make sure that the db is clean
    // and that there are no existing process engines involved.
    ProcessEngines.destroy();

    // Creating the DB schema (without building a process engine)
    ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
    processEngineConfiguration.setProcessEngineName("reboot-test-schema");
    processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000");
    ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();

    // Create process engine and deploy test process
    ProcessEngine processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
        .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine();

    processEngine.getRepositoryService().createDeployment().addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy();

    // verify existence of process definition
    List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();

    assertEquals(1, processDefinitions.size());

    // Start a new Process instance
    ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
    String processInstanceId = processInstance.getId();
    assertNotNull(processInstance);

    // Close the process engine
    processEngine.close();
    assertNotNull(processEngine.getRuntimeService());

    // Reboot the process engine
    processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
        .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine();

    // Check if the existing process instance is still alive
    processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

    assertNotNull(processInstance);

    // Complete the task. That will end the process instance
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.createTaskQuery().list().get(0);
    taskService.complete(task.getId());

    // Check if the process instance has really ended. This means that the
    // process definition has
    // re-loaded into the process definition cache
    processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

    assertNull(processInstance);

    // Extra check to see if a new process instance can be started as well
    processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
    assertNotNull(processInstance);

    // close the process engine
    processEngine.close();

    // Cleanup schema
    schemaProcessEngine.close();
  }
 
Example 18
Source File: AbstractProcessEngineTest.java    From openwebflow with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 测试加签功能的持久化
 */
@Test
public void testInsertTasksWithPersistence() throws Exception
{
	ProcessInstance instance = _processEngine.getRuntimeService().startProcessInstanceByKey("test2");
	String processInstanceId = instance.getId();
	TaskService taskService = _processEngine.getTaskService();
	TaskFlowControlService tfcs = _taskFlowControlServiceFactory.create(instance.getId());
	//到了step2
	//在前面加两个节点
	Authentication.setAuthenticatedUserId("kermit");
	ActivityImpl[] as = tfcs.insertTasksAfter("step2", "bluejoe", "alex");
	//应该执行到了第一个节点
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals("bluejoe", taskService.createTaskQuery().singleResult().getAssignee());

	//此时模拟服务器重启
	ProcessEngine oldProcessEngine = _processEngine;
	rebuildApplicationContext();
	Assert.assertNotSame(oldProcessEngine, _processEngine);

	//重新构造以上对象
	instance = _processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId)
			.singleResult();
	taskService = _processEngine.getTaskService();
	tfcs = _taskFlowControlServiceFactory.create(instance.getId());

	//应该到了下一个节点
	Assert.assertEquals("bluejoe", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals(as[2].getId(), taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	Assert.assertEquals("alex", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals("step3", taskService.createTaskQuery().singleResult().getTaskDefinitionKey());

	//确认历史轨迹里已保存
	//step1,step2,step2,step2-1,step2-2,step3
	List<HistoricActivityInstance> activities = _processEngine.getHistoryService()
			.createHistoricActivityInstanceQuery().processInstanceId(instance.getId()).list();
	Assert.assertEquals(6, activities.size());

	//删掉流程
	_processEngine.getRuntimeService().deleteProcessInstance(instance.getId(), "test");
}
 
Example 19
Source File: AbstractProcessEngineTest.java    From openwebflow with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 测试测试节点分裂
 */
@Test
public void testSplit() throws Exception
{
	String processDefId = _processEngine.getRepositoryService().createProcessDefinitionQuery()
			.processDefinitionKey("test2").singleResult().getId();
	int size = ProcessDefinitionUtils.getProcessDefinition(_processEngine, processDefId).getActivities().size();

	//重复执行,以确定当前流程的修改不会影响其他流程
	for (int i = 0; i < 2; i++)
	{
		ProcessInstance instance = _processEngine.getRuntimeService().startProcessInstanceByKey("test2");
		TaskFlowControlService tfcs = _taskFlowControlServiceFactory.create(instance.getId());
		TaskService taskService = _processEngine.getTaskService();
		//应该有1个step2任务在执行
		Assert.assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("step2").count());

		//有1个execution
		Assert.assertEquals(1, _processEngine.getRuntimeService().createExecutionQuery().count());
		//step2分裂成2个
		ActivityImpl newActivity = tfcs.split("step2", "bluejoe", "alex");

		//只有1个step2任务
		Assert.assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("step2").count());
		Assert.assertEquals(2, _processEngine.getRuntimeService().createExecutionQuery().count());

		//依次完成2个任务
		taskService.complete(taskService.createTaskQuery().list().get(0).getId());
		taskService.complete(taskService.createTaskQuery().list().get(0).getId());

		Assert.assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("step2").count());
		//应该顺利到达step3
		Assert.assertEquals("step3", taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
		Assert.assertEquals(1, _processEngine.getRuntimeService().createExecutionQuery().count());

		Assert.assertNotNull(ProcessDefinitionUtils.getProcessDefinition(_processEngine, processDefId)
				.findActivity(newActivity.getId()));

		//确认历史轨迹里已保存
		//step1,step2,step2-split,step2-split,step3
		List<HistoricActivityInstance> activities = _processEngine.getHistoryService()
				.createHistoricActivityInstanceQuery().processInstanceId(instance.getId()).list();
		Assert.assertEquals(5, activities.size());

		//删掉流程
		_processEngine.getRuntimeService().deleteProcessInstance(instance.getId(), "test");
	}

	Assert.assertEquals(size + 2, ProcessDefinitionUtils.getProcessDefinition(_processEngine, processDefId)
			.getActivities().size());
}
 
Example 20
Source File: AbstractProcessEngineTest.java    From openwebflow with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 测试多实例节点
 */
@Test
public void testMultiInstancesLoop()
{
	Map<String, Object> variables = new HashMap<String, Object>();
	variables.put("assigneeList", CollectionUtils.arrayToList(new String[] { "kermit", "bluejoe" }));
	ProcessInstance instance = _processEngine.getRuntimeService().startProcessInstanceByKey("test2", variables);

	TaskService taskService = _processEngine.getTaskService();

	//完成step2
	taskService.complete(taskService.createTaskQuery().singleResult().getId());

	//应该有1个step3任务在执行
	Assert.assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("step3").count());
	//有1个execution
	Assert.assertEquals(1, _processEngine.getRuntimeService().createExecutionQuery().count());
	Assert.assertEquals("step3", _processEngine.getRuntimeService().createExecutionQuery().singleResult()
			.getActivityId());

	//完成step3,抵达step4
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//step4是个并行多实例节点
	//应该启动了3个step4,1个二级执行,2个三级执行,加上前面的主执行,共4个
	List<Execution> list = _processEngine.getRuntimeService().createExecutionQuery().list();
	Assert.assertEquals(4, list.size());

	ExecutionEntity execution1 = (ExecutionEntity) list.get(0);
	ExecutionEntity execution11 = (ExecutionEntity) list.get(1);
	ExecutionEntity execution111 = (ExecutionEntity) list.get(2);
	ExecutionEntity execution112 = (ExecutionEntity) list.get(3);

	Assert.assertEquals(null, execution1.getActivityId());
	Assert.assertEquals("step4", execution11.getActivityId());
	Assert.assertEquals("step4", execution111.getActivityId());
	Assert.assertEquals("step4", execution112.getActivityId());

	Assert.assertEquals(false, execution11.isActive());
	Assert.assertEquals(true, execution111.isActive());
	Assert.assertEquals(true, execution112.isActive());
	Assert.assertEquals(true, execution111.isConcurrent());
	Assert.assertEquals(true, execution112.isConcurrent());

	//父子关系
	Assert.assertEquals(execution11.getParentId(), execution1.getId());
	Assert.assertEquals(execution111.getParentId(), execution112.getParentId(), execution11.getId());

	//活动任务是2个
	List<Task> tasks = taskService.createTaskQuery().taskDefinitionKey("step4").list();
	Assert.assertEquals(2, tasks.size());
	Task task41 = tasks.get(0);
	Task task42 = tasks.get(1);
	Assert.assertEquals(execution111.getId(), task41.getExecutionId());
	Assert.assertEquals(execution112.getId(), task42.getExecutionId());

	//完成task41
	taskService.complete(task41.getId());
	//任务删除了1个
	Assert.assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("step4").count());
	Assert.assertEquals(task42.getId(), taskService.createTaskQuery().taskDefinitionKey("step4").singleResult()
			.getId());

	//execution还是4个
	Assert.assertEquals(4, _processEngine.getRuntimeService().createExecutionQuery().count());
	//完成task42
	taskService.complete(task42.getId());
	//没有step4的任何任务了
	Assert.assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("step4").count());
	Assert.assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("step5").count());

	//execution又恢复成1个
	Assert.assertEquals(1, _processEngine.getRuntimeService().createExecutionQuery().count());
	Assert.assertEquals("step5", _processEngine.getRuntimeService().createExecutionQuery().singleResult()
			.getActivityId());

	//完成step5,抵达step6
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//step6是一个串行多实例节点
	//此时应该有2个execution
	Assert.assertEquals(2, _processEngine.getRuntimeService().createExecutionQuery().count());
	Assert.assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("step6").count());
	Assert.assertEquals(taskService.createTaskQuery().taskDefinitionKey("step6").singleResult().getExecutionId(),
		_processEngine.getRuntimeService().createExecutionQuery().list().get(1).getId());
	//执行step6-1
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//还剩下1个
	Assert.assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("step6").count());
	//执行step6-2
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//到达step7
	Assert.assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("step7").count());

	//删掉流程
	_processEngine.getRuntimeService().deleteProcessInstance(instance.getId(), "test");
}