use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testDeleteProcessVariable.
@Test
public void testDeleteProcessVariable() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInfo processRest = startAdhocProcess(requestContext, null);
try {
assertNotNull(processRest);
String processId = processRest.getId();
// Create a variable to be deleted
activitiProcessEngine.getRuntimeService().setVariable(processId, "deleteMe", "This is a string");
// Delete variable
publicApiClient.processesClient().deleteVariable(processId, "deleteMe");
assertFalse(activitiProcessEngine.getRuntimeService().hasVariable(processId, "deleteMe"));
// Deleting again should fail with 404, as variable doesn't exist anymore
try {
publicApiClient.processesClient().deleteVariable(processId, "deleteMe");
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: deleteMe was not found", expected.getHttpResponse());
}
} finally {
cleanupProcessInstance(processRest.getId());
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessActivities.
@Test
public void testGetProcessActivities() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
final 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);
final ProcessInfo process1 = startAdhocProcess(requestContext, null);
try {
ProcessesClient processesClient = publicApiClient.processesClient();
Map<String, String> paramMap = new HashMap<String, String>();
JSONObject activitiesJSON = processesClient.getActivities(process1.getId(), paramMap);
assertNotNull(activitiesJSON);
JSONArray entriesJSON = (JSONArray) activitiesJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 2);
Map<String, JSONObject> activitiesMap = new HashMap<String, JSONObject>();
for (Object entry : entriesJSON) {
JSONObject jsonEntry = (JSONObject) entry;
JSONObject activityJSONObject = (JSONObject) jsonEntry.get("entry");
activitiesMap.put((String) activityJSONObject.get("activityDefinitionId"), activityJSONObject);
}
JSONObject activityJSONObject = activitiesMap.get("start");
assertNotNull(activityJSONObject);
assertNotNull(activityJSONObject.get("id"));
assertEquals("start", activityJSONObject.get("activityDefinitionId"));
assertNull(activityJSONObject.get("activityDefinitionName"));
assertEquals("startEvent", activityJSONObject.get("activityDefinitionType"));
assertNotNull(activityJSONObject.get("startedAt"));
assertNotNull(activityJSONObject.get("endedAt"));
assertNotNull(activityJSONObject.get("durationInMs"));
activityJSONObject = activitiesMap.get("adhocTask");
assertNotNull(activityJSONObject);
assertNotNull(activityJSONObject.get("id"));
assertEquals("adhocTask", activityJSONObject.get("activityDefinitionId"));
assertEquals("Adhoc Task", activityJSONObject.get("activityDefinitionName"));
assertEquals("userTask", activityJSONObject.get("activityDefinitionType"));
assertNotNull(activityJSONObject.get("startedAt"));
assertNull(activityJSONObject.get("endedAt"));
assertNull(activityJSONObject.get("durationInMs"));
paramMap = new HashMap<String, String>();
paramMap.put("status", "active");
activitiesJSON = processesClient.getActivities(process1.getId(), paramMap);
assertNotNull(activitiesJSON);
entriesJSON = (JSONArray) activitiesJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 1);
paramMap = new HashMap<String, String>();
paramMap.put("status", "completed");
activitiesJSON = processesClient.getActivities(process1.getId(), paramMap);
assertNotNull(activitiesJSON);
entriesJSON = (JSONArray) activitiesJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 1);
paramMap = new HashMap<String, String>();
try {
processesClient.getActivities("fakeid", paramMap);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: fakeid was not found", expected.getHttpResponse());
}
// get activities with admin from the same tenant as the process initiator
publicApiClient.setRequestContext(adminContext);
paramMap = new HashMap<String, String>();
activitiesJSON = processesClient.getActivities(process1.getId(), paramMap);
assertNotNull(activitiesJSON);
entriesJSON = (JSONArray) activitiesJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 2);
// get tasks with admin from another tenant as the process initiator
publicApiClient.setRequestContext(otherContext);
paramMap = new HashMap<String, String>();
try {
processesClient.getActivities(process1.getId(), paramMap);
fail("forbidden expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(process1.getId());
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testCreateProcessInstanceWithNoParams.
@Test
public void testCreateProcessInstanceWithNoParams() throws Exception {
initApiClientWithTestUser();
ProcessesClient processesClient = publicApiClient.processesClient();
JSONObject createProcessObject = new JSONObject();
try {
processesClient.createProcess(createProcessObject.toJSONString());
fail("Exception excpected");
} catch (PublicApiException e) {
assertEquals(400, e.getHttpResponse().getStatusCode());
}
}
Aggregations