Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
BaseWorkflowTest
/**
* 工作流测试基类
*
* @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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.