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

@@ -22,6 +22,7 @@ package org.alfresco.repo.workflow.jbpm;
import java.io.InputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.content.MimetypeMap;
@@ -47,10 +48,10 @@ import junit.framework.TestCase;
* @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 defName = "jbpm$wf:testTimerException";
private static final String simpleDefLocation = "jbpmresources/test_simpleTimer.xml";
private static final String exceptionDefLocation = "jbpmresources/test_timerException.xml";
private WorkflowService workflowService;
private WorkflowTestHelper testHelper;
@@ -58,6 +59,8 @@ public class JbpmTimerExceptionTest extends TestCase
public void testTimerException() throws Exception
{
defId = deployDefinition(exceptionDefLocation);
NodeRef pckg = workflowService.createPackage(null);
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_PACKAGE, pckg);
@@ -70,6 +73,29 @@ public class JbpmTimerExceptionTest extends TestCase
Thread.sleep(30000);
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
protected void setUp() throws Exception
@@ -82,20 +108,19 @@ public class JbpmTimerExceptionTest extends TestCase
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
testHelper = new WorkflowTestHelper(adminService, JBPMEngine.ENGINE_ID, false);
testHelper.setVisible(true);
}
/**
* @return
*/
private String deployDefinition(String location)
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream input = classLoader.getResourceAsStream(defLocation);
if(workflowService.isDefinitionDeployed(JBPMEngine.ENGINE_ID, input, MimetypeMap.MIMETYPE_XML) == false)
{
input = classLoader.getResourceAsStream(defLocation);
WorkflowDeployment deployment= workflowService.deployDefinition(JBPMEngine.ENGINE_ID, input, MimetypeMap.MIMETYPE_XML);
defId = deployment.getDefinition().getId();
}
else
{
defId = workflowService.getDefinitionByName(defName).getId();
}
InputStream input = classLoader.getResourceAsStream(exceptionDefLocation);
input = classLoader.getResourceAsStream(location);
WorkflowDeployment deployment
= workflowService.deployDefinition(JBPMEngine.ENGINE_ID, input, MimetypeMap.MIMETYPE_XML);
return deployment.getDefinition().getId();
}
@Override