use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testUpdateTaskInvalidProperty.
@Test
public void testUpdateTaskInvalidProperty() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInstance processInstance = startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
TasksClient tasksClient = publicApiClient.tasksClient();
// Try updating an unexisting property
try {
JSONObject taskBody = new JSONObject();
List<String> selectedFields = new ArrayList<String>();
selectedFields.add("unexisting");
tasksClient.updateTask(task.getId(), taskBody, selectedFields);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The property selected for update does not exist for this resource: unexisting", expected.getHttpResponse());
}
// Try updating a readonly-property
try {
JSONObject taskBody = new JSONObject();
List<String> selectedFields = new ArrayList<String>();
selectedFields.add("id");
tasksClient.updateTask(task.getId(), taskBody, selectedFields);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The property selected for update is read-only: id", expected.getHttpResponse());
}
} finally {
cleanupProcessInstance(processInstance);
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testGetTasksAuthorization.
@Test
public void testGetTasksAuthorization() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String initiator = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId()).getId();
// Start process by one user and try to access the task as the task assignee instead of the process
// initiator to see if the assignee is authorized to get the task
ProcessInstance processInstance = startAdhocProcess(initiator, requestContext.getNetworkId(), null);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
TasksClient tasksClient = publicApiClient.tasksClient();
Map<String, String> params = new HashMap<String, String>();
params.put("processId", processInstance.getId());
JSONObject resultingTasks = tasksClient.findTasks(params);
assertNotNull(resultingTasks);
JSONArray jsonEntries = (JSONArray) resultingTasks.get("entries");
assertNotNull(jsonEntries);
assertEquals(0, jsonEntries.size());
// Set assignee, task should be in the result now
activitiProcessEngine.getTaskService().setAssignee(task.getId(), requestContext.getRunAsUser());
resultingTasks = tasksClient.findTasks(params);
assertNotNull(resultingTasks);
jsonEntries = (JSONArray) resultingTasks.get("entries");
assertNotNull(jsonEntries);
assertEquals(1, jsonEntries.size());
// Fetching task as admin should be possible
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
resultingTasks = tasksClient.findTasks(params);
assertNotNull(resultingTasks);
jsonEntries = (JSONArray) resultingTasks.get("entries");
assertNotNull(jsonEntries);
assertEquals(1, jsonEntries.size());
// Fetching the task as a admin from another tenant shouldn't be possible
TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
resultingTasks = tasksClient.findTasks(params);
assertNotNull(resultingTasks);
jsonEntries = (JSONArray) resultingTasks.get("entries");
assertNotNull(jsonEntries);
assertEquals(0, jsonEntries.size());
} finally {
cleanupProcessInstance(processInstance);
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testGetTaskVariablesRawVariableTypes.
@Test
public void testGetTaskVariablesRawVariableTypes() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInstance processInstance = startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
Calendar dateCal = Calendar.getInstance();
// Set all supported variables on the task to check the resulting types
Map<String, Object> variablesToSet = new HashMap<String, Object>();
variablesToSet.put("testVarString", "string");
variablesToSet.put("testVarInteger", 1234);
variablesToSet.put("testVarLong", 123456789L);
variablesToSet.put("testVarDouble", 1234.5678D);
variablesToSet.put("testVarFloat", 1234.0F);
variablesToSet.put("testVarBoolean", Boolean.TRUE);
variablesToSet.put("testVarDate", dateCal.getTime());
variablesToSet.put("testVarQName", ContentModel.TYPE_AUTHORITY);
variablesToSet.put("testVarNodeRef", new ActivitiScriptNode(new NodeRef("workspace:///testNode"), serviceRegistry));
variablesToSet.put("testVarRawNodeRef", new NodeRef("workspace:///testNode"));
activitiProcessEngine.getTaskService().setVariablesLocal(task.getId(), variablesToSet);
Map<String, Object> actualLocalVariables = activitiProcessEngine.getTaskService().getVariablesLocal(task.getId());
TasksClient tasksClient = publicApiClient.tasksClient();
// Get all local variables
JSONObject variables = tasksClient.findTaskVariables(task.getId(), Collections.singletonMap("where", "(scope = local)"));
assertNotNull(variables);
JSONObject list = (JSONObject) variables.get("list");
assertNotNull(list);
JSONArray entries = (JSONArray) list.get("entries");
assertNotNull(entries);
// Check pagination object for size
JSONObject pagination = (JSONObject) list.get("pagination");
assertNotNull(pagination);
assertEquals(actualLocalVariables.size(), ((Long) pagination.get("count")).intValue());
assertEquals(actualLocalVariables.size(), ((Long) pagination.get("totalItems")).intValue());
assertEquals(0L, pagination.get("skipCount"));
assertFalse((Boolean) pagination.get("hasMoreItems"));
assertEquals(actualLocalVariables.size(), entries.size());
// Add JSON entries to map for easy access when asserting values
Map<String, JSONObject> entriesByName = new HashMap<String, JSONObject>();
for (int i = 0; i < entries.size(); i++) {
JSONObject var = (JSONObject) entries.get(i);
entriesByName.put((String) ((JSONObject) var.get("entry")).get("name"), (JSONObject) var.get("entry"));
}
// Check all values and types
JSONObject var = entriesByName.get("testVarString");
assertNotNull(var);
assertEquals("d:text", var.get("type"));
assertEquals("string", var.get("value"));
var = entriesByName.get("testVarInteger");
assertNotNull(var);
assertEquals("d:int", var.get("type"));
assertEquals(1234L, var.get("value"));
var = entriesByName.get("testVarLong");
assertNotNull(var);
assertEquals("d:long", var.get("type"));
assertEquals(123456789L, var.get("value"));
var = entriesByName.get("testVarDouble");
assertNotNull(var);
assertEquals("d:double", var.get("type"));
assertEquals(1234.5678D, var.get("value"));
var = entriesByName.get("testVarFloat");
assertNotNull(var);
assertEquals("d:float", var.get("type"));
assertEquals(1234.0D, var.get("value"));
var = entriesByName.get("testVarBoolean");
assertNotNull(var);
assertEquals("d:boolean", var.get("type"));
assertEquals(Boolean.TRUE, var.get("value"));
var = entriesByName.get("testVarDate");
assertNotNull(var);
assertEquals("d:datetime", var.get("type"));
assertEquals(dateCal.getTime(), parseDate(var, "value"));
var = entriesByName.get("testVarQName");
assertNotNull(var);
assertEquals("d:qname", var.get("type"));
assertEquals("cm:authority", var.get("value"));
var = entriesByName.get("testVarRawNodeRef");
assertNotNull(var);
assertEquals("d:noderef", var.get("type"));
assertEquals("workspace:///testNode", var.get("value"));
var = entriesByName.get("testVarNodeRef");
assertNotNull(var);
assertEquals("d:noderef", var.get("type"));
assertEquals("workspace:///testNode", var.get("value"));
} finally {
cleanupProcessInstance(processInstance);
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testUpdateUnexistingTask.
@Test
@SuppressWarnings("unchecked")
public void testUpdateUnexistingTask() throws Exception {
initApiClientWithTestUser();
TasksClient tasksClient = publicApiClient.tasksClient();
try {
JSONObject taskBody = new JSONObject();
taskBody.put("name", "Updated name");
List<String> selectedFields = new ArrayList<String>();
selectedFields.addAll(Arrays.asList(new String[] { "name" }));
tasksClient.updateTask("unexisting", taskBody, selectedFields);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: unexisting was not found", expected.getHttpResponse());
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testGetTaskVariables.
@Test
public void testGetTaskVariables() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInstance processInstance = startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
Map<String, Object> actualLocalVariables = activitiProcessEngine.getTaskService().getVariablesLocal(task.getId());
Map<String, Object> actualGlobalVariables = activitiProcessEngine.getRuntimeService().getVariables(processInstance.getId());
assertEquals(5, actualGlobalVariables.size());
assertEquals(8, actualLocalVariables.size());
TasksClient tasksClient = publicApiClient.tasksClient();
JSONObject variables = tasksClient.findTaskVariables(task.getId());
assertNotNull(variables);
JSONObject list = (JSONObject) variables.get("list");
assertNotNull(list);
JSONArray entries = (JSONArray) list.get("entries");
assertNotNull(entries);
// Check pagination object for size
JSONObject pagination = (JSONObject) list.get("pagination");
assertNotNull(pagination);
assertEquals(12L, pagination.get("count"));
assertEquals(12L, pagination.get("totalItems"));
assertEquals(0L, pagination.get("skipCount"));
assertFalse((Boolean) pagination.get("hasMoreItems"));
// Should contain one variable less than the actual variables in the engine, tenant-domain var is filtered out
assertEquals(actualLocalVariables.size() + actualGlobalVariables.size() - 1, entries.size());
List<JSONObject> localResults = new ArrayList<JSONObject>();
List<JSONObject> globalResults = new ArrayList<JSONObject>();
Set<String> expectedLocalVars = new HashSet<String>();
expectedLocalVars.addAll(actualLocalVariables.keySet());
Set<String> expectedGlobalVars = new HashSet<String>();
expectedGlobalVars.addAll(actualGlobalVariables.keySet());
expectedGlobalVars.remove(ActivitiConstants.VAR_TENANT_DOMAIN);
// Add JSON entries to map for easy access when asserting values
Map<String, JSONObject> entriesByName = new HashMap<String, JSONObject>();
for (int i = 0; i < entries.size(); i++) {
JSONObject entry = (JSONObject) ((JSONObject) entries.get(i)).get("entry");
assertNotNull(entry);
// Check if full entry is present
assertNotNull(entry.get("scope"));
assertNotNull(entry.get("name"));
assertNotNull(entry.get("type"));
if (!entry.get("name").equals("bpm_hiddenTransitions")) {
assertNotNull(entry.get("value"));
}
if ("local".equals(entry.get("scope"))) {
localResults.add(entry);
expectedLocalVars.remove(entry.get("name"));
} else if ("global".equals(entry.get("scope"))) {
globalResults.add(entry);
expectedGlobalVars.remove(entry.get("name"));
}
entriesByName.put((String) entry.get("name"), entry);
}
// Check correct count of globas vs. local
assertEquals(4, globalResults.size());
assertEquals(8, localResults.size());
// Check if all variables are present
assertEquals(0, expectedGlobalVars.size());
assertEquals(0, expectedLocalVars.size());
// Check if types are returned, based on content-model
JSONObject var = entriesByName.get("bpm_percentComplete");
assertNotNull(var);
assertEquals("d:int", var.get("type"));
assertEquals(0L, var.get("value"));
var = entriesByName.get("bpm_reassignable");
assertNotNull(var);
assertEquals("d:boolean", var.get("type"));
assertEquals(Boolean.TRUE, var.get("value"));
var = entriesByName.get("bpm_status");
assertNotNull(var);
assertEquals("d:text", var.get("type"));
assertEquals("Not Yet Started", var.get("value"));
var = entriesByName.get("bpm_assignee");
assertNotNull(var);
assertEquals("cm:person", var.get("type"));
final String userName = requestContext.getRunAsUser();
assertEquals(userName, var.get("value"));
} finally {
cleanupProcessInstance(processInstance);
}
}
Aggregations