1 package org.example; 2 3 import org.jbpm.db.JbpmSession; 4 import org.jbpm.db.GraphSession; 5 import org.jbpm.db.JbpmSessionFactory; 6 import org.jbpm.graph.def.ProcessDefinition; 7 import org.jbpm.graph.exe.ProcessInstance; 8 import org.jbpm.graph.exe.Token; 9 10 import junit.framework.TestCase; 11 12 16 public class AsyncProcessTest extends TestCase { 17 18 private static JbpmSessionFactory jbpmSessionFactory = 19 JbpmSessionFactory.buildJbpmSessionFactory(); 20 21 public AsyncProcessTest(String name) { 22 super(name); 23 } 24 25 public void testAsyncScenario() throws Exception { 26 JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession(); 28 jbpmSession.beginTransaction(); 30 31 GraphSession graphSession = jbpmSession.getGraphSession(); 34 ProcessDefinition processDefinition = 35 graphSession.findLatestProcessDefinition("asyncProcess"); 36 37 ProcessInstance processInstance = new ProcessInstance(processDefinition); 38 graphSession.saveProcessInstance(processInstance); 40 41 jbpmSession.commitTransaction(); 43 44 jbpmSession.beginTransaction(); 46 47 graphSession.lockProcessInstance(processInstance); 49 Token token = processInstance.getRootToken(); 50 assertEquals("start", token.getNode().getName()); 51 52 token.signal(); 54 assertEquals("A", token.getNode().getName()); 56 token.signal(); 57 58 assertEquals("fork", token.getNode().getName()); 61 Token b = token.getChild("branch-b"); 62 Token c = token.getChild("branch-c"); 63 Token d = token.getChild("branch-d"); 64 assertEquals("B", b.getNode().getName()); 65 assertEquals("C", c.getNode().getName()); 66 assertEquals("D", d.getNode().getName()); 67 68 graphSession.saveProcessInstance(processInstance); 72 73 jbpmSession.commitTransaction(); 75 jbpmSession.close(); 77 78 Thread.currentThread().sleep(10000); 79 80 assertInstanceCompleted(processInstance.getId()); 82 } 83 84 private void assertInstanceCompleted(long processInstanceId) { 85 JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession(); 87 jbpmSession.beginTransaction(); 89 GraphSession graphSession = jbpmSession.getGraphSession(); 90 91 ProcessInstance pi = graphSession.loadProcessInstance( processInstanceId ); 93 graphSession.lockProcessInstance(pi); 94 assertNotNull( pi.getEnd() ); 95 96 jbpmSession.commitTransaction(); 97 jbpmSession.close(); 99 } 100 } 101 | Popular Tags |