package com.blueland.ebpm.engine.core.service;

import java.util.List;

import com.blueland.bpm.engine.core.service.ProcessInstanceService;
import com.blueland.ebpm.engine.BaseWfServiceTest;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.Execution;
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.boot.test.context.SpringBootTest;

import com.blueland.bpm.engine.core.model.ActivityInstanceModel;
import com.blueland.bpm.engine.core.model.ProcessInstanceModel;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest
@RunWith(SpringRunner.class)
public class ProcessInstanceServiceTest extends BaseWfServiceTest {
	
	@Autowired
	private ProcessInstanceService processInstanceService;
	@Test
	/**
	 * 起草流程
	 */
	public void getThroughBizAppProcess() {
		List<ProcessInstanceModel> processInstanceModels=processInstanceService.getThroughBizAppProcess("ebae6f07-0e83-11e5-99a8-68f72803f161");
		System.out.println(processInstanceModels);
	}
	
	@Test
	/**
	 * 起草流程
	 */
	public void getAllThroughBizAppProcess() {
		List<ProcessInstanceModel> processInstanceModels=processInstanceService.getAllThroughBizAppProcess("STDD_SYS");
		System.out.println(processInstanceModels);
	}
	
	
	@Test
	/**
	 * 起草流程
	 */
	public void getProcessTasksByTopId() {
		List<Task> processInstanceModels=processInstanceService.getProcessTasksByTopId("8a1cb8f9-0050-11e5-88fe-68f72803f161", "gaof0709", "");
		System.out.println(processInstanceModels);
	}
	@Test
	/**
	 * 起草流程
	 */
	public void signal() {
		Execution execution = runtimeService.createExecutionQuery()
		  .processInstanceId("e7f6fdee-1587-11e5-8d5a-68f72803f161")
		  .activityId("sid-393FB09C-32D8-4FAA-97B0-8BF779BFCFDB")
		  .singleResult();
		runtimeService.signal(execution.getId());
	}
	
	@Test
	/**
	 * 起草流程
	 */
	public void getTaskEntity() {
		ActivityInstanceModel taskEntity=processInstanceService.getTask("d69af11d-aa8a-11ec-aba6-0242ac11000a");
		ProcessInstance processInstance=processInstanceService.getRuntimeService().createProcessInstanceQuery().processInstanceId(taskEntity.getProcInstId()).singleResult();
		ProcessDefinition processDefinition=this.repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
	}
	
	@Test
	/**
	 * 起草流程
	 */
	public void getProcessFieldVariable() {
		processInstanceService.getProcessFieldVariable("4747152f-1b12-11e5-9846-68f72803f161");
	}
	
	
	@Test
	/**
	 * 起草流程
	 */
	public void getBusinessDataObject() {
		processInstanceService.getBusinessDataObject("deafce2f-10d5-11e5-9f50-68f72803f161");
	}
	
	@Test
	/**
	 * 起草流程
	 */
	public void getProcessFieldVariableByFinished() {
		processInstanceService.getProcessFieldVariableByFinished("0bd06a5d-1590-11e5-8a3c-68f72803f161");
	}
	
	@Test
	/**
	 * 起草流程
	 */
	public void findBackAvtivity() {
		System.out.println(processInstanceService.findBackAvtivity("00ec2015-a456-11ec-9d9e-e2d464bea7a3"));
	}
	
}
