Fixing build failures caused by ActivitiSprintTest leaving the DB in a dirty state.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@26027 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
N Smith
2011-03-04 16:12:29 +00:00
parent abde694951
commit 5e78575ca7

View File

@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -107,10 +108,9 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
private NodeRef contentNodeRef;
private AuthenticationComponent authenticationComponent;
private List<String> workflows = new LinkedList<String>();
public void testTaskInstancesGet() throws Exception
{
String startedWorkflowId = null;
try
{
// Check USER2 starts with no tasks.
personManager.setUser(USER2);
@@ -135,8 +135,10 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
startedWorkflowId = adhocPath.getInstance().getId();
WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
String workflowId = adhocPath.getInstance().getId();
workflows.add(workflowId);
WorkflowTask startTask = workflowService.getStartTask(workflowId);
workflowService.endTask(startTask.getId(), null);
// Check USER2 now has one task.
@@ -194,47 +196,50 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
// Due after yesterday, started task should be in it
dueDateCal.add(Calendar.DAY_OF_MONTH, -1);
checkTasksPresent(MessageFormat.format(URL_TASKS_DUE_AFTER, ISO8601DateFormat.format(dueDateCal.getTime())),
true,
task.getId());
true, task.getId());
// Due before yesterday, started task shouldn't be in it
checkTasksPresent(MessageFormat.format(URL_TASKS_DUE_BEFORE, ISO8601DateFormat.format(dueDateCal.getTime())),
false,
task.getId());
false, task.getId());
// Due before tomorrow, started task should be in it
dueDateCal.add(Calendar.DAY_OF_MONTH, 2);
checkTasksPresent(MessageFormat.format(URL_TASKS_DUE_BEFORE, ISO8601DateFormat.format(dueDateCal.getTime())),
true,
task.getId());
true, task.getId());
// Due after tomorrow, started task shouldn't be in it
checkTasksPresent(MessageFormat.format(URL_TASKS_DUE_AFTER, ISO8601DateFormat.format(dueDateCal.getTime())),
false,
task.getId());
false, task.getId());
//checkFiltering(URL_TASKS + "?dueAfter=" + ISO8601DateFormat.format(dueDate));
// checkFiltering(URL_TASKS + "?dueAfter=" +
// ISO8601DateFormat.format(dueDate));
//checkFiltering(URL_TASKS + "?dueBefore=" + ISO8601DateFormat.format(new Date()));
// checkFiltering(URL_TASKS + "?dueBefore=" +
// ISO8601DateFormat.format(new Date()));
// Check property filtering on the task assigned to USER2
String customProperties = "bpm_description,bpm_priority";
checkTaskPropertyFiltering(customProperties, Arrays.asList("bpm_description", "bpm_priority"));
// Properties that aren't explicitally present on task should be returned as wel
// Properties that aren't explicitally present on task should be
// returned as wel
customProperties = "bpm_unexistingProperty,bpm_description,bpm_priority";
checkTaskPropertyFiltering(customProperties, Arrays.asList("bpm_description", "bpm_priority", "bpm_unexistingProperty"));
checkTaskPropertyFiltering(customProperties,
Arrays.asList("bpm_description", "bpm_priority", "bpm_unexistingProperty"));
// Check paging
int maxItems = 3;
for (int skipCount = 0; skipCount < totalItems; skipCount += maxItems)
{
// one of this should test situation when skipCount + maxItems > totalItems
checkPaging(MessageFormat.format(URL_USER_TASKS, USER2) + "&maxItems=" + maxItems + "&skipCount=" + skipCount, totalItems, maxItems, skipCount);
// one of this should test situation when skipCount + maxItems >
// totalItems
checkPaging(MessageFormat.format(URL_USER_TASKS, USER2) + "&maxItems=" + maxItems + "&skipCount="
+ skipCount, totalItems, maxItems, skipCount);
}
// testing when skipCount > totalItems
checkPaging(MessageFormat.format(URL_USER_TASKS, USER2) + "&maxItems=" + maxItems + "&skipCount=" + (totalItems + 1), totalItems, maxItems, totalItems + 1);
checkPaging(MessageFormat.format(URL_USER_TASKS, USER2) + "&maxItems=" + maxItems + "&skipCount="
+ (totalItems + 1), totalItems, maxItems, totalItems + 1);
// check the exclude filtering
String exclude = "wf:submitAdhocTask";
@@ -257,29 +262,10 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
break;
}
}
assertFalse("Found wf:submitAdhocTask when they were supposed to be excluded", adhocTasksPresent);
}
finally
{
if(startedWorkflowId != null)
{
try {
// Cleanup
workflowService.cancelWorkflow(startedWorkflowId);
}
catch(Throwable t)
{
// Ignore exception while cleaning up
}
}
}
}
public void testTaskInstancesForWorkflowGet() throws Exception
{
String startedWorkflowId = null;
try
{
// Check starts with no workflow.
personManager.setUser(USER2);
@@ -298,10 +284,11 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
startedWorkflowId = adhocPath.getInstance().getId();
String workflowId = adhocPath.getInstance().getId();
workflows.add(workflowId);
// End start task.
WorkflowTask startTask = workflowService.getStartTask(startedWorkflowId);
WorkflowTask startTask = workflowService.getStartTask(workflowId);
String startTaskId = startTask.getId();
workflowService.endTask(startTaskId, null);
@@ -311,7 +298,7 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
WorkflowTask task = tasks.get(0);
// Retrieve tasks using the workflow instance
String baseUrl = MessageFormat.format(URL_WORKFLOW_TASKS, startedWorkflowId);
String baseUrl = MessageFormat.format(URL_WORKFLOW_TASKS, workflowId);
// Check returns the completed start task and the current task.
String adhocTaskId = task.getId();
@@ -341,27 +328,9 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
String user2InProgressURL = user2Url + "&state=" + WorkflowTaskState.IN_PROGRESS;
checkTasksMatch(user2InProgressURL, adhocTaskId);
}
finally
{
if(startedWorkflowId != null)
{
try {
// Cleanup
workflowService.cancelWorkflow(startedWorkflowId);
}
catch(Throwable t)
{
// Ignore exception while cleaning up
}
}
}
}
public void testTaskInstanceGet() throws Exception
{
String startedWorkflowId = null;
try {
//Start workflow as USER1 and assign task to USER2.
personManager.setUser(USER1);
WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
@@ -372,7 +341,9 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
startedWorkflowId = adhocPath.getInstance().getId();
String workflowId = adhocPath.getInstance().getId();
workflows.add(workflowId);
WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
// Get the start-task
@@ -482,22 +453,6 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
checkWorkflowInstance(firstTask.getPath().getInstance(), result.getJSONObject("workflowInstance"));
checkWorkflowTaskDefinition(firstTask.getDefinition(), result.getJSONObject("definition"));
}
finally
{
if(startedWorkflowId != null)
{
try {
// Cleanup
workflowService.deleteWorkflow(startedWorkflowId);
}
catch(Throwable t)
{
// Ignore exception while cleaning up
}
}
}
}
private void checkWorkflowTaskPropertiesPresent(JSONObject taskJson) throws Exception
@@ -604,10 +559,6 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
}
public void testTaskInstancePut() throws Exception
{
String startedWorkflowId = null;
try
{
// Start workflow as USER1 and assign task to USER2.
personManager.setUser(USER1);
@@ -619,7 +570,9 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
startedWorkflowId = adhocPath.getInstance().getId();
String worfklowId = adhocPath.getInstance().getId();
workflows.add(worfklowId);
WorkflowTask startTask = workflowService.getStartTask(adhocPath.getInstance().getId());
// Finish the start-task
@@ -697,26 +650,8 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
editedJsonProperties = result.getJSONObject("properties");
compareProperties(jsonProperties, editedJsonProperties);
}
finally
{
if(startedWorkflowId != null)
{
try {
// Cleanup
workflowService.deleteWorkflow(startedWorkflowId);
}
catch(Throwable t)
{
// Ignore exception while cleaning up
}
}
}
}
public void testTaskInstancePutCompletedTask() throws Exception
{
String startedWorkflowId = null;
try
{
// Start workflow as USER1 and assign to self
personManager.setUser(USER1);
@@ -728,7 +663,9 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
startedWorkflowId = adhocPath.getInstance().getId();
String WorkflowId = adhocPath.getInstance().getId();
workflows.add(WorkflowId);
WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
// Finish the start-task
@@ -742,23 +679,7 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
jsonProperties.put(qnameToString(WorkflowModel.PROP_DESCRIPTION), "Edited description");
// Update task. An error is expected, since the task is completed (and not editable)
sendRequest(new PutRequest(URL_TASKS + "/" + startTask.getId(), jsonProperties.toString(), "application/json"),
Status.STATUS_UNAUTHORIZED);
}
finally
{
if(startedWorkflowId != null)
{
try {
// Cleanup
workflowService.deleteWorkflow(startedWorkflowId);
}
catch(Throwable t)
{
// Ignore exception while cleaning up
}
}
}
sendRequest(new PutRequest(URL_TASKS + "/" + startTask.getId(), jsonProperties.toString(), "application/json"), Status.STATUS_UNAUTHORIZED);
}
public void testWorkflowDefinitionsGet() throws Exception
@@ -928,10 +849,6 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
public void testWorkflowInstanceGet() throws Exception
{
String startedWorkflowId = null;
try
{
//Start workflow as USER1 and assign task to USER2.
personManager.setUser(USER1);
@@ -945,7 +862,10 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
params.put(WorkflowModel.PROP_CONTEXT, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
startedWorkflowId = adhocPath.getInstance().getId();
String WorkflowId = adhocPath.getInstance().getId();
workflows.add(WorkflowId);
// End start task.
WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
startTask = workflowService.endTask(startTask.getId(), null);
@@ -994,26 +914,8 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
JSONArray tasks = result.getJSONArray("tasks");
assertTrue(tasks.length() > 1);
}
finally
{
if(startedWorkflowId != null)
{
try {
// Cleanup
workflowService.deleteWorkflow(startedWorkflowId);
}
catch(Throwable t)
{
// Ignore exception while cleaning up
}
}
}
}
public void testWorkflowInstancesGet() throws Exception
{
String startedWorkflowId = null;
try
{
//Start workflow as USER1 and assign task to USER2.
personManager.setUser(USER1);
@@ -1027,7 +929,9 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
params.put(WorkflowModel.PROP_CONTEXT, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
startedWorkflowId = adhocPath.getInstance().getId();
String WorkflowId = adhocPath.getInstance().getId();
workflows.add(WorkflowId);
WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
WorkflowInstance adhocInstance = startTask.getPath().getInstance();
workflowService.endTask(startTask.getId(), null);
@@ -1131,22 +1035,6 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
}
}
assertFalse("Found adhoc workflows when they were supposed to be excluded", adhocWorkflowPresent);
}
finally
{
if(startedWorkflowId != null)
{
try {
// Cleanup
workflowService.deleteWorkflow(startedWorkflowId);
}
catch(Throwable t)
{
// Ignore exception while cleaning up
}
}
}
}
public void testWorkflowInstancesForNodeGet() throws Exception
@@ -1263,9 +1151,6 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
}
protected void runReviewFlow(boolean approve) throws Exception
{
String startedWorkflowId = null;
try
{
// Start workflow as USER1
personManager.setUser(USER1);
@@ -1280,7 +1165,9 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
params.put(WorkflowModel.PROP_CONTEXT, packageRef);
WorkflowPath reviewPath = workflowService.startWorkflow(reviewDef.getId(), params);
startedWorkflowId = reviewPath.getInstance().getId();
String workflowId = reviewPath.getInstance().getId();
workflows.add(workflowId);
WorkflowTask startTask = workflowService.getTasksForWorkflowPath(reviewPath.getId()).get(0);
// End start task
@@ -1328,27 +1215,10 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
{
assertEquals("wf:rejectedTask", taskType);
}
}
finally
{
if(startedWorkflowId != null)
{
try {
// Cleanup
workflowService.deleteWorkflow(startedWorkflowId);
}
catch(Throwable t)
{
// Ignore exception while cleaning up
}
}
}
workflowService.cancelWorkflow(workflowId);
}
protected void runReviewPooledFlow(boolean approve) throws Exception
{
String startedWorkflowId = null;
try
{
// Start workflow as USER1
personManager.setUser(USER1);
@@ -1364,14 +1234,16 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
params.put(WorkflowModel.PROP_CONTEXT, packageRef);
WorkflowPath reviewPath = workflowService.startWorkflow(reviewDef.getId(), params);
startedWorkflowId = reviewPath.getInstance().getId();
String workflowId = reviewPath.getInstance().getId();
workflows.add(workflowId);
WorkflowTask startTask = workflowService.getTasksForWorkflowPath(reviewPath.getId()).get(0);
// End start task
startTask = workflowService.endTask(startTask.getId(), null);
// Check if task is NOT available in list USER3, not a member of the group
// Check if task is NOT available in list USER3, not a member of the
// group
personManager.setUser(USER3);
Response response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER3)), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
@@ -1381,7 +1253,8 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
assertNotNull(results);
assertEquals(0, results.length());
// Check if task is available in list of reviewer, member of GROUP: USER2
// Check if task is available in list of reviewer, member of GROUP:
// USER2
personManager.setUser(USER2);
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
@@ -1415,7 +1288,6 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
assertFalse(taskJson.getBoolean("isClaimable"));
assertTrue(taskJson.getBoolean("isPooled"));
// Delegate approval/rejection to implementing engine-test
if (approve)
{
@@ -1446,22 +1318,7 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
{
assertEquals("wf:rejectedTask", taskType);
}
}
finally
{
if(startedWorkflowId != null)
{
try {
// Cleanup
workflowService.deleteWorkflow(startedWorkflowId);
}
catch(Throwable t)
{
// Ignore exception while cleaning up
}
}
}
workflowService.cancelWorkflow(workflowId);
}
protected abstract void approveTask(String taskId) throws Exception;
@@ -1519,6 +1376,17 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
{
super.tearDown();
authenticationComponent.setSystemUserAsCurrentUser();
for (String id: workflows)
{
try
{
workflowService.cancelWorkflow(id);
}
catch(Throwable t)
{
// Do nothing
}
}
groupManager.clearGroups();
personManager.clearPeople();
authenticationComponent.clearCurrentSecurityContext();