use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testDeleteProcessItemWithAdmin.
@Test
public void testDeleteProcessItemWithAdmin() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
final RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
publicApiClient.setRequestContext(adminContext);
// start process with admin user
NodeRef[] docNodeRefs = createTestDocuments(adminContext);
final ProcessInfo processRest = startAdhocProcess(adminContext, docNodeRefs);
try {
assertNotNull(processRest);
final String newProcessInstanceId = processRest.getId();
ProcessesClient processesClient = publicApiClient.processesClient();
// Delete the item
processesClient.deleteProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
// Fetching the item should result in 404
try {
publicApiClient.processesClient().findProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: " + docNodeRefs[0].getId() + " was not found", expected.getHttpResponse());
}
} finally {
cleanupProcessInstance(processRest.getId());
}
// start process with default user and delete item with admin
publicApiClient.setRequestContext(requestContext);
docNodeRefs = createTestDocuments(requestContext);
final ProcessInfo processRestDefaultUser = startAdhocProcess(requestContext, docNodeRefs);
try {
assertNotNull(processRestDefaultUser);
publicApiClient.setRequestContext(adminContext);
final String newProcessInstanceId = processRestDefaultUser.getId();
ProcessesClient processesClient = publicApiClient.processesClient();
// Delete the item
processesClient.deleteProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
// Fetching the item should result in 404
try {
publicApiClient.processesClient().findProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: " + docNodeRefs[0].getId() + " was not found", expected.getHttpResponse());
}
} finally {
cleanupProcessInstance(processRestDefaultUser.getId());
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testDeleteProcessItem.
@Test
public void testDeleteProcessItem() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
try {
assertNotNull(processRest);
final String newProcessInstanceId = processRest.getId();
ProcessesClient processesClient = publicApiClient.processesClient();
// Delete the item
processesClient.deleteProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
// Fetching the item should result in 404
try {
publicApiClient.processesClient().findProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: " + docNodeRefs[0].getId() + " was not found", expected.getHttpResponse());
}
// Deleting the item again should give an error
try {
processesClient.deleteProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
fail("Expected not found");
} catch (PublicApiException e) {
assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(processRest.getId());
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testAddProcessItem.
@Test
@SuppressWarnings("unchecked")
public void testAddProcessItem() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
final ProcessInfo processRest = startAdhocProcess(requestContext, null);
try {
assertNotNull(processRest);
final String newProcessInstanceId = processRest.getId();
ProcessesClient processesClient = publicApiClient.processesClient();
JSONObject createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
// Add the item
processesClient.addProcessItem(newProcessInstanceId, createItemObject.toJSONString());
// Fetching the item
JSONObject itemJSON = publicApiClient.processesClient().findProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
assertEquals("Test Doc1", itemJSON.get("name"));
assertEquals("Test Doc1 Title", itemJSON.get("title"));
assertEquals("Test Doc1 Description", itemJSON.get("description"));
assertNotNull(itemJSON.get("createdAt"));
assertEquals(requestContext.getRunAsUser(), itemJSON.get("createdBy"));
assertNotNull(itemJSON.get("modifiedAt"));
assertEquals(requestContext.getRunAsUser(), itemJSON.get("modifiedBy"));
assertNotNull(itemJSON.get("size"));
assertNotNull(itemJSON.get("mimeType"));
// add non existing item
createItemObject = new JSONObject();
createItemObject.put("id", "blablabla");
// Add the item
try {
processesClient.addProcessItem(newProcessInstanceId, createItemObject.toJSONString());
fail("not found expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(processRest.getId());
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testUpdateProcessVariables.
@SuppressWarnings("unchecked")
@Test
public void testUpdateProcessVariables() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
ProcessInfo processRest = startAdhocProcess(requestContext, null);
try {
assertNotNull(processRest);
String processId = processRest.getId();
// Update an unexisting variable, creates a new one using explicit typing (d:long)
JSONObject variableJson = new JSONObject();
variableJson.put("name", "newVariable");
variableJson.put("value", 1234L);
variableJson.put("type", "d:long");
JSONObject resultEntry = publicApiClient.processesClient().updateVariable(processId, "newVariable", variableJson);
assertNotNull(resultEntry);
JSONObject result = (JSONObject) resultEntry.get("entry");
assertEquals("newVariable", result.get("name"));
assertEquals(1234L, result.get("value"));
assertEquals("d:long", result.get("type"));
assertEquals(1234L, activitiProcessEngine.getRuntimeService().getVariable(processId, "newVariable"));
// Update an unexisting variable, creates a new one using no tying
variableJson = new JSONObject();
variableJson.put("name", "stringVariable");
variableJson.put("value", "This is a string value");
resultEntry = publicApiClient.processesClient().updateVariable(processId, "stringVariable", variableJson);
assertNotNull(resultEntry);
result = (JSONObject) resultEntry.get("entry");
assertEquals("stringVariable", result.get("name"));
assertEquals("This is a string value", result.get("value"));
assertEquals("d:text", result.get("type"));
assertEquals("This is a string value", activitiProcessEngine.getRuntimeService().getVariable(processId, "stringVariable"));
// Update an existing variable, creates a new one using explicit typing (d:long)
variableJson = new JSONObject();
variableJson.put("name", "newVariable");
variableJson.put("value", 4567L);
variableJson.put("type", "d:long");
resultEntry = publicApiClient.processesClient().updateVariable(processId, "newVariable", variableJson);
assertNotNull(resultEntry);
result = (JSONObject) resultEntry.get("entry");
assertEquals("newVariable", result.get("name"));
assertEquals(4567L, result.get("value"));
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");
variableJson.put("value", "Updated string variable");
resultEntry = publicApiClient.processesClient().updateVariable(processId, "stringVariable", variableJson);
assertNotNull(resultEntry);
result = (JSONObject) resultEntry.get("entry");
assertEquals("stringVariable", result.get("name"));
assertEquals("Updated string variable", result.get("value"));
assertEquals("d:text", result.get("type"));
assertEquals("Updated string variable", activitiProcessEngine.getRuntimeService().getVariable(processId, "stringVariable"));
// Update an unexisting variable with wrong variable data
variableJson = new JSONObject();
variableJson.put("name", "newLongVariable");
variableJson.put("value", "text");
variableJson.put("type", "d:long");
try {
publicApiClient.processesClient().updateVariable(processId, "newLongVariable", variableJson);
fail("Expected server error exception");
} catch (PublicApiException e) {
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
}
// Update an unexisting variable with no variable data
variableJson = new JSONObject();
variableJson.put("name", "newNoValueVariable");
variableJson.put("type", "d:datetime");
resultEntry = publicApiClient.processesClient().updateVariable(processId, "newNoValueVariable", variableJson);
assertNotNull(resultEntry);
result = (JSONObject) resultEntry.get("entry");
assertEquals("newNoValueVariable", result.get("name"));
assertNotNull(result.get("value"));
assertEquals("d:datetime", result.get("type"));
assertNotNull(activitiProcessEngine.getRuntimeService().getVariable(processId, "newNoValueVariable"));
// Test update variable with admin user
publicApiClient.setRequestContext(adminContext);
variableJson = new JSONObject();
variableJson.put("name", "newVariable");
variableJson.put("value", 1234L);
variableJson.put("type", "d:long");
resultEntry = publicApiClient.processesClient().updateVariable(processId, "newVariable", variableJson);
assertNotNull(resultEntry);
result = (JSONObject) resultEntry.get("entry");
assertEquals("newVariable", result.get("name"));
assertEquals(1234L, result.get("value"));
assertEquals("d:long", result.get("type"));
assertEquals(1234L, activitiProcessEngine.getRuntimeService().getVariable(processId, "newVariable"));
} finally {
cleanupProcessInstance(processRest.getId());
}
// test update variable with admin user that also started the process instance
processRest = startAdhocProcess(adminContext, null);
try {
assertNotNull(processRest);
String processId = processRest.getId();
// Update an unexisting variable, creates a new one using explicit typing (d:long)
JSONObject variableJson = new JSONObject();
variableJson.put("name", "newVariable");
variableJson.put("value", 1234L);
variableJson.put("type", "d:long");
JSONObject resultEntry = publicApiClient.processesClient().updateVariable(processId, "newVariable", variableJson);
assertNotNull(resultEntry);
JSONObject result = (JSONObject) resultEntry.get("entry");
assertEquals("newVariable", result.get("name"));
assertEquals(1234L, result.get("value"));
assertEquals("d:long", result.get("type"));
assertEquals(1234L, activitiProcessEngine.getRuntimeService().getVariable(processId, "newVariable"));
// test update variable with user not involved in the process instance
publicApiClient.setRequestContext(requestContext);
try {
publicApiClient.processesClient().updateVariable(processId, "newVariable", variableJson);
fail("Expected forbidden exception");
} catch (PublicApiException e) {
assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(processRest.getId());
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessInstances.
@Test
public void testGetProcessInstances() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
final ProcessInfo process1 = startAdhocProcess(requestContext, null);
final ProcessInfo process2 = startAdhocProcess(requestContext, null);
final ProcessInfo process3 = startAdhocProcess(requestContext, null);
try {
ProcessesClient processesClient = publicApiClient.processesClient();
Map<String, String> paramMap = new HashMap<String, String>();
ListResponse<ProcessInfo> processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
Map<String, ProcessInfo> processMap = new HashMap<String, ProcessInfo>();
for (ProcessInfo processRest : processList.getList()) {
processMap.put(processRest.getId(), processRest);
}
assertTrue(processMap.containsKey(process1.getId()));
assertTrue(processMap.containsKey(process2.getId()));
assertTrue(processMap.containsKey(process3.getId()));
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
assertNull(processList.getList().get(0).getProcessVariables());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc2')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(0, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
paramMap.put("maxItems", "2");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(2, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
paramMap.put("maxItems", "3");
paramMap.put("skipCount", "1");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(2, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
paramMap.put("maxItems", "5");
paramMap.put("skipCount", "2");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(1, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
paramMap.put("maxItems", "5");
paramMap.put("skipCount", "5");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(0, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(status = 'completed')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(0, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(status = 'any')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(status = 'active')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(status = 'active2')");
try {
processList = processesClient.getProcesses(paramMap);
fail();
} catch (PublicApiException e) {
// expected exception
}
// Test the variable where-clause
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority = 'd_int 1')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority = 'd:int 1')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority > 'd:int 1')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(0, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority >= 'd:int 1')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority < 'd:int 5')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority <= 'd:int 4')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority = 'd_int 5')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(0, processList.getList().size());
// test with date variable
Calendar dateCal = Calendar.getInstance();
Map<String, Object> variablesToSet = new HashMap<String, Object>();
variablesToSet.put("testVarDate", dateCal.getTime());
activitiProcessEngine.getRuntimeService().setVariables(process1.getId(), variablesToSet);
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/testVarDate = 'd_datetime " + ISO8601DateFormat.format(dateCal.getTime()) + "')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(1, processList.getList().size());
// include process variables as well
paramMap = new HashMap<String, String>();
paramMap.put("where", "(includeVariables=true)");
paramMap.put("maxItems", "1");
paramMap.put("skipCount", "0");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(1, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc' AND includeVariables = true)");
paramMap.put("maxItems", "1");
paramMap.put("skipCount", "0");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(1, processList.getList().size());
ProcessInfo processInfo = processList.getList().get(0);
assertNotNull(processInfo.getProcessVariables());
boolean foundDescription = false;
boolean foundAssignee = false;
for (Variable variable : processInfo.getProcessVariables()) {
if ("bpm_description".equals(variable.getName())) {
assertEquals("d:text", variable.getType());
assertNull(variable.getValue());
foundDescription = true;
} else if ("bpm_assignee".equals(variable.getName())) {
assertEquals("cm:person", variable.getType());
assertEquals(requestContext.getRunAsUser(), variable.getValue());
foundAssignee = true;
}
}
assertTrue(foundDescription);
assertTrue(foundAssignee);
// include process variables with paging
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc' AND includeVariables = true)");
paramMap.put("maxItems", "3");
paramMap.put("skipCount", "1");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(2, processList.getList().size());
processInfo = processList.getList().get(0);
assertNotNull(processInfo.getProcessVariables());
foundDescription = false;
foundAssignee = false;
for (Variable variable : processInfo.getProcessVariables()) {
if ("bpm_description".equals(variable.getName())) {
assertEquals("d:text", variable.getType());
assertNull(variable.getValue());
foundDescription = true;
} else if ("bpm_assignee".equals(variable.getName())) {
assertEquals("cm:person", variable.getType());
assertEquals(requestContext.getRunAsUser(), variable.getValue());
foundAssignee = true;
}
}
assertTrue(foundDescription);
assertTrue(foundAssignee);
// include process variables with paging outside boundaries
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc' AND includeVariables = true)");
paramMap.put("maxItems", "4");
paramMap.put("skipCount", "5");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(0, processList.getList().size());
} finally {
cleanupProcessInstance(process1.getId(), process2.getId(), process3.getId());
}
}
Aggregations