当前位置 博文首页 > 程序员石磊:快速搭建activiti spring junit测试,用起来超级方便
在学习activiti中难免会做一些小demo,来测试activiti中各种组件,下面介绍junit,spring,activiti项目搭建并附上代码。这是maven项目
这是我的项目结构:
<activiti-version>5.22.0</activiti-version>
<spring.version>4.1.5.RELEASE</spring.version>
import org.activiti.engine.*;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.spring.ProcessEngineFactoryBean;
import org.activiti.spring.impl.test.SpringActivitiTestCase;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.junit.Test;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
@RunWith( SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring-activity.xml")
public class ActivitiTest extends SpringActivitiTestCase {
private static Logger logger = LoggerFactory.getLogger(ActivitiTest.class);
@Autowired
RuntimeService runtimeService;
@Autowired
protected TaskService taskService;
@Autowired
protected HistoryService historyService;
@Autowired
protected RepositoryService repositoryService;
@Autowired
private IdentityService identityService;
@Autowired
private ProcessEngineFactoryBean processEngine;
@Autowired
private FormService formService;
@Test
public void testlist(){
List<Task> list = taskService.createTaskQuery().taskAssignee("zl").list();
for(Task task:list){
logger.info("sss"+ task.getName());
}
}
@Test
public void startProcessInstanceByKey(){
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("bb");
logger.info("sss"+ processInstance.getProcessInstanceId());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd ">
<!-- <context:component-scan
base-package="org.activiti.conf,org.activiti.rest.editor">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
<property name="username" value="TRMS"/>
<property name="password" value="TRMS"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 单例json对象 -->
<bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"/>
<!--
<bean id="idGenerator" class="com.raymon.trms.activiti.persistence.SequenceIdGeneratorFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="sequenceName" value="TRMS_ACTIVITI_ID"/>
</bean>-->
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource"/>
<property name="transactionManager" ref="transactionManager"/>
<property name="databaseSchemaUpdate" value="true"/>
<property name="jobExecutorActivate" value="false"/>
<property name="history" value="full"/>
<property name="processDefinitionCacheLimit" value="10"/>
<!-- 生成流程图的字体 -->
<property name="activityFontName" value="宋体"/>
<property name="labelFontName" value="宋体"/>
<property name="annotationFontName" value="宋体"/>
<!-- 自动部署 -->
<property name="deploymentResources">
<list>
<value>classpath*:/diagrams/*</value>
</list>
</property>
<!-- <property name="idGenerator" ref="idGenerator"/>-->
<property name="eventListeners">
<list>
<!-- <ref bean="globalEventListener"/>-->
</list>
</property>
<property name="customFormTypes">
<bean class="org.activiti.engine.impl.form.DateFormType">
<constructor-arg value="yyyy-MM-dd HH:mm:ss"/>
</bean>
</property>
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration"/>
</bean>
<bean id="