[jboss-user] [JBoss jBPM] - Re: process versioning + swimlane with pooledActors
yoyoyoyo
do-not-reply at jboss.com
Thu Apr 12 19:17:27 EDT 2007
| import java.util.Iterator;
| import java.util.List;
|
| import junit.framework.Test;
| import junit.framework.TestCase;
| import junit.framework.TestSuite;
|
| import org.jbpm.JbpmConfiguration;
| import org.jbpm.JbpmContext;
| import org.jbpm.graph.def.ProcessDefinition;
| import org.jbpm.graph.exe.ProcessInstance;
| import org.jbpm.taskmgmt.def.Swimlane;
| import org.jbpm.taskmgmt.exe.TaskInstance;
|
| public class JbpmTest extends TestCase {
|
| JbpmConfiguration jbpmCfg;
| JbpmContext jbpmContext;
|
| public JbpmDelegatorTest(String name) {
| super(name);
| }
|
| protected void setUp() {
| this.jbpmCfg = JbpmConfiguration.getInstance();
| this.jbpmContext = jbpmCfg.createJbpmContext();
| }
|
| protected void tearDown() {
| jbpmContext.close();
| }
|
| public void testDeployProcessXml() {
| String xmlResource = "returngoods.swimlane-pooled-actors/processdefinition.xml";
| ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource(xmlResource);
| jbpmContext.deployProcessDefinition(processDefinition);
| }
|
| public void testCreateStartTaskInstance() {
| ProcessDefinition processDefinition = jbpmContext.getGraphSession().findLatestProcessDefinition("returngoods.swimlane-pooled-actors");
| // long processDefinitionId = processDefinition.getId();
|
| ProcessInstance processInstance = processDefinition.createProcessInstance();
| TaskInstance startTaskInstance = processInstance.getTaskMgmtInstance().createStartTaskInstance();
| startTaskInstance.end();
| jbpmContext.save(processInstance);
|
| List pooledTaskInstances = jbpmContext.getTaskMgmtSession().findPooledTaskInstances("yoyo");
| assertTrue(pooledTaskInstances.size() > 0); //the 'Receive Item' task should be there according to the process definition
| TaskInstance taskInstanceOld = (TaskInstance) pooledTaskInstances.get(0);
| assertEquals("Receive Item", taskInstanceOld.getName());
| int oldVersion = taskInstanceOld.getTaskMgmtInstance().getTaskMgmtDefinition().getProcessDefinition().getVersion();
| System.out.println("oldVersion " + oldVersion);
|
| }
|
| public void testChangeProcessDefinition() {
| ProcessDefinition processDefinition = jbpmContext.getGraphSession().findLatestProcessDefinition("returngoods.swimlane-pooled-actors");
|
| //removing yoyo from all swimlanes
| Swimlane swimlane = processDefinition.getTaskMgmtDefinition().getSwimlane("Shipping");
| swimlane.setActorIdExpression(null);
| swimlane.setPooledActorsExpression("grover");
|
| swimlane = processDefinition.getTaskMgmtDefinition().getSwimlane("Sales");
| swimlane.setActorIdExpression(null);
| swimlane.setPooledActorsExpression("ernie");
|
| swimlane = processDefinition.getTaskMgmtDefinition().getSwimlane("Accounting");
| swimlane.setActorIdExpression(null);
| swimlane.setPooledActorsExpression("bert");
|
| jbpmContext.deployProcessDefinition(processDefinition);
| }
|
| public void testCompleteTask() {
| List pooledTaskInstances = jbpmContext.getTaskMgmtSession().findPooledTaskInstances("yoyo");
| assertTrue(pooledTaskInstances.size() > 0); //the 'Receive Item' task should be there according to the process definition
| TaskInstance taskInstanceNew = (TaskInstance) pooledTaskInstances.get(0);
| assertEquals("Receive Item", taskInstanceNew.getName());
| int newVersion = taskInstanceNew.getTaskMgmtInstance().getTaskMgmtDefinition().getProcessDefinition().getVersion();
|
| //The taskInstance is still there, but with new process version!
| System.out.println("newVersion "+ newVersion);
|
| taskInstanceNew.end();
| }
|
| public void testPooledTaskInstances() {
| List pooledTaskInstances = jbpmContext.getTaskMgmtSession().findPooledTaskInstances("yoyo");
|
| // the suite failed here!
| assertTrue(pooledTaskInstances.size() > 0);
|
| for (Iterator iter = pooledTaskInstances.iterator(); iter.hasNext();) {
| TaskInstance taskInstance = (TaskInstance) iter.next();
| System.out.println("taskInstanceName " + taskInstance.getName());
| System.out.println("version " + taskInstance.getTaskMgmtInstance().getTaskMgmtDefinition().getProcessDefinition().getVersion());
| }
| }
|
| //clean up all pooledTaskInstances for yoyo to make the result clear
| public void testCleanUp() {
| List pooledTaskInstances = jbpmContext.getTaskMgmtSession().findPooledTaskInstances("yoyo");
| for (Iterator iter = pooledTaskInstances.iterator(); iter.hasNext();) {
| TaskInstance taskInstance = (TaskInstance) iter.next();
| taskInstance.end();
| ProcessInstance processInstance = taskInstance.getTaskMgmtInstance().getProcessInstance();
| processInstance.end();
| jbpmContext.save(processInstance);
| }
| pooledTaskInstances = jbpmContext.getTaskMgmtSession().findPooledTaskInstances("yoyo");
| // assertNull(pooledTaskInstances);
| assertEquals(0, pooledTaskInstances.size());
| }
|
| public static Test suite() {
| TestSuite suite = new TestSuite("Test for jbpm");
| //$JUnit-BEGIN$
| suite.addTest(new JbpmDelegatorTest("testCleanUp"));
| suite.addTest(new JbpmDelegatorTest("testDeployProcessXml"));
|
| //start a process instance
| suite.addTest(new JbpmDelegatorTest("testCreateStartTaskInstance"));
|
| //do some changes in TaskMgmtDefinition
| suite.addTest(new JbpmDelegatorTest("testChangeProcessDefinition"));
|
| //complete the already assigned taskInstance
| suite.addTest(new JbpmDelegatorTest("testCompleteTask"));
|
| //test if the processInstance is still using the old process definition, but failed here
| suite.addTest(new JbpmDelegatorTest("testPooledTaskInstances"));
| //$JUnit-END$
| return suite;
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4036908#4036908
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4036908
More information about the jboss-user
mailing list