1 package org.jbpm.tutorial.db; 2 3 import java.util.List ; 4 5 import junit.framework.TestCase; 6 7 import org.jbpm.db.GraphSession; 8 import org.jbpm.db.JbpmSession; 9 import org.jbpm.db.JbpmSessionFactory; 10 import org.jbpm.graph.def.ProcessDefinition; 11 import org.jbpm.graph.exe.ProcessInstance; 12 import org.jbpm.graph.exe.Token; 13 14 public class HelloWorldDbTest extends TestCase { 15 16 static JbpmSessionFactory jbpmSessionFactory = 20 JbpmSessionFactory.buildJbpmSessionFactory(); 21 22 static { 23 jbpmSessionFactory.getJbpmSchema().createSchema(); 28 } 29 30 public void testSimplePersistence() { 31 37 deployProcessDefinition(); 41 42 processInstanceIsCreatedWhenUserSubmitsWebappForm(); 45 46 theProcessInstanceContinuesWhenAnAsyncMessageIsReceived(); 49 } 50 51 public void deployProcessDefinition() { 52 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 57 "<process-definition name='hello world'>" + 58 " <start-state name='start'>" + 59 " <transition to='s' />" + 60 " </start-state>" + 61 " <state name='s'>" + 62 " <transition to='end' />" + 63 " </state>" + 64 " <end-state name='end' />" + 65 "</process-definition>" 66 ); 67 68 JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession(); 70 jbpmSession.beginTransaction(); 72 73 jbpmSession 75 .getGraphSession() 76 .saveProcessDefinition(processDefinition); 77 78 jbpmSession.commitTransaction(); 80 jbpmSession.close(); 82 } 83 84 public void processInstanceIsCreatedWhenUserSubmitsWebappForm() { 85 88 JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession(); 90 jbpmSession.beginTransaction(); 92 93 ProcessDefinition processDefinition = 96 jbpmSession 97 .getGraphSession() 98 .findLatestProcessDefinition("hello world"); 99 100 ProcessInstance processInstance = 104 new ProcessInstance(processDefinition); 105 106 Token token = processInstance.getRootToken(); 107 assertEquals("start", token.getNode().getName()); 108 token.signal(); 110 assertEquals("s", token.getNode().getName()); 112 113 jbpmSession 117 .getGraphSession() 118 .saveProcessInstance(processInstance); 119 123 jbpmSession.commitTransaction(); 125 jbpmSession.close(); 127 } 128 129 public void theProcessInstanceContinuesWhenAnAsyncMessageIsReceived() { 130 132 JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession(); 134 jbpmSession.beginTransaction(); 138 GraphSession graphSession = jbpmSession.getGraphSession(); 139 140 ProcessDefinition processDefinition = 146 graphSession.findLatestProcessDefinition("hello world"); 147 148 List processInstances = 150 graphSession.findProcessInstances(processDefinition.getId()); 151 152 ProcessInstance processInstance = 157 (ProcessInstance) processInstances.get(0); 158 159 processInstance.signal(); 162 163 assertTrue(processInstance.hasEnded()); 166 167 graphSession.saveProcessInstance(processInstance); 169 170 jbpmSession.commitTransaction(); 172 jbpmSession.close(); 174 } 175 } 176 | Popular Tags |