1 package org.jbpm.graph.action; 2 3 import java.util.List ; 4 5 import org.jbpm.db.AbstractDbTestCase; 6 import org.jbpm.graph.def.Action; 7 import org.jbpm.graph.def.Event; 8 import org.jbpm.graph.def.ProcessDefinition; 9 10 public class ActionDbTest extends AbstractDbTestCase { 11 12 public void testIsPropagationAllowedFalse() { 13 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 14 "<process-definition>" + 15 " <node name='n'>" + 16 " <event type='node-enter'>" + 17 " <action name='a' class='unimportant' accept-propagated-events='false' />" + 18 " </event>" + 19 " </node>" + 20 "</process-definition>"); 21 22 processDefinition = saveAndReload(processDefinition); 23 24 Action action = processDefinition.getAction("a"); 25 assertFalse(action.acceptsPropagatedEvents()); 26 } 27 28 public void testIsPropagationAllowedTrue() { 29 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 30 "<process-definition>" + 31 " <node name='n'>" + 32 " <event type='node-enter'>" + 33 " <action name='a' class='unimportant' accept-propagated-events='true' />" + 34 " </event>" + 35 " </node>" + 36 "</process-definition>"); 37 38 processDefinition = saveAndReload(processDefinition); 39 40 Action action = processDefinition.getAction("a"); 41 assertTrue(action.acceptsPropagatedEvents()); 42 } 43 44 public void testReferencedAction() { 45 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 46 "<process-definition>" + 47 " <node name='n'>" + 48 " <event type='node-enter'>" + 49 " <action ref-name='a'/>" + 50 " </event>" + 51 " </node>" + 52 " <action name='a' class='unimportant'/>" + 53 "</process-definition>"); 54 55 processDefinition = saveAndReload(processDefinition); 56 57 Action nodeAction = (Action) processDefinition.getNode("n").getEvent("node-enter").getActions().get(0); 58 assertSame(processDefinition.getAction("a"), nodeAction.getReferencedAction()); 59 } 60 61 public void testActionDelegation() { 62 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 63 "<process-definition>" + 64 " <action name='a' class='myclass' config-type='constructor'>" + 65 " <myconfiguration></myconfiguration>" + 66 " </action>" + 67 "</process-definition>"); 68 69 processDefinition = saveAndReload(processDefinition); 70 71 Action action = processDefinition.getAction("a"); 72 assertNotNull(action.getActionDelegation()); 73 } 74 75 public void testEvent() { 76 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 77 "<process-definition>" + 78 " <node name='n'>" + 79 " <event type='node-enter'>" + 80 " <action name='a' class='unimportant'/>" + 81 " </event>" + 82 " </node>" + 83 "</process-definition>"); 84 85 processDefinition = saveAndReload(processDefinition); 86 87 Event event = processDefinition.getNode("n").getEvent("node-enter"); 88 Action action = processDefinition.getAction("a"); 89 assertSame(event, action.getEvent()); 90 } 91 92 public void testProcessDefinition() { 93 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 94 "<process-definition>" + 95 " <node name='n'>" + 96 " <event type='node-enter'>" + 97 " <action name='a' class='unimportant'/>" + 98 " </event>" + 99 " </node>" + 100 "</process-definition>"); 101 102 processDefinition = saveAndReload(processDefinition); 103 104 Action action = processDefinition.getAction("a"); 105 assertSame(processDefinition, action.getProcessDefinition()); 106 } 107 108 public void testProcessDefinitionActionMap() { 109 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 110 "<process-definition>" + 111 " <action name='a' class='unimportant'/>" + 112 " <action name='b' class='unimportant'/>" + 113 " <action name='c' class='unimportant'/>" + 114 " <action name='d' class='unimportant'/>" + 115 "</process-definition>"); 116 117 processDefinition = saveAndReload(processDefinition); 118 119 assertEquals("a", processDefinition.getAction("a").getName()); 120 assertEquals("b", processDefinition.getAction("b").getName()); 121 assertEquals("c", processDefinition.getAction("c").getName()); 122 assertEquals("d", processDefinition.getAction("d").getName()); 123 } 124 125 public void testNodeEventCascading() { 126 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 127 "<process-definition>" + 128 " <node name='n'>" + 129 " <event type='node-enter'>" + 130 " <action name='a' class='unimportant'/>" + 131 " <action name='b' class='unimportant'/>" + 132 " <action name='c' class='unimportant'/>" + 133 " <action name='d' class='unimportant'/>" + 134 " </event>" + 135 " </node>" + 136 "</process-definition>"); 137 138 processDefinition = saveAndReload(processDefinition); 139 140 List actions = processDefinition.getNode("n").getEvent("node-enter").getActions(); 141 142 assertEquals(processDefinition.getAction("a"), actions.get(0)); 143 assertEquals(processDefinition.getAction("b"), actions.get(1)); 144 assertEquals(processDefinition.getAction("c"), actions.get(2)); 145 assertEquals(processDefinition.getAction("d"), actions.get(3)); 146 } 147 148 public void testTransitionEventCascading() { 149 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 150 "<process-definition>" + 151 " <node name='n'>" + 152 " <transition name='t' to='n'>" + 153 " <action name='a' class='unimportant'/>" + 154 " <action name='b' class='unimportant'/>" + 155 " <action name='c' class='unimportant'/>" + 156 " <action name='d' class='unimportant'/>" + 157 " </transition>" + 158 " </node>" + 159 "</process-definition>"); 160 161 processDefinition = saveAndReload(processDefinition); 162 163 List actions = processDefinition.getNode("n").getLeavingTransition("t").getEvent("transition").getActions(); 164 165 assertEquals(processDefinition.getAction("a"), actions.get(0)); 166 assertEquals(processDefinition.getAction("b"), actions.get(1)); 167 assertEquals(processDefinition.getAction("c"), actions.get(2)); 168 assertEquals(processDefinition.getAction("d"), actions.get(3)); 169 } 170 } 171 | Popular Tags |