KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > scheduler > exe > SchedulerTest


1 package org.jbpm.scheduler.exe;
2
3 import java.util.List JavaDoc;
4
5 import junit.framework.TestCase;
6
7 import org.jbpm.graph.def.ProcessDefinition;
8 import org.jbpm.graph.exe.ProcessInstance;
9 import org.jbpm.scheduler.exe.SchedulerInstance.CancelledTimer;
10
11 public class SchedulerTest extends TestCase {
12   
13   public void testTimerCreation() {
14     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
15       "<process-definition>" +
16       " <start-state>" +
17       " <transition to='catch crooks' />" +
18       " </start-state>" +
19       " <state name='catch crooks'>" +
20       " <timer name='reminder' " +
21       " duedate='3 business hours' " +
22       " repeat='10 business minutes'" +
23       " transition='time-out-transition' >" +
24       " <action class='the-remainder-action-class-name' />" +
25       " </timer>" +
26       " </state>" +
27       "</process-definition>"
28     );
29     
30     ProcessInstance processInstance = new ProcessInstance(processDefinition);
31     processInstance.signal();
32     
33     assertEquals(1, processInstance.getSchedulerInstance().getScheduledTimers().size());
34     Timer scheduledTimer = (Timer) processInstance.getSchedulerInstance().getScheduledTimers().get(0);
35     assertEquals("reminder", scheduledTimer.name);
36     assertEquals(processDefinition.getNode("catch crooks"), scheduledTimer.graphElement);
37     System.out.println("due date: "+scheduledTimer.dueDate);
38     assertNotNull(scheduledTimer.dueDate);
39     assertEquals("10 business minutes", scheduledTimer.repeat);
40     assertEquals("the-remainder-action-class-name", scheduledTimer.action.getActionDelegation().getClassName());
41     assertSame(processInstance.getRootToken(), scheduledTimer.token);
42     assertEquals("time-out-transition", scheduledTimer.transitionName);
43   }
44
45   public void testCreateTimerAction() {
46     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
47       "<process-definition>" +
48       " <start-state>" +
49       " <transition to='catch crooks' />" +
50       " </start-state>" +
51       " <state name='catch crooks'>" +
52       " <event type='node-enter'>" +
53       " <create-timer name='reminder' " +
54       " duedate='3 business hours' " +
55       " repeat='10 business minutes'" +
56       " transition='time-out-transition' >" +
57       " <action class='the-remainder-action-class-name' />" +
58       " </create-timer>" +
59       " </event>" +
60       " <transition to='end'/>" +
61       " </state>" +
62       " <end-state name='end'/>" +
63       "</process-definition>"
64     );
65     
66     ProcessInstance processInstance = new ProcessInstance(processDefinition);
67     processInstance.signal();
68     
69     assertEquals(1, processInstance.getSchedulerInstance().getScheduledTimers().size());
70     Timer scheduledTimer = (Timer) processInstance.getSchedulerInstance().getScheduledTimers().get(0);
71     assertEquals("reminder", scheduledTimer.name);
72     assertEquals(processDefinition.getNode("catch crooks"), scheduledTimer.graphElement);
73     System.out.println("due date: "+scheduledTimer.dueDate);
74     assertNotNull(scheduledTimer.dueDate);
75     assertEquals("10 business minutes", scheduledTimer.repeat);
76     assertEquals("the-remainder-action-class-name", scheduledTimer.action.getActionDelegation().getClassName());
77     assertSame(processInstance.getRootToken(), scheduledTimer.token);
78     assertEquals("time-out-transition", scheduledTimer.transitionName);
79
80     // while we are at it, i might as well check if the cancel timer is not
81
// executed ;)
82
processInstance.signal();
83     assertEquals(0, processInstance.getSchedulerInstance().getCancelledTimerNames().size());
84   }
85
86   public void testTimerCancelAction() {
87     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
88       "<process-definition>" +
89       " <start-state>" +
90       " <transition to='catch crooks' />" +
91       " </start-state>" +
92       " <state name='catch crooks'>" +
93       " <timer name='reminder' " +
94       " duedate='3 business hours' " +
95       " repeat='10 business minutes'" +
96       " transition='time-out-transition' >" +
97       " <action class='the-remainder-action-class-name' />" +
98       " </timer>" +
99       " <transition to='end'/>" +
100       " </state>" +
101       " <end-state name='end'/>" +
102       "</process-definition>"
103     );
104     
105     ProcessInstance processInstance = new ProcessInstance(processDefinition);
106     processInstance.signal();
107     processInstance.signal();
108     
109     List JavaDoc cancelledTimerNames = processInstance.getSchedulerInstance().getCancelledTimerNames();
110     assertEquals(1, cancelledTimerNames.size());
111     SchedulerInstance.CancelledTimer cancelledTimer = (CancelledTimer) cancelledTimerNames.get(0);
112     assertEquals("reminder", cancelledTimer.getTimerName());
113     assertSame(processInstance.getRootToken(), cancelledTimer.getToken());
114   }
115 }
116
Popular Tags