use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.
the class TaskResourceTest method testResolveTask.
/**
* Test resolving a single task and all exceptional cases related to resolution.
* POST runtime/tasks/{taskId}
*/
public void testResolveTask() throws Exception {
try {
Task task = taskService.newTask();
task.setAssignee("initialAssignee");
taskService.saveTask(task);
taskService.delegateTask(task.getId(), "anotherUser");
String taskId = task.getId();
// Resolve the task and check result
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "resolve");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId));
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
task = taskService.createTaskQuery().taskId(taskId).singleResult();
assertNotNull(task);
assertEquals("initialAssignee", task.getAssignee());
assertEquals("initialAssignee", task.getOwner());
assertEquals(DelegationState.RESOLVED, task.getDelegationState());
// Resolving again shouldn't cause an exception
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
task = taskService.createTaskQuery().taskId(taskId).singleResult();
assertNotNull(task);
assertEquals("initialAssignee", task.getAssignee());
assertEquals("initialAssignee", task.getOwner());
assertEquals(DelegationState.RESOLVED, task.getDelegationState());
} finally {
// Clean adhoc-tasks even if test fails
List<Task> tasks = taskService.createTaskQuery().list();
for (Task task : tasks) {
taskService.deleteTask(task.getId(), true);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.
the class TaskResourceTest method testClaimTask.
/**
* Test claiming a single task and all exceptional cases related to claiming.
* POST runtime/tasks/{taskId}
*/
public void testClaimTask() throws Exception {
try {
Task task = taskService.newTask();
taskService.saveTask(task);
taskService.addCandidateUser(task.getId(), "newAssignee");
assertEquals(1L, taskService.createTaskQuery().taskCandidateUser("newAssignee").count());
// Add candidate group
String taskId = task.getId();
task.setAssignee("fred");
// Claiming without assignee should set asisgnee to null
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "claim");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId));
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
task = taskService.createTaskQuery().taskId(taskId).singleResult();
assertNotNull(task);
assertNull(task.getAssignee());
assertEquals(1L, taskService.createTaskQuery().taskCandidateUser("newAssignee").count());
// Claim the task and check result
requestNode.put("assignee", "newAssignee");
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
task = taskService.createTaskQuery().taskId(taskId).singleResult();
assertNotNull(task);
assertEquals("newAssignee", task.getAssignee());
assertEquals(0L, taskService.createTaskQuery().taskCandidateUser("newAssignee").count());
// Claiming with the same user shouldn't cause an exception
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
task = taskService.createTaskQuery().taskId(taskId).singleResult();
assertNotNull(task);
assertEquals("newAssignee", task.getAssignee());
assertEquals(0L, taskService.createTaskQuery().taskCandidateUser("newAssignee").count());
// Claiming with another user should cause exception
requestNode.put("assignee", "anotherUser");
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_CONFLICT));
} finally {
// Clean adhoc-tasks even if test fails
List<Task> tasks = taskService.createTaskQuery().list();
for (Task task : tasks) {
taskService.deleteTask(task.getId(), true);
}
// Clean historic tasks with no runtime-counterpart
List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery().list();
for (HistoricTaskInstance task : historicTasks) {
historyService.deleteHistoricTaskInstance(task.getId());
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.
the class TaskResourceTest method testInvalidTaskAction.
/**
* Test executing an invalid action on a single task.
* POST runtime/tasks/{taskId}
*/
public void testInvalidTaskAction() throws Exception {
try {
Task task = taskService.newTask();
taskService.saveTask(task);
String taskId = task.getId();
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "unexistingaction");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId));
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
} finally {
// Clean adhoc-tasks even if test fails
List<Task> tasks = taskService.createTaskQuery().list();
for (Task task : tasks) {
taskService.deleteTask(task.getId(), true);
}
// Clean historic tasks with no runtime-counterpart
List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery().list();
for (HistoricTaskInstance task : historicTasks) {
historyService.deleteHistoricTaskInstance(task.getId());
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.
the class ProcessDefinitionResourceTest method testSuspendProcessDefinition.
/**
* Test suspending a process definition.
* POST repository/process-definitions/{processDefinitionId}
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testSuspendProcessDefinition() throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
assertFalse(processDefinition.isSuspended());
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "suspend");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
// Check "OK" status
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertTrue(responseNode.get("suspended").booleanValue());
// Check if process-definitoin is suspended
processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
assertTrue(processDefinition.isSuspended());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.
the class ProcessDefinitionResourceTest method testActivateProcessDefinition.
/**
* Test activating a suspended process definition.
* POST repository/process-definitions/{processDefinitionId}
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testActivateProcessDefinition() throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
repositoryService.suspendProcessDefinitionById(processDefinition.getId());
processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
assertTrue(processDefinition.isSuspended());
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "activate");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
// Check "OK" status
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertFalse(responseNode.get("suspended").booleanValue());
// Check if process-definitoin is suspended
processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
assertFalse(processDefinition.isSuspended());
}
Aggregations