Java_Activiti5_菜鳥也來學Activiti5工作流_之JUnit單元測試(四)


 1 /**ActivitiSpringJuinitTest.java
 2  * author : 馮孟活 ^_^
 3  * dates  : 2015年9月2日 下午2:16:54
 4  * class   : activiti 之 Junit 測試
 5  */
 6 // 指定運行環境要用到spring的測試包(spring-test.jar)
 7 @RunWith(SpringJUnit4ClassRunner.class)
 8 // 注入一些配置信息
 9 @ContextConfiguration(locations="classpath:applicationConfig.xml") 
10 public class ActivitiSpringJuinitTest {
11     
12     @Autowired // 注入運行服務類
13     private RuntimeService runtimeService;
14     
15     @Autowired // 注入任務服務類
16     private TaskService taskService;
17     
18     @Autowired
19     @Rule // 注入一些規則
20     private ActivitiRule activitiSpringRule;
21     
22     @Test 
23     @Deployment // 部署
24     public void activitiTest(){
25         // 根據key來啟動流程實例
26         runtimeService.startProcessInstanceByKey("myProcess");
27         // 獲取單個任務
28         Task task = taskService.createTaskQuery().singleResult();
29         // 斷言任務名稱就是 "My Task"
30         Assert.assertEquals("My Task",task.getName());
31         // 完成任務
32         taskService.complete(task.getName());
33         /**
34          * 總結:簡單的單元測試到此為止!
35          *             注意:葯正確使用 注解類
36          *                     遇到的問題:
37          *                     Caused by: java.lang.ClassNotFoundException: org.junit.Assume$AssumptionViolatedException
38          *                     這一般是spring-text包與junit包沖突引起,把junit改低版本就沒有問題了^_^
39          */
40     }
41 }
42 
43 
44 <!-- applicationConfig.xml -->
45 <?xml version="1.0" encoding="UTF-8"?>
46 <beans xmlns="http://www.springframework.org/schema/beans"
47     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
48     xmlns:context="http://www.springframework.org/schema/context"
49     xmlns:tx="http://www.springframework.org/schema/tx"
50     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
51         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
52         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
53     
54     <!-- 配置數據源 -->
55     <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
56         <property name="driverClass" value="com.mysql.jdbc.Driver"/>
57         <property name="url" value="jdbc:mysql://localhost:3306/db_activiti?useUnicode=true&amp;characterEncoding=utf-8"/>
58         <property name="username" value="root"/>
59         <property name="password" value="root"/>
60     </bean>
61 
62     <!-- 配置數據源事務管理器 -->
63     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
64         <property name="dataSource" ref="dataSource"/> <!-- 引用上面的數據源 -->
65     </bean>
66     
67     <!-- 配置流程引擎配置類 注意:這是用 org.activiti.spring.SpringProcessEngineConfiguration 這個類-->
68     <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
69         <property name="dataSource" ref="dataSource"/>
70         <property name="transactionManager" ref="transactionManager" />
71         <property name="databaseSchemaUpdate" value="true" />
72         <property name="jobExecutorActivate" value="false" />
73         <property name="createDiagramOnDeploy" value="false" /> <!-- 是否生成流程定義圖片 -->
74     </bean>
75     
76     <!-- 配置流程引擎工廠 -->
77     <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
78         <property name="processEngineConfiguration" ref="processEngineConfiguration" />
79     </bean>
80     
81     <!-- 配置注入一些服務 -->
82     <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/>
83     <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>
84     <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
85     <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
86     <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
87     
88     <!-- 配置activiti的規則 -->
89     <bean id="activitiRule" class="org.activiti.engine.test.ActivitiRule">
90         <property name="processEngine" ref="processEngine" />
91     </bean>
92     
93 </beans>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM