Author: jbarrez
Date: 2009-07-16 04:36:51 -0400 (Thu, 16 Jul 2009)
New Revision: 5309
Modified:
jbpm4/trunk/modules/distro/src/main/files/readme.html
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/TaskActivity.java
jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/taskactivity/TaskCompletionTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/taskactivity/TaskOutcomesTest.java
Log:
JBPM-2425: When taskService.completeTask(taskId, outcome) is called with an unexisting
outcome, an exception is thrown instead of suspending the process.
Modified: jbpm4/trunk/modules/distro/src/main/files/readme.html
===================================================================
--- jbpm4/trunk/modules/distro/src/main/files/readme.html 2009-07-16 07:26:11 UTC (rev
5308)
+++ jbpm4/trunk/modules/distro/src/main/files/readme.html 2009-07-16 08:36:51 UTC (rev
5309)
@@ -34,8 +34,19 @@
guide are not guaranteed to be forward compatible.</td>
</tr>
</table>
+
+<h1>Release Notes for jBPM 4.1</h1>
+<h2>Changed functionality</h2>
+<ul>
+<li>
+ Calling <i>taskService.completeTask(String taskId, String outcome)</i>i>
with an unexisting outcome will
+ throw an exception instead of suspending the process instance. (see <a
href="https://jira.jboss.org/jira/browse/JBPM-2425">[JBPM-24...>)
+</li>
+</ul>
+
+
<h1>Release Notes for jBPM 4.0 (GA)</h1>
<h2>Known Issues
Modified:
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/TaskActivity.java
===================================================================
---
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/TaskActivity.java 2009-07-16
07:26:11 UTC (rev 5308)
+++
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/TaskActivity.java 2009-07-16
08:36:51 UTC (rev 5309)
@@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;
+import org.jbpm.api.JbpmException;
import org.jbpm.api.activity.ActivityExecution;
import org.jbpm.api.task.Task;
import org.jbpm.internal.log.Log;
@@ -130,11 +131,9 @@
}
} else {
// if a user specified outcome was provided and it doesn't
- // match with an outgoing transition name, then the process
- // instance is suspended. parked for admin intervention.
- log.info("No outcome named '" + signalName + "' was
found."
- + "The process instance is now suspended.");
- ((ExecutionImpl)execution.getProcessInstance()).suspend();
+ // match with an outgoing transition name, then an exception is
+ // thrown since this is likely a programmatic error.
+ throw new JbpmException("No outcome named '" + signalName +
"' was found.");
}
}
if (transition!=null) {
Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java 2009-07-16
07:26:11 UTC (rev 5308)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java 2009-07-16
08:36:51 UTC (rev 5309)
@@ -199,6 +199,27 @@
return null;
}
+ public void assertNoOpenTasks(String processInstanceId) {
+ List<Task> tasks =
taskService.createTaskQuery().processInstanceId(processInstanceId).list();
+ assertTrue("There were still open tasks found for the process instance with id
" +
+ processInstanceId + ". Current tasks are: " +
+ listAllOpenTasks(processInstanceId), tasks.isEmpty());
+ }
+
+ protected String listAllOpenTasks(String processInstanceId) {
+ List<Task> tasks =
taskService.createTaskQuery().processInstanceId(processInstanceId).list();
+ StringBuilder result = new StringBuilder();
+ for (Task task : tasks) {
+ result.append("'" + task.getName() + "', ");
+ }
+
+ if (result.length() > 2) {
+ result.setLength(result.length() - 2); // remove the last ', '
+ }
+
+ return result.toString();
+ }
+
// execution helper methods //////////////////////////////////////////
public void assertExecutionEnded(String processInstanceId) {
@@ -262,7 +283,11 @@
for (String activeActivity : activeActivities) {
result.append("'" + activeActivity + "', ");
}
- result.setLength(result.length() - 2); // remove the last ', '
+
+ if (result.length() > 2) {
+ result.setLength(result.length() - 2); // remove the last ', '
+ }
+
return result.toString();
}
Modified:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java 2009-07-16
07:26:11 UTC (rev 5308)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java 2009-07-16
08:36:51 UTC (rev 5309)
@@ -23,6 +23,7 @@
import java.util.List;
+import org.jbpm.api.JbpmException;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.history.HistoryProcessInstanceQuery;
@@ -75,32 +76,4 @@
assertEquals(0, processInstances.size());
}
- //Additonal test case for JBPM-2319
- public void testProcessInstanceEndState() {
- deployJpdlXmlString(
- "<process name='testProcess'>" +
- " <start name='start'>" +
- " <transition to='task'/>" +
- " </start>" +
- " <task name='task' >" +
- " <transition name='Reject (risk)' to='Rejected by risk'
/>" +
- " <transition name='Reject (reporting)' to='Rejected by
reporting' />" +
- " </task>" +
- " <end name='Rejected by risk' />" +
- " <end name='Rejected by reporting' />" +
- "</process>"
- );
-
- ProcessInstance pi =
executionService.startProcessInstanceByKey("testProcess");
- Task task = taskService.createTaskQuery()
- .processInstanceId(pi.getId())
- .uniqueResult();
- taskService.completeTask(task.getId(), "TYPO");
-
- HistoryProcessInstance historyPi =
historyService.createHistoryProcessInstanceQuery()
- .processInstanceId(pi.getId())
- .uniqueResult();
- assertEquals(HistoryProcessInstance.STATE_ACTIVE, historyPi.getState());
- }
-
}
Modified:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/taskactivity/TaskCompletionTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/taskactivity/TaskCompletionTest.java 2009-07-16
07:26:11 UTC (rev 5308)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/taskactivity/TaskCompletionTest.java 2009-07-16
08:36:51 UTC (rev 5309)
@@ -57,6 +57,7 @@
Ids ids = deployAndStartProcessInstance();
taskService.completeTask(ids.taskId);
assertExecutionInOneOrMoreActivitiesActive(ids.processInstanceId,
"stateOne", "stateTwo");
+ assertNoOpenTasks(ids.processInstanceId);
assertHistoryTaskCreated(ids.processInstanceId, null);
}
@@ -75,7 +76,7 @@
}
}
- public void testCompletionWithInvalidId() {
+ public void testCompletionWithInvalidTaskId() {
try {
taskService.completeTask(Long.toString(-123456789L));
fail();
@@ -87,17 +88,38 @@
public void testCompletionWithOutcome() {
Ids ids = deployAndStartProcessInstance();
taskService.completeTask(ids.taskId, "one");
+
assertActivityActive(ids.processInstanceId, "stateOne");
assertNotActivityActive(ids.processInstanceId, "stateTwo");
+
+ assertNoOpenTasks(ids.processInstanceId);
assertHistoryTaskCreated(ids.processInstanceId, "one");
}
+ // Test for JBPM-2425
+ public void testCompletionWithInvalidOutcome() {
+ Ids ids = deployAndStartProcessInstance();
+
+ try {
+ taskService.completeTask(ids.taskId, "doesn't exist");
+ fail();
+ } catch (JbpmException e) {
+ // exception should be thrown
+ }
+
+ // Task should still be open now (rollback in db)
+ assertNotNull("After completion with an invalid outcome, the task should remain
unchanged",
+
taskService.createTaskQuery().processInstanceId(ids.processInstanceId).uniqueResult());
+ }
+
public void testCompletionWithVariables() {
Ids ids = deployAndStartProcessInstance();
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("testVar", "testValue");
taskService.completeTask(ids.taskId, vars);
+
assertEquals("testValue",
executionService.getVariable(ids.processInstanceId, "testVar"));
+ assertNoOpenTasks(ids.processInstanceId);
assertHistoryTaskCreated(ids.processInstanceId, null);
}
@@ -106,8 +128,11 @@
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("testVar", "testValue");
taskService.completeTask(ids.taskId, "two",vars);
+
assertEquals("testValue",
executionService.getVariable(ids.processInstanceId, "testVar"));
assertActivityActive(ids.processInstanceId, "stateTwo");
+
+ assertNoOpenTasks(ids.processInstanceId);
assertHistoryTaskCreated(ids.processInstanceId, "two");
}
@@ -123,13 +148,13 @@
return result;
}
- private void assertHistoryTaskCreated(String executionId, String outcome) {
+ private void assertHistoryTaskCreated(String executionId, String historicalOutcome) {
HistoryTask historyTask = historyService.createHistoryTaskQuery()
.executionId(executionId)
.uniqueResult();
assertNotNull(historyTask);
- if (outcome != null) {
- assertEquals(outcome, historyTask.getOutcome());
+ if (historicalOutcome != null) {
+ assertEquals(historicalOutcome, historyTask.getOutcome());
}
}
Modified:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/taskactivity/TaskOutcomesTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/taskactivity/TaskOutcomesTest.java 2009-07-16
07:26:11 UTC (rev 5308)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/taskactivity/TaskOutcomesTest.java 2009-07-16
08:36:51 UTC (rev 5309)
@@ -24,6 +24,7 @@
import java.util.HashSet;
import java.util.Set;
+import org.jbpm.api.JbpmException;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.task.Task;
import org.jbpm.test.JbpmTestCase;
@@ -139,15 +140,13 @@
.assignee("johndoe")
.uniqueResult();
- taskService.completeTask(task.getId(), "Refused");
+ try {
+ taskService.completeTask(task.getId(), "Refused");
+ fail();
+ } catch (JbpmException e) {
+ // exception should be thrown
+ }
- processInstance = executionService.
- createProcessInstanceQuery()
- .suspended()
- .processInstanceId(processInstance.getId())
- .uniqueResult();
-
- assertTrue(processInstance.isSuspended());
}
public void testGetOutcomesNoTransition() {