Java Test 1, java Test
Fa dashui
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. ju Nit. test; import com. java1234.activiti. model. student; public class VariableTest {/*** gets the default Process Engine instance and reads the configuration file activiti by default. cfg. xml */private ProcessEngine processEngine = ProcessEngines. getdefaprocesprocessengine ();/*** 1. deployment process definition. * // @ Testpublic void deployWidthClassPath () {Deployment deployment = processEngine. getRepositoryService () // deploy related services. createDeployment () // create a deployment object. addClasspathResource ("diagrams/StudentLeav EProcess. bpmn ") // load the resource file. addClasspathResource ("diagrams/StudentLeaveProcess.png") // load the resource image. name ("Student leave Process") // set the name. deploy (); // deploy 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; # select * from act_ge_bytearray ;*/}/*** 1.1 process deployment and 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 key _ Field System of act_re_procdef in the database. out. println ("process instance ID:" + pi. getId (); System. out. println ("process definition ID:" + pi. getProcessDefinitionId (); // process definition ID/* process instance ID: 17 501,300 01 process definition ID: studentLeaveProcess: 1: 15004 */}/*** 3. query a Task **/@ Testpublic void findTask () {List <Task> taskList = processEngine. getTaskService () // Task Service instance. createTaskQuery () // create a task query. taskAssignee ("Wang Wu") // query Zhang San, Li Si, and later European Wang Wu. list (); for (Task task: taskList) {// act_ru_task; 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. getCreate Time (); System. out. println ("task delegate:" + task. getAssignee (); System. out. println ("task instance ID:" + task. getProcessInstanceId ();}/* print result: task Id: 17504,300 04 Task Name: Student leave application task Creation Time: Thu Jul 28 15:24:50 CST 2016 task delegate: task instance ID: 17501,30001 */}/*** 4. complete the task. let Michael complete the task */@ Testpublic void completeTask () {processEngine. getTaskService () // Task Server. complete ("50002"); // use the preceding: task Id: (17504) System. out. println ("task completed! ");}/*** Sets the process variable data * 42504, 47502. If you use again, an exception will occur! */Private String taskId = "47502"; @ Testpublic void setVariableValues () {/* # runtime parameter settings, first, the data in this table will be cleared 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 ("Settings completed! ") ;}@ 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 * based on his task id. Set the parameter using 42504, and use 47502 to get */Integer days = (Integer) taskService. getVariable (taskId, "days"); Date 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 complete! ");/* Days: 2 date: Thu Jul 28 17:52:45 CST 2016 reason: fever student: Student [id = 1, name = James] */}/*** this setting overwrites data! * // @ Testpublic void setVariableMap () {TaskService taskService = processEngine. getTaskService (); // Map of the task service instance <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 San 1"); variables. put ("student", student);/*** this setting method overwrites the task data! */TaskService. setVariables (taskId, variables); System. out. println ("the setting is complete! ") ;}@ Testpublic void getVariableMap () {TaskService taskService = processEngine. getTaskService (); // Task Service instance // String taskId = "";/*** when a task is submitted, the next person can obtain these variable values * based on his task id and set parameters with 42504, or get */Map <String, Object> variables = (Map <String, object>) taskService. getVariables (taskId); System. out. println (variables); System. out. println ("------ Query complete! ");}}