use of org.alfresco.rest.api.tests.client.PublicApiException 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.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testUpdateProcessVariableWithWrongType.
@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());
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessVariables.
@Test
public void testGetProcessVariables() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
final RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
ProcessInfo processRest = startAdhocProcess(requestContext, null);
try {
assertNotNull(processRest);
String processInstanceId = processRest.getId();
JSONObject processvariables = publicApiClient.processesClient().getProcessvariables(processInstanceId);
assertNotNull(processvariables);
validateVariablesResponse(processvariables, requestContext.getRunAsUser());
// get variables with admin from same network
publicApiClient.setRequestContext(adminContext);
processvariables = publicApiClient.processesClient().getProcessvariables(processInstanceId);
assertNotNull(processvariables);
validateVariablesResponse(processvariables, requestContext.getRunAsUser());
// get variables with admin from other network
publicApiClient.setRequestContext(otherContext);
try {
processvariables = publicApiClient.processesClient().getProcessvariables(processInstanceId);
fail("forbidden expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
}
// get variables with non existing process id
try {
processvariables = publicApiClient.processesClient().getProcessvariables("fakeid");
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.PublicApiException 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.PublicApiException 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());
}
}
Aggregations