KickJava   Java API By Example, From Geeks To Geeks.

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


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 AuctionTextTest extends TestCase {
13
14   // parse the process definition
15
static ProcessDefinition auctionProcess = ProcessDefinition.parseXmlString(
16     "<process-definition>" +
17     " <start-state name='start'>" +
18     " <transition to='auction'/>" +
19     " </start-state>" +
20     " <state name='auction'>" +
21     " <transition to='end'/>" +
22     " </state>" +
23     " <end-state name='end'/>" +
24     "</process-definition>");
25
26   // get the nodes for easy asserting
27
static StartState start = auctionProcess.getStartState();
28   static State auction = (State) auctionProcess.getNode("auction");
29   static EndState end = (EndState) auctionProcess.getNode("end");
30
31   // the process instance
32
ProcessInstance processInstance;
33
34   // the main path of execution
35
Token token;
36
37   public void setUp() {
38     // create a new process instance for the given process definition
39
processInstance = new ProcessInstance(auctionProcess);
40
41     // the main path of execution is the root token
42
token = processInstance.getRootToken();
43   }
44
45   public void testMainScenario() {
46     // after process instance creation, the main path of
47
// execution is positioned in the start state.
48
assertSame(start, token.getNode());
49     
50     token.signal();
51     
52     // after the signal, the main path of execution has
53
// moved to the auction state
54
assertSame(auction, token.getNode());
55     
56     token.signal();
57     
58     // after the signal, the main path of execution has
59
// moved to the end state and the process has ended
60
assertSame(end, token.getNode());
61     assertTrue(processInstance.hasEnded());
62   }
63
64 }
65
Popular Tags