/*
 * 该类主要负责系统主要业务逻辑的实现,如多表处理的事务操作、权限控制等
 * 该类根据具体的业务逻辑来调用该实体对应的Dao或者多个Dao来实现数据库操作
 * 实际的数据库操作在对应的Dao或其他Dao中实现
 */

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

import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;

import com.blueland.ebpm.engine.BaseManagerTestCase;
import com.blueland.bpm.engine.core.model.ActivityInstanceModel;
import com.blueland.bpm.engine.core.model.ProcessPageContext;
import com.blueland.bpm.engine.core.service.ProcessConfigService;
import com.blueland.bpm.engine.core.service.ProcessInstanceService;
import com.blueland.bpm.engine.util.WorkFlowContants;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @author lw
 * @version 1.0
 * @since
 */

@SpringBootTest
@RunWith(SpringRunner.class)
public class AllActivityOperatePowerTest extends BaseManagerTestCase {
	@Autowired
	ProcessConfigService processConfigService;
	@Autowired
	ProcessInstanceService processInstanceService;

	 @Test
	public void testCallPrevButBut() {// 退回上一步
		Map<String, Object> pageDetailVaribale = new HashMap<String, Object>();
		String curUserId = "gaof0709";
		String curUserOrgId = "204300015350";
		String curProcInstId = "fcd3f132-04e8-11e5-b040-68f72803f161";
		String curActInstId = "fcdb443c-04e8-11e5-b040-68f72803f161";
		ProcessPageContext processPageContext = new ProcessPageContext(
				WorkFlowContants.TODO_OPEN_PAGE_TYPE,
				WorkFlowContants.ACTION_TYPE_EXECUTE_ACTIVITY, "", curUserId,
				curUserOrgId);
		HistoricProcessInstanceEntity processInstance = (HistoricProcessInstanceEntity) processInstanceService
				.getHistoryService().createHistoricProcessInstanceQuery()
				.processInstanceId(curProcInstId).singleResult();
		ActivityInstanceModel task = processInstanceService
				.getTask(curActInstId);
		pageDetailVaribale.put("processInstance", processInstance);
		pageDetailVaribale.put("task", task);
		pageDetailVaribale.put("processPageContext", processPageContext);
		//判断按钮是否有权限
		boolean result=processConfigService.hasActivityButOperatePower("BACK_PREV_ACT_BTN",
				pageDetailVaribale);
		//新建暂时时的起草环节无法退回上一步
		System.out.println(result);
	}

	@Test
	public void testCallStartBut() {// 退回起草
		Map<String, Object> pageDetailVaribale = new HashMap<String, Object>();
		String curProcInstId = "799f18da-0825-11e5-8f2b-68f72803f161";
		String curActInstId = "79f37a88-0825-11e5-8f2b-68f72803f161";
		HistoricProcessInstanceEntity processInstance = (HistoricProcessInstanceEntity) processInstanceService
				.getHistoryService().createHistoricProcessInstanceQuery()
				.processInstanceId(curProcInstId).singleResult();
		ActivityInstanceModel task = processInstanceService
				.getTask(curActInstId);
		pageDetailVaribale.put("processInstance", processInstance);
		pageDetailVaribale.put("task", task);
		//判断按钮是否有权限
		boolean result=processConfigService.hasActivityButOperatePower("BACK_PREV_ACT_BTN",
				pageDetailVaribale);
		System.out.println(result);
	}

	@Test
	public void testCancelBut() {// 作废
		Map<String, Object> pageDetailVaribale = new HashMap<String, Object>();
		String curProcInstId = "799f18da-0825-11e5-8f2b-68f72803f161";
		String curActInstId = "79f37a88-0825-11e5-8f2b-68f72803f161";
		HistoricProcessInstanceEntity processInstance = (HistoricProcessInstanceEntity) processInstanceService
				.getHistoryService().createHistoricProcessInstanceQuery()
				.processInstanceId(curProcInstId).singleResult();
		ActivityInstanceModel task = processInstanceService
				.getTask(curActInstId);
		pageDetailVaribale.put("processInstance", processInstance);
		pageDetailVaribale.put("task", task);
		//判断按钮是否有权限
		boolean result=processConfigService.hasActivityButOperatePower("BACK_PREV_ACT_BTN",
				pageDetailVaribale);
		System.out.println(result);
	}
}
