Author: rebody
Date: 2010-08-19 10:20:33 -0400 (Thu, 19 Aug 2010)
New Revision: 6614
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/listener/EventListenerExecution.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/Event.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/eventlistener/EventListenerTest.java
Log:
JBPM-2805 expose event from EventListenerExecution.
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/listener/EventListenerExecution.java
===================================================================
---
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/listener/EventListenerExecution.java 2010-08-19
14:14:16 UTC (rev 6613)
+++
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/listener/EventListenerExecution.java 2010-08-19
14:20:33 UTC (rev 6614)
@@ -22,20 +22,24 @@
package org.jbpm.api.listener;
import org.jbpm.api.Execution;
+import org.jbpm.api.model.Event;
import org.jbpm.api.model.OpenExecution;
-/** view upon an {@link Execution path of execution} exposed to
+/** view upon an {@link Execution path of execution} exposed to
* {@link EventListener} implementations.
- *
+ *
* @author Tom Baeyens
*/
public interface EventListenerExecution extends OpenExecution {
-
- /** setter for the priority. The default priority is 0, which means
- * NORMAL. Other recognized named priorities are HIGHEST (2), HIGH (1),
- * LOW (-1) and LOWEST (-2). For the rest, the user can set any other
- * priority integer value, but then, the UI will have to display it as
+
+ /** setter for the priority. The default priority is 0, which means
+ * NORMAL. Other recognized named priorities are HIGHEST (2), HIGH (1),
+ * LOW (-1) and LOWEST (-2). For the rest, the user can set any other
+ * priority integer value, but then, the UI will have to display it as
* an integer and not the named value.*/
void setPriority(int priority);
+
+ /** get the event of execution. */
+ Event getEvent();
}
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/Event.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/Event.java 2010-08-19
14:14:16 UTC (rev 6613)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/Event.java 2010-08-19
14:20:33 UTC (rev 6614)
@@ -23,7 +23,7 @@
/** event constants.
- *
+ *
* @author Tom Baeyens
*/
public interface Event {
@@ -38,4 +38,7 @@
String ASSIGN = "assign";
/** fired when an assignee is reminded of a task */
String REMIND = "remind";
+
+ /** get the name of event. */
+ String getName();
}
Modified:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/eventlistener/EventListenerTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/eventlistener/EventListenerTest.java 2010-08-19
14:14:16 UTC (rev 6613)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/eventlistener/EventListenerTest.java 2010-08-19
14:20:33 UTC (rev 6614)
@@ -36,7 +36,7 @@
* @author Tom Baeyens
*/
public class EventListenerTest extends JbpmTestCase {
-
+
public static class ProcessStartListener implements EventListener {
private static final long serialVersionUID = 1L;
public void notify(EventListenerExecution execution) {
@@ -56,15 +56,15 @@
" <state name='a' />" +
"</process>"
);
-
+
String processInstanceId =
executionService.startProcessInstanceByKey("ICL").getId();
assertEquals("true", executionService.getVariable(processInstanceId,
"isInvoked"));
-
+
executionService.setVariable(processInstanceId, "isInvoked",
"false");
-
+
executionService.signalExecutionById(processInstanceId);
-
+
assertEquals("false", executionService.getVariable(processInstanceId,
"isInvoked"));
}
@@ -95,15 +95,15 @@
" <state name='b' />" +
"</process>"
);
-
+
String processInstanceId =
executionService.startProcessInstanceByKey("ICL").getId();
- // the PropagationEnabledListener is invoked once for the start event
+ // the PropagationEnabledListener is invoked once for the start event
// of the process and once for the start event of activity a
assertEquals(2, executionService.getVariable(processInstanceId,
"invocations"));
-
+
executionService.signalExecutionById(processInstanceId);
-
+
// the listener is invoked once more for the start of activity b
assertEquals(3, executionService.getVariable(processInstanceId,
"invocations"));
}
@@ -130,9 +130,9 @@
" <state name='end' />" +
"</process>"
);
-
+
String processInstanceId =
executionService.startProcessInstanceByKey("ICL").getId();
-
+
assertEquals("true", executionService.getVariable(processInstanceId,
"isInvoked"));
}
@@ -158,12 +158,12 @@
" <state name='end' />" +
"</process>"
);
-
+
ProcessInstance processInstance =
executionService.startProcessInstanceByKey("ICL");
String processInstanceId = processInstance.getId();
assertNull(executionService.getVariable(processInstanceId, "isInvoked"));
-
+
executionService.signalExecutionById(processInstance.getId());
assertEquals("true", executionService.getVariable(processInstanceId,
"isInvoked"));
@@ -187,9 +187,9 @@
" <state name='end' />" +
"</process>"
);
-
+
String processInstanceId =
executionService.startProcessInstanceByKey("ICL").getId();
-
+
assertEquals("true", executionService.getVariable(processInstanceId,
"isInvoked"));
}
@@ -228,21 +228,46 @@
" <state name='end' />" +
"</process>"
);
-
+
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("order", new ArrayList<Integer>());
String processInstanceId =
executionService.startProcessInstanceByKey("ICL", variables).getId();
-
+
List<Integer> expectedOrder = new ArrayList<Integer>();
expectedOrder.add(1);
expectedOrder.add(2);
expectedOrder.add(3);
expectedOrder.add(4);
expectedOrder.add(5);
-
+
assertEquals(expectedOrder, executionService.getVariable(processInstanceId,
"order"));
}
+ public static class RetrieveEventNameListener implements EventListener {
+ private static final long serialVersionUID = 1L;
+ public void notify(EventListenerExecution execution) {
+ execution.setVariable("retrieveEventName",
execution.getEvent().getName());
+ }
+ }
+
+ public void testRetrieveEventNameListener() {
+ deployJpdlXmlString(
+ "<process name='retrieve event name' key='ICL'>" +
+ " <start>" +
+ " <on event='end'>" +
+ " <event-listener class='" +
RetrieveEventNameListener.class.getName() + "' />" +
+ " </on>" +
+ " <transition to='end'/>" +
+ " </start>" +
+ " <state name='end' />" +
+ "</process>"
+ );
+
+ String processInstanceId =
executionService.startProcessInstanceByKey("ICL").getId();
+
+ assertEquals("end", executionService.getVariable(processInstanceId,
"retrieveEventName"));
+ }
+
public void testProcessStartListenerExpr() {
deployJpdlXmlString(
"<process name='Insurance claim' key='ICL'>" +
@@ -255,17 +280,17 @@
" <state name='a' />" +
"</process>"
);
-
+
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("processstartlistener", new ProcessStartListener());
String processInstanceId =
executionService.startProcessInstanceByKey("ICL", variables).getId();
assertEquals("true", executionService.getVariable(processInstanceId,
"isInvoked"));
-
+
executionService.setVariable(processInstanceId, "isInvoked",
"false");
-
+
executionService.signalExecutionById(processInstanceId);
-
+
assertEquals("false", executionService.getVariable(processInstanceId,
"isInvoked"));
}
@@ -284,11 +309,11 @@
" <state name='end' />" +
"</process>"
);
-
+
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("activitystartlistener", new ActivityStartListener());
String processInstanceId =
executionService.startProcessInstanceByKey("ICL", variables).getId();
-
+
assertEquals("true", executionService.getVariable(processInstanceId,
"isInvoked"));
}
@@ -307,14 +332,14 @@
" <state name='end' />" +
"</process>"
);
-
+
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("activityendlistener", new ActivityEndListener());
ProcessInstance processInstance =
executionService.startProcessInstanceByKey("ICL", variables);
String processInstanceId = processInstance.getId();
assertNull(executionService.getVariable(processInstanceId, "isInvoked"));
-
+
executionService.signalExecutionById(processInstance.getId());
assertEquals("true", executionService.getVariable(processInstanceId,
"isInvoked"));