Flood
Package Com.java1234.activiti.variable;import Java.util.date;import Java.util.hashmap;import java.util.List;import Java.util.map;import Org.activiti.engine.processengine;import Org.activiti.engine.processengines;import Org.activiti.engine.taskservice;import Org.activiti.engine.repository.deployment;import Org.activiti.engine.runtime.processinstance;import Org.activiti.engine.task.task;import Org.junit.Test;import Com.java1234.activiti.model.student;public class Variabletest {/** * Gets the default process engine instance, reads the configuration file by default Activiti.cfg.xml */private Processengine processengine=processengines.getdefaultprocessengine ();/** * 1. Deploy the process definition. */@Testpublic void Deploywidthclasspath () {Deployment deployment=processengine.getrepositoryservice ()// Deploy the related service.createdeployment ()//Create a Deployment object. Addclasspathresource ("DIAGRAMS/STUDENTLEAVEPROCESS.BPMN")// Load the resource file. Addclasspathresource ("diagrams/studentleaveprocess.png")//load resource picture. Name ("Student Leave Process")//Set name. Deploy ();/ Deployment System.out.println ("Process Deployment ID:" +deployment.getid ()); SYSTEM.OUT.PRINTLN ("Process deployment NAMe: "+deployment.getname ());/* Process deployment id:15001 Process deployment Name: Student leave Process-------------------# # Process Deployment Table SELECT * FROM Act_re_deployment ; # # Process Definition Table SELECT * from act_re_procdef;## resource File Table select * from Act_ge_bytearray; */}/** * 1.1 Query so process deployment, name query, like query */@Test public void Finddeploy () {//processengine.getrepositoryservice (). get}/** * 2. Start Process instance */@Testpublic void start () {processinstance pi=processengine.getruntimeservice ()// Run the service. Startprocessinstancebykey ("studentleaveprocess"); The Act_re_procdef key_ field in the database System.out.println ("Process instance ID:" +pi.getid ()); SYSTEM.OUT.PRINTLN ("Process definition ID:" +pi.getprocessdefinitionid ());//process definition id/* Process instance id:17501, 30001 process definition ID: studentleaveprocess:1:15004 */}/** * 3. Query Task * */@Testpublic void Findtask () {list<task> tasklist= Processengine.gettaskservice ()///Task service instance. Createtaskquery ()//Create task query. Taskassignee ("Harry")//Query Zhang San, John Doe, after Europe Harry. List (); for ( Task Task:tasklist) {//act_ru_task; The information in the field SYSTEM.OUT.PRINTLN ("Task ID:" +task.getid ()); SYSTEM.OUT.PRINTLN ("Task Name:" +task.getname ()); SYSTEM.OUT.PRINTLN ("Task Creation time:" +Task.getcreatetime ()); SYSTEM.OUT.PRINTLN ("Mission Delegate:" +task.getassignee ()); SYSTEM.OUT.PRINTLN ("Task instance ID:" +task.getprocessinstanceid ());} /* Print Results: task id:17504, 30004 task Name: Student leave application Task creation time: Thu 15:24:50 CST 2016 task delegate: Zhang San task instance id:17501,30001 */}/** * 4. Finish the task and let the Zhang San finish. Into task */@Testpublic void Completetask () {processengine.gettaskservice ()//Task server. Complete ("50002"); Use above: Task ID: (17504) System.out.println ("Task done!");} /** * Set the process variable data * 42504,47502, if you use 42504 will appear an exception! */private String taskid= "47502"; @Testpublic void Setvariablevalues () {/* # run-time parameter setting, first the data for this table will be emptied at the end of the task select * from Act_ ru_variable; */taskservice Taskservice=processengine.gettaskservice (); Task Service Instance//string taskid= ""; Taskservice.setvariable (TaskId, "Days", 2); Taskservice.setvariable (taskId, "date", new Date ()); Taskservice.setvariable (taskId, "reason", "fever"); Student student=new Student () Student.setid (1); Student.setname ("Zhang San"); Taskservice.setvariable (TaskId, "Student", Student); SYSTEM.OUT.PRINTLN ("Setup done!");} @Testpublic void Getvariablevalues () {Taskservice Taskservice=processengine.gettaskservice (); Task Service Instance//string taskid= "";/** * When a task is submitted, the next person can get these variable values according to their task ID * use 42504 to set parameters, use 47502 can also get to */integer days = (Integer) Taskservice.getvariable (TaskId, "days");D ate Date = (date) taskservice.getvariable (taskId, "date"); String reason= (String) taskservice.getvariable (taskId, "reason"); Student student= (Student) taskservice.getvariable (taskId, "Student"); System.out.println ("Days:" +days+ ""); System.out.println ("Date:" +date); System.out.println ("Reason:" +reason); System.out.println ("Student:" +student); SYSTEM.OUT.PRINTLN ("------query completed!"); *days:2date:thu Jul 17:52:45 CST 2016reason: Fever student:student [Id=1, Name= Zhang San] */}/** * This setting overwrites the data! */@Testpublic void Setvariablemap () {Taskservice taskservice=processengine.gettaskservice ();//Task service instance map<string, object> variables =new hashmap<string, object> () variables.put ("Days", 3); Variables.put ("Date", new Date ()); Variables.put ("Reason", "Fever 22"); Student student=new Student (); Student.setid (2); StuDent.setname ("Zhang 31"); Variables.put ("Student", student);/** * This setting method overwrites the task data! */taskservice.setvariables (taskId, variables); SYSTEM.OUT.PRINTLN ("Setup done!");} @Testpublic void Getvariablemap () {Taskservice taskservice=processengine.gettaskservice ();//Task service instance//string taskid= " ";/** * When a task is submitted, the next person can get the value of these variables according to their task ID * use 42504 to set parameters, use 47502 can also get to */map<string,object> variables = (map<str ING, object>) taskservice.getvariables (taskId); SYSTEM.OUT.PRINTLN (variables); SYSTEM.OUT.PRINTLN ("------query completed!");}}
Java Test 1