KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > tdd > AuctionXmlTest


1 package org.jbpm.tdd;
2
3 import junit.framework.TestCase;
4
5 import org.jbpm.graph.def.ProcessDefinition;
6 import org.jbpm.graph.exe.ProcessInstance;
7 import org.jbpm.graph.exe.Token;
8 import org.jbpm.graph.node.EndState;
9 import org.jbpm.graph.node.StartState;
10 import org.jbpm.graph.node.State;
11
12 public class AuctionXmlTest extends TestCase {
13
14   // parse the process definition
15
static ProcessDefinition auctionProcess =
16       ProcessDefinition.parseXmlResource("org/jbpm/tdd/auction.xml");
17
18   // get the nodes for easy asserting
19
static StartState start = auctionProcess.getStartState();
20   static State auction = (State) auctionProcess.getNode("auction");
21   static EndState end = (EndState) auctionProcess.getNode("end");
22
23   // the process instance
24
ProcessInstance processInstance;
25
26   // the main path of execution
27
Token token;
28
29   public void setUp() {
30     // create a new process instance for the given process definition
31
processInstance = new ProcessInstance(auctionProcess);
32
33     // the main path of execution is the root token
34
token = processInstance.getRootToken();
35   }
36
37   public void testMainScenario() {
38     // after process instance creation, the main path of
39
// execution is positioned in the start state.
40
assertSame(start, token.getNode());
41     
42     token.signal();
43     
44     // after the signal, the main path of execution has
45
// moved to the auction state
46
assertSame(auction, token.getNode());
47     
48     token.signal();
49     
50     // after the signal, the main path of execution has
51
// moved to the end state and the process has ended
52
assertSame(end, token.getNode());
53     assertTrue(processInstance.hasEnded());
54   }
55 }
56
Popular Tags