KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > tutorial > context > ContextTest


1 package org.jbpm.tutorial.context;
2
3 import junit.framework.TestCase;
4
5 import org.jbpm.context.exe.ContextInstance;
6 import org.jbpm.graph.def.ProcessDefinition;
7 import org.jbpm.graph.exe.ProcessInstance;
8
9 public class ContextTest extends TestCase {
10   
11   public void testContext() {
12     // Also this example starts from the hello world process.
13
// This time even without modification.
14
ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
15       "<process-definition>" +
16       " <start-state>" +
17       " <transition to='s' />" +
18       " </start-state>" +
19       " <state name='s'>" +
20       " <transition to='end' />" +
21       " </state>" +
22       " <end-state name='end' />" +
23       "</process-definition>"
24     );
25     
26     ProcessInstance processInstance =
27       new ProcessInstance(processDefinition);
28
29     // Fetch the context instance from the process instance
30
// for working with the process variables.
31
ContextInstance contextInstance =
32       processInstance.getContextInstance();
33     
34     // Before the process has left the start-state,
35
// we are going to set some process variables in the
36
// context of the process instance.
37
contextInstance.setVariable("amount", new Integer JavaDoc(500));
38     contextInstance.setVariable("reason", "i met my deadline");
39     
40     // From now on, these variables are associated with the
41
// process instance. The process variables are now accessible
42
// by user code via the API shown here, but also in the actions
43
// and node implementations. The process variables are also
44
// stored into the database as a part of the process instance.
45

46     processInstance.signal();
47     
48     // The variables are accessible via the contextInstance.
49

50     assertEquals(new Integer JavaDoc(500),
51                  contextInstance.getVariable("amount"));
52     assertEquals("i met my deadline",
53                  contextInstance.getVariable("reason"));
54   }
55
56 }
57
Popular Tags