KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.jpdl.exe;
2
3 import junit.framework.TestCase;
4
5 import org.jbpm.graph.def.ProcessDefinition;
6 import org.jbpm.graph.exe.ExecutionContext;
7 import org.jbpm.graph.exe.ProcessInstance;
8 import org.jbpm.graph.node.DecisionHandler;
9
10 public class DecisionHandlerTest extends TestCase {
11
12   public static class LeadEvaluator implements DecisionHandler {
13     private static final long serialVersionUID = 1L;
14
15     public String JavaDoc decide(ExecutionContext executionContext) {
16       int budget = ((Number JavaDoc)executionContext.getContextInstance().getVariable("budget")).intValue();
17       if (budget>1000) return "important lead";
18       else if (budget>100) return "lead";
19       return "beggars";
20     }
21   }
22
23   ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
24     "<process-definition>" +
25     " <start-state>" +
26     " <transition to='d' />" +
27     " </start-state>" +
28     " <decision name='d'>" +
29     " <handler class='org.jbpm.jpdl.exe.DecisionHandlerTest$LeadEvaluator'/>" +
30     " <transition name='important lead' to='harras them'/>" +
31     " <transition name='lead' to='put it in the lead db'/>" +
32     " <transition name='beggars' to='forget about it'/>" +
33     " </decision>" +
34     " <state name='harras them' />" +
35     " <state name='put it in the lead db' />" +
36     " <state name='forget about it' />" +
37     "</process-definition>" );
38   
39   public void testBudgetHignerThenThousand() {
40     ProcessInstance processInstance = new ProcessInstance(processDefinition);
41     processInstance.getContextInstance().setVariable("budget", new Integer JavaDoc(3500));
42     processInstance.signal();
43     
44     assertEquals(processDefinition.getNode("harras them"), processInstance.getRootToken().getNode());
45   }
46
47   public void testBudgetBetweenHundredAndThousand() {
48     ProcessInstance processInstance = new ProcessInstance(processDefinition);
49     processInstance.getContextInstance().setVariable("budget", new Integer JavaDoc(350));
50     processInstance.signal();
51     
52     assertEquals(processDefinition.getNode("put it in the lead db"), processInstance.getRootToken().getNode());
53   }
54
55   public void testSmallBudget() {
56     ProcessInstance processInstance = new ProcessInstance(processDefinition);
57     processInstance.getContextInstance().setVariable("budget", new Integer JavaDoc(35));
58     processInstance.signal();
59     
60     assertEquals(processDefinition.getNode("forget about it"), processInstance.getRootToken().getNode());
61   }
62
63 }
64
Popular Tags