ALF-20190, ALF-20178 fixes for workflow rest api

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@56272 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tijs Rademakers
2013-10-02 17:42:33 +00:00
parent 3e148f0b29
commit a402cc75ed
12 changed files with 826 additions and 156 deletions

View File

@@ -38,6 +38,7 @@ import org.alfresco.rest.api.tests.client.PublicApiException;
import org.alfresco.rest.api.tests.client.RequestContext;
import org.alfresco.rest.workflow.api.model.Deployment;
import org.alfresco.rest.workflow.api.tests.WorkflowApiClient.DeploymentsClient;
import org.json.simple.JSONObject;
import org.junit.Test;
import org.springframework.http.HttpStatus;
@@ -120,6 +121,58 @@ public class DeploymentWorkflowApiTest extends EnterpriseWorkflowTestApi
assertEquals(activitiDeployment.getCategory(), adhocDeployment.getCategory());
assertEquals(activitiDeployment.getName(), adhocDeployment.getName());
assertEquals(activitiDeployment.getDeploymentTime(), adhocDeployment.getDeployedAt());
Map<String, String> params = new HashMap<String, String>();
params.put("maxItems", "2");
JSONObject deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
JSONObject paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(5l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "2");
params.put("maxItems", "2");
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "2");
params.put("maxItems", "5");
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(3l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "0");
params.put("maxItems", "7");
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(5l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
}
@Test

View File

@@ -88,6 +88,58 @@ public class ProcessDefinitionWorkflowApiTest extends EnterpriseWorkflowTestApi
assertEquals("wf:submitAdhocTask", adhocDefinitionRest.getStartFormResourceKey());
assertEquals("New Task", adhocDefinitionRest.getTitle());
assertEquals("Assign a new task to yourself or a colleague", adhocDefinitionRest.getDescription());
Map<String, String> params = new HashMap<String, String>();
params.put("maxItems", "2");
JSONObject definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
JSONObject paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(5l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "2");
params.put("maxItems", "2");
definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "2");
params.put("maxItems", "5");
definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(3l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "0");
params.put("maxItems", "7");
definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(5l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
}
@Test

View File

@@ -1749,6 +1749,25 @@ public class ProcessWorkflowApiTest extends EnterpriseWorkflowTestApi
assertEquals("d:long", result.get("type"));
assertEquals(4567L, activitiProcessEngine.getRuntimeService().getVariable(processId, "newVariable"));
JSONObject processvariables = publicApiClient.processesClient().getProcessvariables(processId);
assertNotNull(processvariables);
JSONObject newVariableEntry = null;
JSONArray entries = (JSONArray) processvariables.get("entries");
assertNotNull(entries);
for(int i=0; i<entries.size(); i++)
{
JSONObject entry = (JSONObject) entries.get(i);
assertNotNull(entry);
entry = (JSONObject) entry.get("entry");
assertNotNull(entry);
if ("newVariable".equals((String) entry.get("name"))) {
newVariableEntry = entry;
}
}
assertNotNull(newVariableEntry);
assertEquals(4567L, newVariableEntry.get("value"));
// Update an existing variable, creates a new one using no explicit typing
variableJson = new JSONObject();
variableJson.put("name", "stringVariable");
@@ -1856,6 +1875,187 @@ public class ProcessWorkflowApiTest extends EnterpriseWorkflowTestApi
}
}
@SuppressWarnings("unchecked")
@Test
public void testUpdateProcessVariableWithWrongType() throws Exception
{
final RequestContext requestContext = initApiClientWithTestUser();
ProcessInfo processRest = startParallelReviewProcess(requestContext);
try
{
assertNotNull(processRest);
String processId = processRest.getId();
// Update an existing variable with wrong type
JSONObject variableJson = new JSONObject();
variableJson.put("name", "wf_requiredApprovePercent");
variableJson.put("value", 55.99);
variableJson.put("type", "d:double");
try
{
publicApiClient.processesClient().updateVariable(processId, "wf_requiredApprovePercent", variableJson);
fail("Exception expected");
}
catch (PublicApiException e)
{
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
}
variableJson = new JSONObject();
variableJson.put("name", "wf_requiredApprovePercent");
variableJson.put("value", 55.99);
variableJson.put("type", "d:int");
JSONObject resultEntry = publicApiClient.processesClient().updateVariable(processId, "wf_requiredApprovePercent", variableJson);
assertNotNull(resultEntry);
JSONObject result = (JSONObject) resultEntry.get("entry");
assertEquals("wf_requiredApprovePercent", result.get("name"));
assertEquals(55l, result.get("value"));
assertEquals("d:int", result.get("type"));
assertEquals(55, activitiProcessEngine.getRuntimeService().getVariable(processId, "wf_requiredApprovePercent"));
JSONObject processvariables = publicApiClient.processesClient().getProcessvariables(processId);
assertNotNull(processvariables);
// Add process variables to map for easy lookup
Map<String, JSONObject> variablesByName = new HashMap<String, JSONObject>();
JSONObject entry = null;
JSONArray entries = (JSONArray) processvariables.get("entries");
assertNotNull(entries);
for(int i=0; i<entries.size(); i++)
{
entry = (JSONObject) entries.get(i);
assertNotNull(entry);
entry = (JSONObject) entry.get("entry");
assertNotNull(entry);
variablesByName.put((String) entry.get("name"), entry);
}
JSONObject approvePercentObject = variablesByName.get("wf_requiredApprovePercent");
assertNotNull(approvePercentObject);
assertEquals(55l, approvePercentObject.get("value"));
assertEquals("d:int", approvePercentObject.get("type"));
// set a new variable
variableJson = new JSONObject();
variableJson.put("name", "testVariable");
variableJson.put("value", "text");
variableJson.put("type", "d:text");
resultEntry = publicApiClient.processesClient().updateVariable(processId, "testVariable", variableJson);
assertNotNull(resultEntry);
result = (JSONObject) resultEntry.get("entry");
assertEquals("testVariable", result.get("name"));
assertEquals("text", result.get("value"));
assertEquals("d:text", result.get("type"));
assertEquals("text", activitiProcessEngine.getRuntimeService().getVariable(processId, "testVariable"));
// change the variable value and type (should be working because no content model type)
variableJson = new JSONObject();
variableJson.put("name", "testVariable");
variableJson.put("value", 123);
variableJson.put("type", "d:int");
resultEntry = publicApiClient.processesClient().updateVariable(processId, "testVariable", variableJson);
assertNotNull(resultEntry);
result = (JSONObject) resultEntry.get("entry");
assertEquals("testVariable", result.get("name"));
assertEquals(123l, result.get("value"));
assertEquals("d:int", result.get("type"));
assertEquals(123, activitiProcessEngine.getRuntimeService().getVariable(processId, "testVariable"));
// change the variable value for a list of noderefs (bpm_assignees)
final JSONObject updateAssigneesJson = new JSONObject();
updateAssigneesJson.put("name", "bpm_assignees");
updateAssigneesJson.put("type", "d:noderef");
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
JSONArray assigneeArray = new JSONArray();
assigneeArray.add(requestContext.getRunAsUser());
updateAssigneesJson.put("value", assigneeArray);
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
resultEntry = publicApiClient.processesClient().updateVariable(processId, "bpm_assignees", updateAssigneesJson);
assertNotNull(resultEntry);
final JSONObject updateAssigneeResult = (JSONObject) resultEntry.get("entry");
assertEquals("bpm_assignees", updateAssigneeResult.get("name"));
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
JSONArray assigneeArray = (JSONArray) updateAssigneeResult.get("value");
assertNotNull(assigneeArray);
assertEquals(1, assigneeArray.size());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
assertEquals("d:noderef", updateAssigneeResult.get("type"));
// update the bpm_assignees with a single entry, should result in an error
final JSONObject updateAssigneeJson = new JSONObject();
updateAssigneeJson.put("name", "bpm_assignees");
updateAssigneeJson.put("type", "d:noderef");
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
updateAssigneeJson.put("value", requestContext.getRunAsUser());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
try
{
publicApiClient.processesClient().updateVariable(processId, "bpm_assignees", updateAssigneeJson);
fail("Exception expected");
}
catch (PublicApiException e)
{
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
}
// change the variable value with a non-existing person
variableJson = new JSONObject();
variableJson.put("name", "bpm_assignees");
JSONArray assigneeArray = new JSONArray();
assigneeArray.add("nonExistingPerson");
variableJson.put("value", assigneeArray);
variableJson.put("type", "d:noderef");
try
{
publicApiClient.processesClient().updateVariable(processId, "bpm_assignees", variableJson);
fail("Exception expected");
}
catch (PublicApiException e)
{
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
}
}
finally
{
cleanupProcessInstance(processRest.getId());
}
}
@Test
public void testDeleteProcessVariable() throws Exception
{

View File

@@ -1106,7 +1106,7 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
JSONObject variableBody = new JSONObject();
variableBody.put("name", "bpm_workflowDueDate");
variableBody.put("value", formatDate(new Date()));
variableBody.put("type", "d:datetime");
variableBody.put("type", "d:date");
variableBody.put("scope", "global");
tasksClient.updateTaskVariable(task.getId(), "bpm_workflowDueDate", variableBody);
@@ -2397,6 +2397,179 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
}
}
@SuppressWarnings("unchecked")
@Test
public void testUpdateTaskVariableWithWrongType() throws Exception
{
final RequestContext requestContext = initApiClientWithTestUser();
ProcessInfo processRest = startParallelReviewProcess(requestContext);
try
{
List<Task> tasks = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processRest.getId()).list();
assertNotNull(tasks);
String taskId = tasks.get(0).getId();
// Update an existing variable with wrong type
JSONObject variableJson = new JSONObject();
variableJson.put("name", "wf_requiredApprovePercent");
variableJson.put("value", 55.99);
variableJson.put("type", "d:double");
variableJson.put("scope", "global");
try
{
publicApiClient.tasksClient().updateTaskVariable(taskId, "wf_requiredApprovePercent", variableJson);
fail("Exception expected");
}
catch (PublicApiException e)
{
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
}
variableJson = new JSONObject();
variableJson.put("name", "wf_requiredApprovePercent");
variableJson.put("value", 55.99);
variableJson.put("type", "d:int");
variableJson.put("scope", "global");
JSONObject resultEntry = publicApiClient.tasksClient().updateTaskVariable(taskId, "wf_requiredApprovePercent", variableJson);
assertNotNull(resultEntry);
JSONObject result = (JSONObject) resultEntry.get("entry");
assertEquals("wf_requiredApprovePercent", result.get("name"));
assertEquals(55l, result.get("value"));
assertEquals("d:int", result.get("type"));
assertEquals(55, activitiProcessEngine.getRuntimeService().getVariable(processRest.getId(), "wf_requiredApprovePercent"));
JSONObject taskVariables = publicApiClient.tasksClient().findTaskVariables(taskId);
assertNotNull(taskVariables);
JSONObject list = (JSONObject) taskVariables.get("list");
assertNotNull(list);
// Add process variables to map for easy lookup
Map<String, JSONObject> variablesByName = new HashMap<String, JSONObject>();
JSONObject entry = null;
JSONArray entries = (JSONArray) list.get("entries");
assertNotNull(entries);
for(int i=0; i<entries.size(); i++)
{
entry = (JSONObject) entries.get(i);
assertNotNull(entry);
entry = (JSONObject) entry.get("entry");
assertNotNull(entry);
variablesByName.put((String) entry.get("name"), entry);
}
JSONObject approvePercentObject = variablesByName.get("wf_requiredApprovePercent");
assertNotNull(approvePercentObject);
assertEquals(55l, approvePercentObject.get("value"));
assertEquals("d:int", approvePercentObject.get("type"));
// set a new variable
variableJson = new JSONObject();
variableJson.put("name", "testVariable");
variableJson.put("value", "text");
variableJson.put("type", "d:text");
variableJson.put("scope", "local");
resultEntry = publicApiClient.tasksClient().updateTaskVariable(taskId, "testVariable", variableJson);
assertNotNull(resultEntry);
result = (JSONObject) resultEntry.get("entry");
assertEquals("testVariable", result.get("name"));
assertEquals("text", result.get("value"));
assertEquals("d:text", result.get("type"));
assertEquals("text", activitiProcessEngine.getTaskService().getVariable(taskId, "testVariable"));
// change the variable value and type (should be working because no content model type)
variableJson = new JSONObject();
variableJson.put("name", "testVariable");
variableJson.put("value", 123);
variableJson.put("type", "d:int");
variableJson.put("scope", "local");
resultEntry = publicApiClient.tasksClient().updateTaskVariable(taskId, "testVariable", variableJson);
assertNotNull(resultEntry);
result = (JSONObject) resultEntry.get("entry");
assertEquals("testVariable", result.get("name"));
assertEquals(123l, result.get("value"));
assertEquals("d:int", result.get("type"));
assertEquals(123, activitiProcessEngine.getTaskService().getVariable(taskId, "testVariable"));
// change the variable value for a list of noderefs (bpm_assignees)
final JSONObject updateAssigneesJson = new JSONObject();
updateAssigneesJson.put("name", "bpm_assignees");
updateAssigneesJson.put("type", "d:noderef");
updateAssigneesJson.put("scope", "global");
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
JSONArray assigneeArray = new JSONArray();
assigneeArray.add(requestContext.getRunAsUser());
updateAssigneesJson.put("value", assigneeArray);
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
resultEntry = publicApiClient.tasksClient().updateTaskVariable(taskId, "bpm_assignees", updateAssigneesJson);
assertNotNull(resultEntry);
final JSONObject updateAssigneeResult = (JSONObject) resultEntry.get("entry");
assertEquals("bpm_assignees", updateAssigneeResult.get("name"));
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
JSONArray assigneeArray = (JSONArray) updateAssigneeResult.get("value");
assertNotNull(assigneeArray);
assertEquals(1, assigneeArray.size());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
assertEquals("d:noderef", updateAssigneeResult.get("type"));
// update the bpm_assignees with a single entry, should result in an error
final JSONObject updateAssigneeJson = new JSONObject();
updateAssigneeJson.put("name", "bpm_assignees");
updateAssigneeJson.put("type", "d:noderef");
updateAssigneeJson.put("scope", "global");
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
updateAssigneeJson.put("value", requestContext.getRunAsUser());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
try
{
publicApiClient.tasksClient().updateTaskVariable(taskId, "bpm_assignees", updateAssigneeJson);
fail("Exception expected");
}
catch (PublicApiException e)
{
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
}
}
finally
{
cleanupProcessInstance(processRest.getId());
}
}
@Test
@SuppressWarnings("unchecked")
public void testUpdateTaskVariablesAuthentication() throws Exception

View File

@@ -69,6 +69,13 @@ public class WorkflowApiClient extends PublicApiClient
HttpResponse response = getAll("deployments", null, null, null, params, "Failed to get deploymentsClient");
return DeploymentParser.INSTANCE.parseList(response.getJsonResponse());
}
public JSONObject getDeploymentsWithRawResponse(Map<String, String> params) throws PublicApiException
{
HttpResponse response = getAll("deployments", null, null, null, params, "Failed to get deploymentsClient");
JSONObject list = (JSONObject) response.getJsonResponse().get("list");
return list;
}
public ListResponse<Deployment> getDeployments() throws PublicApiException
{
@@ -106,6 +113,13 @@ public class WorkflowApiClient extends PublicApiClient
HttpResponse response = getAll("process-definitions", null, null, null, params, "Failed to get process definitions");
return ProcessDefinitionParser.INSTANCE.parseList(response.getJsonResponse());
}
public JSONObject getProcessDefinitionsWithRawResponse(Map<String, String> params) throws PublicApiException
{
HttpResponse response = getAll("process-definitions", null, null, null, params, "Failed to get process definitions");
JSONObject list = (JSONObject) response.getJsonResponse().get("list");
return list;
}
public ProcessDefinition findProcessDefinitionById(String processDefinitionId) throws PublicApiException
{