KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > jpdl > exe > ForkInLoopTest


1 package org.jbpm.jpdl.exe;
2
3 import junit.framework.TestCase;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.jbpm.graph.def.ProcessDefinition;
8 import org.jbpm.graph.exe.ProcessInstance;
9
10 public class ForkInLoopTest extends TestCase {
11
12     public void testCycle() {
13         ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
14         "<process-definition>" +
15         " <start-state name='start'>" +
16         " <transition to='a' />" +
17         " </start-state>" +
18         " <state name='a'>" +
19         " <transition to='f' />" +
20         " </state>" +
21         " <fork name='f'>" +
22         " <transition name='b' to='b' />" +
23         " <transition name='c' to='c' />" +
24         " </fork>" +
25         " <state name='b'>" +
26         " <transition to='j' />" +
27         " </state>" +
28         " <state name='c'>" +
29         " <transition to='j' />" +
30         " </state>" +
31         " <join name='j'>" +
32         " <transition to='d' />" +
33         " </join>" +
34         " <state name='d'>" +
35         " <transition to='a' />" +
36         " </state>" +
37         "</process-definition>" );
38          
39          
40         ProcessInstance pi = (ProcessInstance) processDefinition.createInstance();
41          
42         for (int i= 0; i<3;i++) {
43         
44             log.debug("starting round "+i);
45             pi.signal();
46             assertEquals("a", pi.getRootToken().getNode().getName());
47          
48             pi.signal();
49
50       String JavaDoc extend = "";
51             if (i >= 1) extend = Integer.toString(i+1);
52       
53             assertEquals("b", pi.findToken("/b" + extend).getNode().getName());
54             assertEquals("c", pi.findToken("/c" + extend).getNode().getName());
55          
56       log.debug("signalling '/b"+extend+"' in round "+i);
57             pi.findToken("/b" + extend).signal();
58       log.debug("signalling '/c"+extend+"' in round "+i);
59             pi.findToken("/c" + extend).signal();
60       
61             assertEquals("d", pi.getRootToken().getNode().getName());
62         }
63     }
64
65   private static final Log log = LogFactory.getLog(ForkInLoopTest.class);
66 }
Popular Tags