use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testUpdateTaskVariablesExceptions.
@Test
@SuppressWarnings("unchecked")
public void testUpdateTaskVariablesExceptions() 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);
// Update without name
JSONObject variableBody = new JSONObject();
variableBody.put("value", 1234);
variableBody.put("scope", "global");
TasksClient tasksClient = publicApiClient.tasksClient();
try {
tasksClient.updateTaskVariable(task.getId(), "newVariable", variableBody);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("Variable name is required.", expected.getHttpResponse());
}
// Update without scope
variableBody = new JSONObject();
variableBody.put("value", 1234);
variableBody.put("name", "newVariable");
try {
tasksClient.updateTaskVariable(task.getId(), "newVariable", variableBody);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("Variable scope is required and can only be 'local' or 'global'.", expected.getHttpResponse());
}
// Update in 'any' scope
variableBody = new JSONObject();
variableBody.put("value", 1234);
variableBody.put("name", "newVariable");
variableBody.put("scope", "any");
try {
tasksClient.updateTaskVariable(task.getId(), "newVariable", variableBody);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("Variable scope is required and can only be 'local' or 'global'.", expected.getHttpResponse());
}
// Update in illegal scope
variableBody = new JSONObject();
variableBody.put("value", 1234);
variableBody.put("name", "newVariable");
variableBody.put("scope", "illegal");
try {
tasksClient.updateTaskVariable(task.getId(), "newVariable", variableBody);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("Illegal value for variable scope: 'illegal'.", expected.getHttpResponse());
}
// Update using unsupported type
variableBody = new JSONObject();
variableBody.put("value", 1234);
variableBody.put("name", "newVariable");
variableBody.put("scope", "local");
variableBody.put("type", "d:unexisting");
try {
tasksClient.updateTaskVariable(task.getId(), "newVariable", variableBody);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("Unsupported type of variable: 'd:unexisting'.", expected.getHttpResponse());
}
// Update using unsupported type (invalid QName)
variableBody = new JSONObject();
variableBody.put("value", 1234);
variableBody.put("name", "newVariable");
variableBody.put("scope", "local");
variableBody.put("type", " 12unexisting");
try {
tasksClient.updateTaskVariable(task.getId(), "newVariable", variableBody);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("Unsupported type of variable: ' 12unexisting'.", expected.getHttpResponse());
}
} finally {
cleanupProcessInstance(processInstance);
}
}
Aggregations