Activiti学习资料(单元测试)

74 篇文章 0 订阅
67 篇文章 0 订阅

Activiti学习资料--单元测试

单元测试均使用Spring的AbstractTransactionalJUnit4SpringContextTests作为SuperClass,并且在测试类添加:

@ContextConfiguration(locations = { "/applicationContext-test.xml" })
@RunWith(SpringJUnit4ClassRunner.class)

?

虽然Activiti也提供了测试的一些超类,但是感觉不好用,所以自己封装了一些方法。

java代码如下:

/**
 * 工作流测试基类
 *
 * @author HenryYan
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/applicationContext-test.xml" })
public abstract class BaseWorkflowTest extends AbstractTransactionalJUnit4SpringContextTests {

	@Autowired
	protected RepositoryService repositoryService;

	@Autowired
	protected ProcessEngine processEngine;

	@Autowired
	protected RuntimeService runtimeService;

	@Autowired
	protected TaskService taskService;

	@Autowired
	protected HistoryService historyService;

	protected DataSource dataSource;

	@Override
	@Autowired
	public void setDataSource(DataSource dataSource) {
		super.setDataSource(dataSource);
		this.dataSource = dataSource;
	}

	/**
	 * 部署流程定义
	 * @param filePath	流程定义文件路径,ZIP格式
	 * @throws FileNotFoundException 找不到流程定义文件的时候
	 */
	protected void deployprocessDefinition(String filePath) throws FileNotFoundException {
		logger.debug("deploy process definition, path: " + filePath);
		File file = new File(filePath);
		FileInputStream fileInputStream = new FileInputStream(file);
		String deploymentFileName = file.getName();
		String extension = FilenameUtils.getExtension(deploymentFileName);
		if (extension.equals("zip") || extension.equals("bar")) {
			ZipInputStream zip = new ZipInputStream(fileInputStream);
			repositoryService.createDeployment().addZipInputStream(zip).deploy();
		} else {
			repositoryService.createDeployment().addInputStream(deploymentFileName, fileInputStream).deploy();
		}
	}

	/**
	 * 获取流程定义ZIP文件的文件夹
	 * <p>从<b>workflow.process.definition.path</b>属性中读取</p>
	 * <p>根目录<b>deployments</b></p>
	 */
	protected String getProcessDefinitionZipDir() {
		return PropertyFileUtil.get("workflow.process.definition.path") + "/deployments/";
	}

	/**
	 * 获取流程定义XML文件的文件夹
	 * <p>从<b>workflow.process.definition.path</b>属性中读取</p>
	 * <p>根目录<b>diagrams</b></p>
	 */
	protected String getProcessDefinitionXmlDir() {
		return PropertyFileUtil.get("workflow.process.definition.path") + "/diagrams/";
	}

	/**
	 * 删除部署的流程定义文件
	 */
	@After
	public void tearDown() {
		List<Deployment> list = repositoryService.createDeploymentQuery().list();
		logger.info("total: " + list.size() + " , undeploy activit process definitioning ...");
		for (Deployment deployment : list) {
			repositoryService.deleteDeployment(deployment.getId(), true);
		}
		processEngine.close();
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值