use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class ProcessInstanceResourceTest method testSuspendProcessInstance.
/**
* Test suspending a single process instance.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testSuspendProcessInstance() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "suspend");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
// Check engine id instance is suspended
assertEquals(1, runtimeService.createProcessInstanceQuery().suspended().processInstanceId(processInstance.getId()).count());
// Check resulting instance is suspended
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals(processInstance.getId(), responseNode.get("id").textValue());
assertTrue(responseNode.get("suspended").booleanValue());
// Suspending again should result in conflict
httpPut.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_CONFLICT));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class ProcessInstanceResourceTest method testActivateProcessInstance.
/**
* Test suspending a single process instance.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testActivateProcessInstance() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
runtimeService.suspendProcessInstanceById(processInstance.getId());
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "activate");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
// Check engine id instance is suspended
assertEquals(1, runtimeService.createProcessInstanceQuery().active().processInstanceId(processInstance.getId()).count());
// Check resulting instance is suspended
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals(processInstance.getId(), responseNode.get("id").textValue());
assertFalse(responseNode.get("suspended").booleanValue());
// Activating again should result in conflict
httpPut.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_CONFLICT));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class TaskAttachmentResourceTest method testCreateAttachment.
/**
* Test creating a single attachments for a task
* POST runtime/tasks/{taskId}/attachments/{attachmentId}
*/
public void testCreateAttachment() throws Exception {
try {
Task task = taskService.newTask();
taskService.saveTask(task);
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("name", "Simple attachment");
requestNode.put("description", "Simple attachment description");
requestNode.put("type", "simpleType");
requestNode.put("externalUrl", "http://activiti.org");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_COLLECTION, task.getId()));
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
// Check if attachment is created
List<Attachment> attachments = taskService.getTaskAttachments(task.getId());
assertEquals(1, attachments.size());
Attachment urlAttachment = attachments.get(0);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertEquals(urlAttachment.getId(), responseNode.get("id").textValue());
assertEquals("simpleType", responseNode.get("type").textValue());
assertEquals("Simple attachment", responseNode.get("name").textValue());
assertEquals("Simple attachment description", responseNode.get("description").textValue());
assertEquals("http://activiti.org", responseNode.get("externalUrl").textValue());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), urlAttachment.getId())));
assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));
assertTrue(responseNode.get("contentUrl").isNull());
assertTrue(responseNode.get("processInstanceUrl").isNull());
assertFalse(responseNode.get("time").isNull());
} 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.JsonNode in project Activiti by Activiti.
the class TaskCollectionResourceTest method testCreateTask.
/**
* Test creating a task.
* POST runtime/tasks
*/
public void testCreateTask() throws Exception {
try {
Task parentTask = taskService.newTask();
taskService.saveTask(parentTask);
ObjectNode requestNode = objectMapper.createObjectNode();
Calendar dueDate = Calendar.getInstance();
String dueDateString = getISODateString(dueDate.getTime());
requestNode.put("name", "New task name");
requestNode.put("description", "New task description");
requestNode.put("assignee", "assignee");
requestNode.put("owner", "owner");
requestNode.put("priority", 20);
requestNode.put("delegationState", "resolved");
requestNode.put("dueDate", dueDateString);
requestNode.put("parentTaskId", parentTask.getId());
requestNode.put("formKey", "testKey");
requestNode.put("tenantId", "test");
// Execute the request
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION));
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
String createdTaskId = responseNode.get("id").asText();
// Check if task is created with right arguments
Task task = taskService.createTaskQuery().taskId(createdTaskId).singleResult();
assertEquals("New task name", task.getName());
assertEquals("New task description", task.getDescription());
assertEquals("assignee", task.getAssignee());
assertEquals("owner", task.getOwner());
assertEquals(20, task.getPriority());
assertEquals(DelegationState.RESOLVED, task.getDelegationState());
assertEquals(dateFormat.parse(dueDateString), task.getDueDate());
assertEquals(parentTask.getId(), task.getParentTaskId());
assertEquals("testKey", task.getFormKey());
assertEquals("test", task.getTenantId());
} 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.JsonNode in project Activiti by Activiti.
the class TaskCommentResourceTest method testGetComment.
/**
* Test getting a comment for a task.
* GET runtime/tasks/{taskId}/comments/{commentId}
*/
public void testGetComment() throws Exception {
try {
Task task = taskService.newTask();
taskService.saveTask(task);
// Add a comment as "kermit"
identityService.setAuthenticatedUserId("kermit");
Comment comment = taskService.addComment(task.getId(), null, "This is a comment...");
identityService.setAuthenticatedUserId(null);
HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), comment.getId()));
CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("kermit", responseNode.get("author").textValue());
assertEquals("This is a comment...", responseNode.get("message").textValue());
assertEquals(comment.getId(), responseNode.get("id").textValue());
assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), comment.getId())));
assertEquals(task.getId(), responseNode.get("taskId").asText());
assertTrue(responseNode.get("processInstanceUrl").isNull());
assertTrue(responseNode.get("processInstanceId").isNull());
// Test with unexisting task
httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, "unexistingtask", "123"));
closeResponse(executeRequest(httpGet, HttpStatus.SC_NOT_FOUND));
// Test with unexisting comment
httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), "unexistingcomment"));
closeResponse(executeRequest(httpGet, HttpStatus.SC_NOT_FOUND));
} finally {
// Clean adhoc-tasks even if test fails
List<Task> tasks = taskService.createTaskQuery().list();
for (Task task : tasks) {
taskService.deleteTask(task.getId(), true);
}
}
}
Aggregations