KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > graph > exe > TokenDbTest


1 package org.jbpm.graph.exe;
2
3 import org.jbpm.db.AbstractDbTestCase;
4 import org.jbpm.graph.def.ProcessDefinition;
5 import org.jbpm.graph.node.StartState;
6
7 public class TokenDbTest extends AbstractDbTestCase {
8
9   public void testTokenName() {
10     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
11       "<process-definition>" +
12       " <start-state />" +
13       "</process-definition>" );
14     graphSession.saveProcessDefinition(processDefinition);
15     ProcessInstance processInstance = new ProcessInstance(processDefinition);
16     processInstance.getRootToken().name = "roottoken";
17
18     processInstance = saveAndReload(processInstance);
19
20     assertEquals("roottoken", processInstance.getRootToken().getName());
21   }
22
23   public void testTokenStartAndEndDate() {
24     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
25       "<process-definition>" +
26       " <start-state>" +
27       " <transition to='end' />" +
28       " </start-state>" +
29       " <end-state name='end'/>" +
30       "</process-definition>" );
31     graphSession.saveProcessDefinition(processDefinition);
32     ProcessInstance processInstance = new ProcessInstance(processDefinition);
33     processInstance.signal();
34
35     processInstance = saveAndReload(processInstance);
36     Token token = processInstance.getRootToken();
37     
38     assertNotNull(token.getStart());
39     assertNotNull(token.getEnd());
40   }
41
42   public void testTokenNode() {
43     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
44       "<process-definition>" +
45       " <start-state name='s' />" +
46       "</process-definition>");
47     graphSession.saveProcessDefinition(processDefinition);
48
49     ProcessInstance processInstance = new ProcessInstance(processDefinition);
50     processInstance = saveAndReload(processInstance);
51     
52     StartState s = processInstance.getProcessDefinition().getStartState();
53     
54     assertSame(s , processInstance.getRootToken().getNode());
55   }
56
57   public void testTokenProcessInstance() {
58     ProcessDefinition processDefinition = new ProcessDefinition();
59     graphSession.saveProcessDefinition(processDefinition);
60
61     ProcessInstance processInstance = new ProcessInstance(processDefinition);
62     processInstance = saveAndReload(processInstance);
63     
64     assertSame(processInstance , processInstance.getRootToken().getProcessInstance());
65   }
66
67   public void testTokenParent() {
68     ProcessDefinition processDefinition = new ProcessDefinition();
69     graphSession.saveProcessDefinition(processDefinition);
70
71     ProcessInstance processInstance = new ProcessInstance(processDefinition);
72     new Token(processInstance.getRootToken(), "one");
73
74     processInstance = saveAndReload(processInstance);
75     Token rootToken = processInstance.getRootToken();
76     Token childOne = rootToken.getChild("one");
77     
78     assertSame(rootToken , childOne.getParent());
79   }
80   
81   public void testTokenChildren() {
82     ProcessDefinition processDefinition = new ProcessDefinition();
83     graphSession.saveProcessDefinition(processDefinition);
84
85     ProcessInstance processInstance = new ProcessInstance(processDefinition);
86     new Token(processInstance.getRootToken(), "one");
87     new Token(processInstance.getRootToken(), "two");
88     new Token(processInstance.getRootToken(), "three");
89
90     processInstance = saveAndReload(processInstance);
91     Token rootToken = processInstance.getRootToken();
92     Token childOne = rootToken.getChild("one");
93     Token childTwo = rootToken.getChild("two");
94     Token childThree = rootToken.getChild("three");
95     
96     assertEquals("one" , childOne.getName());
97     assertEquals("two" , childTwo.getName());
98     assertEquals("three" , childThree.getName());
99   }
100 }
101
Popular Tags