WorkflowServiceImpl.isReassignable() method now gives an up-to-date result, avoiding stale data issues.

Added tests to check isReassignable works on a task that has been completed by JBPM timer.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32196 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
N Smith
2011-11-22 16:59:07 +00:00
parent 5e1f1de583
commit 656a792d06
3 changed files with 83 additions and 16 deletions

View File

@@ -825,6 +825,8 @@ public class WorkflowServiceImpl implements WorkflowService
*/ */
public boolean isTaskEditable(WorkflowTask task, String username) public boolean isTaskEditable(WorkflowTask task, String username)
{ {
task = getTaskById(task.getId()); // Refresh the task.
// if the task is complete it is not editable // if the task is complete it is not editable
if (task.getState() == WorkflowTaskState.COMPLETED) if (task.getState() == WorkflowTaskState.COMPLETED)
{ {
@@ -856,6 +858,8 @@ public class WorkflowServiceImpl implements WorkflowService
*/ */
public boolean isTaskReassignable(WorkflowTask task, String username) public boolean isTaskReassignable(WorkflowTask task, String username)
{ {
task = getTaskById(task.getId()); // Refresh the task.
// if the task is complete it is not reassignable // if the task is complete it is not reassignable
if (task.getState() == WorkflowTaskState.COMPLETED) if (task.getState() == WorkflowTaskState.COMPLETED)
{ {
@@ -898,6 +902,8 @@ public class WorkflowServiceImpl implements WorkflowService
*/ */
public boolean isTaskClaimable(WorkflowTask task, String username) public boolean isTaskClaimable(WorkflowTask task, String username)
{ {
task = getTaskById(task.getId()); // Refresh the task.
// if the task is complete it is not claimable // if the task is complete it is not claimable
if (task.getState() == WorkflowTaskState.COMPLETED) if (task.getState() == WorkflowTaskState.COMPLETED)
{ {
@@ -920,6 +926,8 @@ public class WorkflowServiceImpl implements WorkflowService
*/ */
public boolean isTaskReleasable(WorkflowTask task, String username) public boolean isTaskReleasable(WorkflowTask task, String username)
{ {
task = getTaskById(task.getId()); // Refresh the task.
// if the task is complete it is not releasable // if the task is complete it is not releasable
if (task.getState() == WorkflowTaskState.COMPLETED) if (task.getState() == WorkflowTaskState.COMPLETED)
{ {

View File

@@ -22,6 +22,7 @@ package org.alfresco.repo.workflow.jbpm;
import java.io.InputStream; import java.io.InputStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.content.MimetypeMap;
@@ -47,10 +48,10 @@ import junit.framework.TestCase;
* @since 4.0 * @since 4.0
* *
*/ */
public class JbpmTimerExceptionTest extends TestCase public class JbpmTimerTest extends TestCase
{ {
private static final String defLocation = "jbpmresources/test_timerException.xml"; private static final String simpleDefLocation = "jbpmresources/test_simpleTimer.xml";
private static final String defName = "jbpm$wf:testTimerException"; private static final String exceptionDefLocation = "jbpmresources/test_timerException.xml";
private WorkflowService workflowService; private WorkflowService workflowService;
private WorkflowTestHelper testHelper; private WorkflowTestHelper testHelper;
@@ -58,6 +59,8 @@ public class JbpmTimerExceptionTest extends TestCase
public void testTimerException() throws Exception public void testTimerException() throws Exception
{ {
defId = deployDefinition(exceptionDefLocation);
NodeRef pckg = workflowService.createPackage(null); NodeRef pckg = workflowService.createPackage(null);
Map<QName, Serializable> params = new HashMap<QName, Serializable>(); Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_PACKAGE, pckg); params.put(WorkflowModel.ASSOC_PACKAGE, pckg);
@@ -71,6 +74,29 @@ public class JbpmTimerExceptionTest extends TestCase
System.out.println("Done!"); System.out.println("Done!");
} }
public void testTimerIsReassignable() throws Exception
{
defId = deployDefinition(simpleDefLocation);
NodeRef pckg = workflowService.createPackage(null);
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_PACKAGE, pckg);
params.put(WorkflowModel.ASSOC_ASSIGNEE, AuthenticationUtil.getAdminUserName());
WorkflowPath path = workflowService.startWorkflow(defId, params);
String instanceId = path.getInstance().getId();
WorkflowTask start = workflowService.getStartTask(instanceId);
workflowService.endTask(start.getId(), null);
List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId());
WorkflowTask task = tasks.get(0);
assertTrue(workflowService.isTaskReassignable(task, AuthenticationUtil.getAdminUserName()));
// Wait for timer to end task
Thread.sleep(30000);
assertFalse(workflowService.isTaskReassignable(task, AuthenticationUtil.getAdminUserName()));
}
@Override @Override
protected void setUp() throws Exception protected void setUp() throws Exception
{ {
@@ -82,20 +108,19 @@ public class JbpmTimerExceptionTest extends TestCase
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
testHelper = new WorkflowTestHelper(adminService, JBPMEngine.ENGINE_ID, false); testHelper = new WorkflowTestHelper(adminService, JBPMEngine.ENGINE_ID, false);
testHelper.setVisible(true); testHelper.setVisible(true);
}
/**
* @return
*/
private String deployDefinition(String location)
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream input = classLoader.getResourceAsStream(defLocation); InputStream input = classLoader.getResourceAsStream(exceptionDefLocation);
if(workflowService.isDefinitionDeployed(JBPMEngine.ENGINE_ID, input, MimetypeMap.MIMETYPE_XML) == false) input = classLoader.getResourceAsStream(location);
{ WorkflowDeployment deployment
input = classLoader.getResourceAsStream(defLocation); = workflowService.deployDefinition(JBPMEngine.ENGINE_ID, input, MimetypeMap.MIMETYPE_XML);
WorkflowDeployment deployment= workflowService.deployDefinition(JBPMEngine.ENGINE_ID, input, MimetypeMap.MIMETYPE_XML); return deployment.getDefinition().getId();
defId = deployment.getDefinition().getId();
}
else
{
defId = workflowService.getDefinitionByName(defName).getId();
}
} }
@Override @Override

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wf:testSimpleTimer">
<start-state name="start">
<task name="wf:submitAdhocTask" />
<transition name="" to="adhoc" />
</start-state>
<swimlane name="assignee">
<assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
<actor>#{bpm_assignee}</actor>
</assignment>
</swimlane>
<task-node name="adhoc">
<task name="wf:adhocTask" swimlane="assignee">
<event type="task-create"/>
<timer name="timeout" duedate="1 second" transition="end">
<action name="reminder" class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>
Packages.java.lang.System.out.println("Timer Fired");
</script>
</action>
</timer>
</task>
<transition name="end" to="end" />
</task-node>
<end-state name="end" />
</process-definition>