本文是使用 Activiti5.8 junit4
关于如是使用activiti的 Demo setup 数据库配置 集成Activiti流程设计器 Activiti的Api 等 网上可以找到很多相关资料 本文不再复述 了
首先当然是要新建一个Activiti项目了!
关键代码:
@Rule
public ActivitiRule activitiRule = new ActivitiRule();
这是使用Junit4必须使用的
protected RepositoryService repositoryService;
protected String filePath="";
// Will be assigned during upload
protected String fileName ="D:/web/activiti/activiti-5.8/workspace/hello-activiti-001/src/test/resources/hello/activiti/activiti.zip";
// Will be assigned after deployment
protected boolean validFile = false;
protected Deployment deployment;
protected RepositoryService getRepositoryService() {
repositoryService = activitiRule.getRepositoryService();
return repositoryService;
}
//管理流程 定义
// 1.1 添加 (部署)
@org.activiti.engine.test.Deployment // 记得这个哦
@Test
public void deployment(){
fileName="activititest.zip";
getRepositoryService();
deployUploadedFile();
}
protected void deployUploadedFile() {
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().name(fileName);
try {
if (fileName.endsWith(".bpmn20.xml")) {
deployment = deploymentBuilder
.addInputStream(fileName, new FileInputStream(filePath))
.deploy();
} else if (fileName.endsWith(".bar") || fileName.endsWith(".zip")) {
deployment = deploymentBuilder
.addZipInputStream(new ZipInputStream(new FileInputStream(filePath)))
.deploy();
} else {//other
}
} catch (ActivitiException e) {
System.out.println(e);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}