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