use of org.activiti.engine.task.Event in project Activiti by Activiti.
the class TaskEventResourceTest method testGetEvent.
/**
* Test getting a single event for a task.
* GET runtime/tasks/{taskId}/events/{eventId}
*/
public void testGetEvent() throws Exception {
try {
Calendar now = Calendar.getInstance();
now.set(Calendar.MILLISECOND, 0);
processEngineConfiguration.getClock().setCurrentTime(now.getTime());
Task task = taskService.newTask();
taskService.saveTask(task);
taskService.addUserIdentityLink(task.getId(), "gonzo", "someType");
Event event = taskService.getTaskEvents(task.getId()).get(0);
HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_EVENT, task.getId(), event.getId()));
CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals(event.getId(), responseNode.get("id").textValue());
assertEquals(event.getAction(), responseNode.get("action").textValue());
assertEquals(event.getUserId(), responseNode.get("userId").textValue());
assertTrue(responseNode.get("url").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_EVENT, task.getId(), event.getId())));
assertTrue(responseNode.get("taskUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));
assertEquals(now.getTime(), getDateFromISOString(responseNode.get("time").textValue()));
} 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.activiti.engine.task.Event in project Activiti by Activiti.
the class TaskIdentityLinksTest method testCandidateGroupLink.
@Deployment(resources = "org/activiti/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testCandidateGroupLink() {
runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
String taskId = taskService.createTaskQuery().singleResult().getId();
taskService.addCandidateGroup(taskId, "muppets");
List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
IdentityLink identityLink = identityLinks.get(0);
assertEquals("muppets", identityLink.getGroupId());
assertNull("kermit", identityLink.getUserId());
assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
assertEquals(taskId, identityLink.getTaskId());
assertEquals(1, identityLinks.size());
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
List<Event> taskEvents = taskService.getTaskEvents(taskId);
assertEquals(1, taskEvents.size());
Event taskEvent = taskEvents.get(0);
assertEquals(Event.ACTION_ADD_GROUP_LINK, taskEvent.getAction());
List<String> taskEventMessageParts = taskEvent.getMessageParts();
assertEquals("muppets", taskEventMessageParts.get(0));
assertEquals(IdentityLinkType.CANDIDATE, taskEventMessageParts.get(1));
assertEquals(2, taskEventMessageParts.size());
}
taskService.deleteCandidateGroup(taskId, "muppets");
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
List<Event> taskEvents = taskService.getTaskEvents(taskId);
Event taskEvent = findTaskEvent(taskEvents, Event.ACTION_DELETE_GROUP_LINK);
assertEquals(Event.ACTION_DELETE_GROUP_LINK, taskEvent.getAction());
List<String> taskEventMessageParts = taskEvent.getMessageParts();
assertEquals("muppets", taskEventMessageParts.get(0));
assertEquals(IdentityLinkType.CANDIDATE, taskEventMessageParts.get(1));
assertEquals(2, taskEventMessageParts.size());
assertEquals(2, taskEvents.size());
}
assertEquals(0, taskService.getIdentityLinksForTask(taskId).size());
}
use of org.activiti.engine.task.Event in project Activiti by Activiti.
the class TaskServiceTest method testCustomTaskComments.
public void testCustomTaskComments() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
Task task = taskService.newTask();
task.setOwner("johndoe");
taskService.saveTask(task);
String taskId = task.getId();
identityService.setAuthenticatedUserId("johndoe");
String customType1 = "Type1";
String customType2 = "Type2";
Comment comment = taskService.addComment(taskId, null, "This is a regular comment");
Comment customComment1 = taskService.addComment(taskId, null, customType1, "This is a custom comment of type Type1");
Comment customComment2 = taskService.addComment(taskId, null, customType1, "This is another Type1 comment");
Comment customComment3 = taskService.addComment(taskId, null, customType2, "This is another custom comment. Type2 this time!");
assertEquals(CommentEntity.TYPE_COMMENT, comment.getType());
assertEquals(customType1, customComment1.getType());
assertEquals(customType2, customComment3.getType());
assertNotNull(taskService.getComment(comment.getId()));
assertNotNull(taskService.getComment(customComment1.getId()));
List<Comment> regularComments = taskService.getTaskComments(taskId);
assertEquals(1, regularComments.size());
assertEquals("This is a regular comment", regularComments.get(0).getFullMessage());
List<Event> allComments = taskService.getTaskEvents(taskId);
assertEquals(4, allComments.size());
List<Comment> type2Comments = taskService.getCommentsByType(customType2);
assertEquals(1, type2Comments.size());
assertEquals("This is another custom comment. Type2 this time!", type2Comments.get(0).getFullMessage());
List<Comment> taskTypeComments = taskService.getTaskComments(taskId, customType1);
assertEquals(2, taskTypeComments.size());
// Clean up
taskService.deleteTask(taskId, true);
}
}
Aggregations