1 /**Activitispringjuinittest.java2 * Author: Feng Mengwao ^_^3 * dates:2015 Year September 2 afternoon 2:16:544 * Class:activiti's Junit test5 */6 //Specify the run environment to use for spring's test package (Spring-test.jar)7@RunWith (Springjunit4classrunner.class)8 //inject some configuration information9@ContextConfiguration (locations= "Classpath:applicationConfig.xml") Ten Public classActivitispringjuinittest { One A@Autowired//Injection Run service class - PrivateRuntimeservice Runtimeservice; - the@Autowired//Inject task service class - PrivateTaskservice Taskservice; - - @Autowired +@Rule//inject some rules - Privateactivitirule Activitispringrule; + A @Test at@Deployment//Deployment - Public voidactivititest () { - //To start a process instance based on key -Runtimeservice.startprocessinstancebykey ("Myprocess"); - //get a single task -Task task =taskservice.createtaskquery (). Singleresult (); in //assert that the task name is "My task" -Assert.assertequals ("My Task", Task.getname ()); to //Complete the Task + Taskservice.complete (Task.getname ()); - /** the * Summary: The simple unit test ends here! * * Note: The correct use of the drug annotation class $ * Problems encountered:Panax Notoginseng * caused by:java.lang.classnotfoundexception:org.junit.assume$assumptionviolatedexcept Ion - * This is usually caused by the Spring-text package conflict with the JUnit package, and it's no problem to change JUnit to a lower version ^_^ the */ + } A } the + -<!--Applicationconfig.xml-- $<?xml version= "1.0" encoding= "UTF-8"?> $<beans xmlns= "Http://www.springframework.org/schema/beans" -Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" -xmlns:context= "Http://www.springframework.org/schema/context" thexmlns:tx= "Http://www.springframework.org/schema/tx" -xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans.xsdWuyihttp//Www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.1.xsd thehttp//Www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> - Wu<!--configuring data sources- -<bean id= "DataSource"class= "Org.springframework.jdbc.datasource.SimpleDriverDataSource" > About<property name= "Driverclass" value= "Com.mysql.jdbc.Driver"/> $<property name= "url" value= "jdbc:mysql://localhost:3306/db_activiti?useunicode=true&characterencoding =utf-8 "/> -<property name= "username" value= "root"/> -<property name= "Password" value= "root"/> -</bean> A +<!--Configuring the data source transaction manager- the<bean id= "TransactionManager"class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" > -<property name= "DataSource" ref= "DataSource"/> <!--reference the data source above-- $</bean> the the<!--Configuring the process engine configuration class Note: This is the class with Org.activiti.spring.SpringProcessEngineConfiguration-- the<bean id= "Processengineconfiguration"class= "Org.activiti.spring.SpringProcessEngineConfiguration" > the<property name= "DataSource" ref= "DataSource"/> -<property name= "TransactionManager" ref= "TransactionManager"/> in<property name= "Databaseschemaupdate" value= "true"/> the<property name= "Jobexecutoractivate" value= "false"/> the<property name= "Creatediagramondeploy" value= "false"/> <!--whether to generate a process definition picture-- About</bean> the the<!--configuration Process engine factory-- the<bean id= "Processengine"class= "Org.activiti.spring.ProcessEngineFactoryBean" > +<property name= "processengineconfiguration" ref= "Processengineconfiguration"/> -</bean> the Bayi<!--configuration Inject some services-- the<bean id= "Repositoryservice" factory-bean= "Processengine" factory-method= "Getrepositoryservice"/> the<bean id= "Runtimeservice" factory-bean= "Processengine" factory-method= "Getruntimeservice"/> -<bean id= "Taskservice" factory-bean= "Processengine" factory-method= "Gettaskservice"/> -<bean id= "Historyservice" factory-bean= "Processengine" factory-method= "Gethistoryservice"/> the<bean id= "Managementservice" factory-bean= "Processengine" factory-method= "Getmanagementservice"/> the the<!--Configure Activiti rules-- the<bean id= "Activitirule"class= "Org.activiti.engine.test.ActivitiRule" > -<property name= "Processengine" ref= "Processengine"/> the</bean> the the</beans>
Java_activiti5_ rookie also come to learn Activiti5 workflow _ JUnit Unit Test (iv)