1 package org.jbpm.jpdl.xml; 2 3 import junit.framework.TestCase; 4 5 import org.jbpm.graph.action.Script; 6 import org.jbpm.graph.def.ProcessDefinition; 7 import org.jbpm.scheduler.def.CancelTimerAction; 8 import org.jbpm.scheduler.def.CreateTimerAction; 9 10 public class TimerXmlTest extends TestCase { 11 12 public void testTimerCreateAction() { 13 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 14 "<process-definition>" + 15 " <node name='catch crooks'>" + 16 " <timer name='reminder' " + 17 " duedate='2 business hours' " + 18 " repeat='10 business minutes'" + 19 " transition='time-out-transition' >" + 20 " <action class='the-remainder-action-class-name' />" + 21 " </timer>" + 22 " </node>" + 23 "</process-definition>" 24 ); 25 26 CreateTimerAction createTimerAction = 27 (CreateTimerAction) processDefinition 28 .getNode("catch crooks") 29 .getEvent("node-enter") 30 .getActions() 31 .get(0); 32 33 assertEquals("reminder", createTimerAction.getTimerName()); 34 assertEquals("2 business hours", createTimerAction.getDueDate()); 35 assertEquals("10 business minutes", createTimerAction.getRepeat()); 36 assertEquals("time-out-transition", createTimerAction.getTransitionName()); 37 assertEquals("the-remainder-action-class-name", createTimerAction.getTimerAction().getActionDelegation().getClassName()); 38 } 39 40 public void testTimerDefaultName() { 41 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 42 "<process-definition>" + 43 " <node name='catch crooks'>" + 44 " <timer />" + 45 " </node>" + 46 "</process-definition>" 47 ); 48 49 CreateTimerAction createTimerAction = 50 (CreateTimerAction) processDefinition 51 .getNode("catch crooks") 52 .getEvent("node-enter") 53 .getActions() 54 .get(0); 55 56 assertEquals("catch crooks", createTimerAction.getTimerName()); 57 } 58 59 public void testTimerCancelAction() { 60 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 61 "<process-definition>" + 62 " <node name='catch crooks'>" + 63 " <timer />" + 64 " </node>" + 65 "</process-definition>" 66 ); 67 68 CancelTimerAction cancelTimerAction = 69 (CancelTimerAction) processDefinition 70 .getNode("catch crooks") 71 .getEvent("node-leave") 72 .getActions() 73 .get(0); 74 75 assertEquals("catch crooks", cancelTimerAction.getTimerName()); 76 } 77 78 public void testTimerScript() { 79 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 80 "<process-definition>" + 81 " <node name='catch crooks'>" + 82 " <timer>" + 83 " <script />" + 84 " </timer>" + 85 " </node>" + 86 "</process-definition>" 87 ); 88 89 CreateTimerAction createTimerAction = 90 (CreateTimerAction) processDefinition 91 .getNode("catch crooks") 92 .getEvent("node-enter") 93 .getActions() 94 .get(0); 95 96 assertEquals(Script.class, createTimerAction.getTimerAction().getClass()); 97 } 98 99 public void testCreateTimerAction() { 100 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 101 "<process-definition>" + 102 " <node name='catch crooks'>" + 103 " <event type='node-enter'>" + 104 " <create-timer name='reminder' " + 105 " duedate='2 business hours' " + 106 " repeat='10 business minutes'" + 107 " transition='time-out-transition' >" + 108 " <action class='the-remainder-action-class-name' />" + 109 " </create-timer>" + 110 " </event>" + 111 " </node>" + 112 "</process-definition>" 113 ); 114 115 CreateTimerAction createTimerAction = 116 (CreateTimerAction) processDefinition 117 .getNode("catch crooks") 118 .getEvent("node-enter") 119 .getActions() 120 .get(0); 121 122 assertEquals("reminder", createTimerAction.getTimerName()); 123 assertEquals("2 business hours", createTimerAction.getDueDate()); 124 assertEquals("10 business minutes", createTimerAction.getRepeat()); 125 assertEquals("time-out-transition", createTimerAction.getTransitionName()); 126 assertEquals("the-remainder-action-class-name", createTimerAction.getTimerAction().getActionDelegation().getClassName()); 127 } 128 129 public void testCancelTimerAction() { 130 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 131 "<process-definition>" + 132 " <node name='catch crooks'>" + 133 " <event type='node-enter'>" + 134 " <cancel-timer name='reminder' />" + 135 " </event>" + 136 " </node>" + 137 "</process-definition>" 138 ); 139 140 CancelTimerAction cancelTimerAction = 141 (CancelTimerAction) processDefinition 142 .getNode("catch crooks") 143 .getEvent("node-enter") 144 .getActions() 145 .get(0); 146 147 assertEquals("reminder", cancelTimerAction.getTimerName()); 148 } 149 } 150 | Popular Tags |