Java Code Examples for org.activiti.engine.task.Task#setName()

The following examples show how to use org.activiti.engine.task.Task#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTaskResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public TaskRepresentation updateTask(String taskId, TaskUpdateRepresentation updated) {
  Task task = taskService.createTaskQuery().taskId(taskId).singleResult();

  if (task == null) {
    throw new NotFoundException("Task with id: " + taskId + " does not exist");
  }

  permissionService.validateReadPermissionOnTask(SecurityUtils.getCurrentUserObject(), task.getId());

  if (updated.isNameSet()) {
    task.setName(updated.getName());
  }

  if (updated.isDescriptionSet()) {
    task.setDescription(updated.getDescription());
  }

  if (updated.isDueDateSet()) {
    task.setDueDate(updated.getDueDate());
  }

  taskService.saveTask(task);

  return new TaskRepresentation(task);
}
 
Example 2
Source File: TaskAndVariablesQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Generates 100 test tasks.
 */
private List<String> generateMultipleTestTasks() throws Exception {
  List<String> ids = new ArrayList<String>();
  
  SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
  processEngineConfiguration.getClock().setCurrentTime(sdf.parse("01/01/2001 01:01:01.000"));
  for (int i = 0; i < 100; i++) {
    Task task = taskService.newTask();
    task.setName("testTask");
    task.setDescription("testTask description");
    task.setPriority(3);
    taskService.saveTask(task);
    ids.add(task.getId());
    taskService.setVariableLocal(task.getId(), "test", "test");
    taskService.setVariableLocal(task.getId(), "testBinary", "This is a binary variable".getBytes());
    taskService.addCandidateUser(task.getId(), "kermit");
  }
  return ids;
}
 
Example 3
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testDeleteTaskWithDeleteReason() {
  // ACT-900: deleteReason can be manually specified - can only be validated when historyLevel > ACTIVITY
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    
    Task task = taskService.newTask();
    task.setName("test task");
    taskService.saveTask(task);
    
    assertNotNull(task.getId());
    
    taskService.deleteTask(task.getId(), "deleted for testing purposes");
    
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery()
      .taskId(task.getId()).singleResult();
    
    assertNotNull(historicTaskInstance);
    assertEquals("deleted for testing purposes", historicTaskInstance.getDeleteReason());
    
    // Delete historic task that is left behind, will not be cleaned up because this is not part of a process
    taskService.deleteTask(task.getId(), true);
    
  }
}
 
Example 4
Source File: InitProcessEngineBySpringAnnotation.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx =
            new AnnotationConfigApplicationContext();
    ctx.register(SpringAnnotationConfiguration.class);
    ctx.refresh();

    assertNotNull(ctx.getBean(ProcessEngine.class));
    assertNotNull(ctx.getBean(RuntimeService.class));
    TaskService bean = ctx.getBean(TaskService.class);
    assertNotNull(bean);
    assertNotNull(ctx.getBean(HistoryService.class));
    assertNotNull(ctx.getBean(RepositoryService.class));
    assertNotNull(ctx.getBean(ManagementService.class));
    assertNotNull(ctx.getBean(FormService.class));
    Task task = bean.newTask();
    task.setName("哈哈");
    bean.saveTask(task);
}
 
Example 5
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testDeleteTaskWithDeleteReason() {
  // ACT-900: deleteReason can be manually specified - can only be
  // validated when historyLevel > ACTIVITY
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {

    Task task = taskService.newTask();
    task.setName("test task");
    taskService.saveTask(task);

    assertNotNull(task.getId());

    taskService.deleteTask(task.getId(), "deleted for testing purposes");

    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).singleResult();

    assertNotNull(historicTaskInstance);
    assertEquals("deleted for testing purposes", historicTaskInstance.getDeleteReason());

    // Delete historic task that is left behind, will not be cleaned up
    // because this is not part of a process
    taskService.deleteTask(task.getId(), true);

  }
}
 
Example 6
Source File: TaskInfoQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private Task createTask(String name, Date dueDate) {
  Task task = taskService.newTask();
  task.setName(name);
  task.setDueDate(dueDate);
  taskService.saveTask(task);
  return task;
}
 
Example 7
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 添加子任务
 */
@RequestMapping("task/subtask/add/{taskId}")
public String addSubTask(@PathVariable("taskId") String parentTaskId, @RequestParam("taskName") String taskName,
                         @RequestParam(value = "description", required = false) String description, HttpSession session) {
    Task newTask = taskService.newTask();
    newTask.setParentTaskId(parentTaskId);
    String userId = UserUtil.getUserFromSession(session).getId();
    newTask.setOwner(userId);
    newTask.setAssignee(userId);
    newTask.setName(taskName);
    newTask.setDescription(description);

    taskService.saveTask(newTask);
    return "redirect:/chapter6/task/getform/" + parentTaskId;
}
 
Example 8
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByCandidateOrAssigned() {
  TaskQuery query = taskService.createTaskQuery().taskCandidateOrAssigned("kermit");
  assertEquals(11, query.count());
  List<Task> tasks = query.list();
  assertEquals(11, tasks.size());

  // if dbIdentityUsed set false in process engine configuration of using
  // custom session factory of GroupIdentityManager
  ArrayList<String> candidateGroups = new ArrayList<String>();
  candidateGroups.add("management");
  candidateGroups.add("accountancy");
  candidateGroups.add("noexist");
  query = taskService.createTaskQuery().taskCandidateGroupIn(candidateGroups).taskCandidateOrAssigned("kermit");
  assertEquals(11, query.count());
  tasks = query.list();
  assertEquals(11, tasks.size());

  query = taskService.createTaskQuery().taskCandidateOrAssigned("fozzie");
  assertEquals(3, query.count());
  assertEquals(3, query.list().size());

  // create a new task that no identity link and assignee to kermit
  Task task = taskService.newTask();
  task.setName("assigneeToKermit");
  task.setDescription("testTask description");
  task.setPriority(3);
  task.setAssignee("kermit");
  taskService.saveTask(task);

  query = taskService.createTaskQuery().taskCandidateOrAssigned("kermit");
  assertEquals(12, query.count());
  tasks = query.list();
  assertEquals(12, tasks.size());

  Task assigneeToKermit = taskService.createTaskQuery().taskName("assigneeToKermit").singleResult();
  taskService.deleteTask(assigneeToKermit.getId());
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    historyService.deleteHistoricTaskInstance(assigneeToKermit.getId());
  }
}
 
Example 9
Source File: TaskInfoQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private Task createTask(String name, Date dueDate) {
	Task task = taskService.newTask();
	task.setName(name);
	task.setDueDate(dueDate);
	taskService.saveTask(task);
	return task;
}
 
Example 10
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByAssigneeIds() {
  TaskQuery query = taskService.createTaskQuery().taskAssigneeIds(Arrays.asList("gonzo", "kermit"));
  assertEquals(1, query.count());
  assertEquals(1, query.list().size());
  assertNotNull(query.singleResult());

  query = taskService.createTaskQuery().taskAssigneeIds(Arrays.asList("kermit", "kermit2"));
  assertEquals(0, query.count());
  assertEquals(0, query.list().size());
  assertNull(query.singleResult());

  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    // History
    assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskAssigneeIds(Arrays.asList("gonzo", "kermit")).count());
    assertEquals(0, historyService.createHistoricTaskInstanceQuery().taskAssigneeIds(Arrays.asList("kermit", "kermit2")).count());
  }

  Task adhocTask = taskService.newTask();
  adhocTask.setName("test");
  adhocTask.setAssignee("testAssignee");
  taskService.saveTask(adhocTask);

  query = taskService.createTaskQuery().taskAssigneeIds(Arrays.asList("gonzo", "testAssignee"));
  assertEquals(2, query.count());
  assertEquals(2, query.list().size());

  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    // History
    assertEquals(2, historyService.createHistoricTaskInstanceQuery().taskAssigneeIds(Arrays.asList("gonzo", "testAssignee")).count());
  }

  taskService.deleteTask(adhocTask.getId(), true);
}
 
Example 11
Source File: CustomMybatisXMLMapperTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected String createTask(String name, String owner, String assignee, int priority) {
  Task task = taskService.newTask();
  task.setName(name);
  task.setOwner(owner);
  task.setAssignee(assignee);
  task.setPriority(priority);
  taskService.saveTask(task);
  return task.getId();
}
 
Example 12
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 添加子任务
 */
@RequestMapping("task/subtask/add/{taskId}")
public String addSubTask(@PathVariable("taskId") String parentTaskId, @RequestParam("taskName") String taskName,
                         @RequestParam(value = "description", required = false) String description, HttpSession session) {
    Task newTask = taskService.newTask();
    newTask.setParentTaskId(parentTaskId);
    String userId = UserUtil.getUserFromSession(session).getId();
    newTask.setOwner(userId);
    newTask.setAssignee(userId);
    newTask.setName(taskName);
    newTask.setDescription(description);

    taskService.saveTask(newTask);
    return "redirect:/chapter6/task/getform/" + parentTaskId;
}
 
Example 13
Source File: StandaloneTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testHistoricVariableOkOnUpdate() {
   if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
 		// 1. create a task
 		Task task = taskService.newTask();
 		task.setName("test execution");
 		task.setOwner("josOwner");
 		task.setAssignee("JosAssignee");
 		taskService.saveTask(task);
 		 
 		// 2. set task variables
 		Map<String, Object> taskVariables = new HashMap<String, Object>();
 		taskVariables.put("finishedAmount", 0);
 		taskService.setVariables(task.getId(), taskVariables);
 		 
 		// 3. complete this task with a new variable
 		Map<String, Object> finishVariables = new HashMap<String, Object>();
 		finishVariables.put("finishedAmount", 40);
 		taskService.complete(task.getId(), finishVariables);
 		 
 		// 4. get completed variable
 		List<HistoricVariableInstance> hisVarList = historyService.createHistoricVariableInstanceQuery().taskId(task.getId()).list();
 		assertEquals(1, hisVarList.size());
 		assertEquals(40, hisVarList.get(0).getValue());
 		
 		// Cleanup
 		historyService.deleteHistoricTaskInstance(task.getId());
   }
}
 
Example 14
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testSaveTaskUpdate() throws Exception {

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
    Task task = taskService.newTask();
    task.setDescription("description");
    task.setName("taskname");
    task.setPriority(0);
    task.setAssignee("taskassignee");
    task.setOwner("taskowner");
    Date dueDate = sdf.parse("01/02/2003 04:05:06");
    task.setDueDate(dueDate);
    taskService.saveTask(task);

    // Fetch the task again and update
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertEquals("description", task.getDescription());
    assertEquals("taskname", task.getName());
    assertEquals("taskassignee", task.getAssignee());
    assertEquals("taskowner", task.getOwner());
    assertEquals(dueDate, task.getDueDate());
    assertEquals(0, task.getPriority());

    task.setName("updatedtaskname");
    task.setDescription("updateddescription");
    task.setPriority(1);
    task.setAssignee("updatedassignee");
    task.setOwner("updatedowner");
    dueDate = sdf.parse("01/02/2003 04:05:06");
    task.setDueDate(dueDate);
    taskService.saveTask(task);

    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertEquals("updatedtaskname", task.getName());
    assertEquals("updateddescription", task.getDescription());
    assertEquals("updatedassignee", task.getAssignee());
    assertEquals("updatedowner", task.getOwner());
    assertEquals(dueDate, task.getDueDate());
    assertEquals(1, task.getPriority());

    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
      HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).singleResult();
      assertEquals("updatedtaskname", historicTaskInstance.getName());
      assertEquals("updateddescription", historicTaskInstance.getDescription());
      assertEquals("updatedassignee", historicTaskInstance.getAssignee());
      assertEquals("updatedowner", historicTaskInstance.getOwner());
      assertEquals(dueDate, historicTaskInstance.getDueDate());
      assertEquals(1, historicTaskInstance.getPriority());
    }

    // Finally, delete task
    taskService.deleteTask(task.getId(), true);
  }
 
Example 15
Source File: TaskListenerTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Validate fix for ACT-1627: Not throwing assignment event on every update
 */
@Deployment(resources = {"org/activiti5/examples/bpmn/tasklistener/TaskListenerTest.bpmn20.xml"})
public void testTaskAssignmentListenerNotCalledWhenAssigneeNotUpdated() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("taskListenerProcess");
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("TaskCreateListener is listening!", task.getDescription());
  
  // Set assignee and check if event is received
  taskService.setAssignee(task.getId(), "kermit");
  task = taskService.createTaskQuery().singleResult();
  
  assertEquals("TaskAssignmentListener is listening: kermit", task.getDescription());
  
  // Reset description and assign to same person. This should NOT trigger an assignment
  task.setDescription("Clear");
  taskService.saveTask(task);
  taskService.setAssignee(task.getId(), "kermit");
  task = taskService.createTaskQuery().singleResult();
  assertEquals("Clear", task.getDescription());
  
  // Set assignee through task-update
  task.setAssignee("kermit");
  taskService.saveTask(task);
  
  task = taskService.createTaskQuery().singleResult();
  assertEquals("Clear", task.getDescription());
  
  // Update another property should not trigger assignment
  task.setName("test");
  taskService.saveTask(task);
  
  task = taskService.createTaskQuery().singleResult();
  assertEquals("Clear", task.getDescription());
  
  // Update to different
  task.setAssignee("john");
  taskService.saveTask(task);
  
  task = taskService.createTaskQuery().singleResult();
  assertEquals("TaskAssignmentListener is listening: john", task.getDescription());
  

  //Manually cleanup the process instance.
  runtimeService.deleteProcessInstance(processInstance.getProcessInstanceId(), "");
}
 
Example 16
Source File: SubTaskTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testSubTaskDeleteOnProcessInstanceDelete() {
  Deployment deployment = repositoryService.createDeployment()
      .addClasspathResource("org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml")
      .deploy();
  
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.setAssignee(task.getId(), "test");
  
  Task subTask1 = taskService.newTask();
  subTask1.setName("Sub task 1");
  subTask1.setParentTaskId(task.getId());
  subTask1.setAssignee("test");
  taskService.saveTask(subTask1);
  
  Task subTask2 = taskService.newTask();
  subTask2.setName("Sub task 2");
  subTask2.setParentTaskId(task.getId());
  subTask2.setAssignee("test");
  taskService.saveTask(subTask2);
  
  List<Task> tasks = taskService.createTaskQuery().taskAssignee("test").list();
  assertEquals(3, tasks.size());
  
  runtimeService.deleteProcessInstance(processInstance.getId(), "none");
  
  tasks = taskService.createTaskQuery().taskAssignee("test").list();
  assertEquals(0, tasks.size());
  
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery().taskAssignee("test").list();
    assertEquals(3, historicTasks.size());
    
    historyService.deleteHistoricProcessInstance(processInstance.getId());
    
    historicTasks = historyService.createHistoricTaskInstanceQuery().taskAssignee("test").list();
    assertEquals(0, historicTasks.size());
  }
  
  repositoryService.deleteDeployment(deployment.getId(), true);
}
 
Example 17
Source File: TaskListenerTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Validate fix for ACT-1627: Not throwing assignment event on every update
 */
@Deployment(resources = { "org/activiti/examples/bpmn/tasklistener/TaskListenerTest.bpmn20.xml" })
public void testTaskAssignmentListenerNotCalledWhenAssigneeNotUpdated() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("taskListenerProcess");
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("TaskCreateListener is listening!", task.getDescription());

  // Set assignee and check if event is received
  taskService.setAssignee(task.getId(), "kermit");
  task = taskService.createTaskQuery().singleResult();

  assertEquals("TaskAssignmentListener is listening: kermit", task.getDescription());

  // Reset description and assign to same person. This should NOT trigger
  // an assignment
  task.setDescription("Clear");
  taskService.saveTask(task);
  taskService.setAssignee(task.getId(), "kermit");
  task = taskService.createTaskQuery().singleResult();
  assertEquals("Clear", task.getDescription());

  // Set assignee through task-update
  task.setAssignee("kermit");
  taskService.saveTask(task);

  task = taskService.createTaskQuery().singleResult();
  assertEquals("Clear", task.getDescription());

  // Update another property should not trigger assignment
  task.setName("test");
  taskService.saveTask(task);

  task = taskService.createTaskQuery().singleResult();
  assertEquals("Clear", task.getDescription());

  // Update to different
  task.setAssignee("john");
  taskService.saveTask(task);

  task = taskService.createTaskQuery().singleResult();
  assertEquals("TaskAssignmentListener is listening: john", task.getDescription());

  // Manually cleanup the process instance.
  runtimeService.deleteProcessInstance(processInstance.getProcessInstanceId(), "");
}
 
Example 18
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testSaveTaskUpdate() throws Exception{
  
  SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
  Task task = taskService.newTask();
  task.setDescription("description");
  task.setName("taskname");
  task.setPriority(0);
  task.setAssignee("taskassignee");
  task.setOwner("taskowner");
  Date dueDate = sdf.parse("01/02/2003 04:05:06");
  task.setDueDate(dueDate);
  taskService.saveTask(task);

  // Fetch the task again and update
  task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
  assertEquals("description", task.getDescription());
  assertEquals("taskname", task.getName());
  assertEquals("taskassignee", task.getAssignee());
  assertEquals("taskowner", task.getOwner());
  assertEquals(dueDate, task.getDueDate());
  assertEquals(0, task.getPriority());

  task.setName("updatedtaskname");
  task.setDescription("updateddescription");
  task.setPriority(1);
  task.setAssignee("updatedassignee");
  task.setOwner("updatedowner");
  dueDate = sdf.parse("01/02/2003 04:05:06");
  task.setDueDate(dueDate);
  taskService.saveTask(task);

  task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
  assertEquals("updatedtaskname", task.getName());
  assertEquals("updateddescription", task.getDescription());
  assertEquals("updatedassignee", task.getAssignee());
  assertEquals("updatedowner", task.getOwner());
  assertEquals(dueDate, task.getDueDate());
  assertEquals(1, task.getPriority());
  
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    HistoricTaskInstance historicTaskInstance = historyService
      .createHistoricTaskInstanceQuery()
      .taskId(task.getId())
      .singleResult();
    assertEquals("updatedtaskname", historicTaskInstance.getName());
    assertEquals("updateddescription", historicTaskInstance.getDescription());
    assertEquals("updatedassignee", historicTaskInstance.getAssignee());
    assertEquals("updatedowner", historicTaskInstance.getOwner());
    assertEquals(dueDate, historicTaskInstance.getDueDate());
    assertEquals(1, historicTaskInstance.getPriority());
  }
  
  // Finally, delete task
  taskService.deleteTask(task.getId(), true);
}
 
Example 19
Source File: SubTaskTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testSubTask() {
  Task gonzoTask = taskService.newTask();
  gonzoTask.setName("gonzoTask");
  taskService.saveTask(gonzoTask);

  Task subTaskOne = taskService.newTask();
  subTaskOne.setName("subtask one");
  String gonzoTaskId = gonzoTask.getId();
  subTaskOne.setParentTaskId(gonzoTaskId);
  taskService.saveTask(subTaskOne);

  Task subTaskTwo = taskService.newTask();
  subTaskTwo.setName("subtask two");
  subTaskTwo.setParentTaskId(gonzoTaskId);
  taskService.saveTask(subTaskTwo);
  
  String subTaskId = subTaskOne.getId();
  assertTrue(taskService.getSubTasks(subTaskId).isEmpty());
  assertTrue(historyService
          .createHistoricTaskInstanceQuery()
          .taskParentTaskId(subTaskId)
          .list()
          .isEmpty());

  List<Task> subTasks = taskService.getSubTasks(gonzoTaskId);
  Set<String> subTaskNames = new HashSet<String>();
  for (Task subTask: subTasks) {
    subTaskNames.add(subTask.getName());
  }

  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    Set<String> expectedSubTaskNames = new HashSet<String>();
    expectedSubTaskNames.add("subtask one");
    expectedSubTaskNames.add("subtask two");

    assertEquals(expectedSubTaskNames, subTaskNames);
    
    List<HistoricTaskInstance> historicSubTasks = historyService
      .createHistoricTaskInstanceQuery()
      .taskParentTaskId(gonzoTaskId)
      .list();
    
    subTaskNames = new HashSet<String>();
    for (HistoricTaskInstance historicSubTask: historicSubTasks) {
      subTaskNames.add(historicSubTask.getName());
    }
    
    assertEquals(expectedSubTaskNames, subTaskNames);
  }

  taskService.deleteTask(gonzoTaskId, true);
}
 
Example 20
Source File: TaskQueryResourceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Test querying tasks. GET runtime/tasks
 */
public void testQueryTasksWithPaging() throws Exception {
  try {
    Calendar adhocTaskCreate = Calendar.getInstance();
    adhocTaskCreate.set(Calendar.MILLISECOND, 0);

    processEngineConfiguration.getClock().setCurrentTime(adhocTaskCreate.getTime());
    List<String> taskIdList = new ArrayList<String>();
    for (int i = 0; i < 10; i++) {
      Task adhocTask = taskService.newTask();
      adhocTask.setAssignee("gonzo");
      adhocTask.setOwner("owner");
      adhocTask.setDelegationState(DelegationState.PENDING);
      adhocTask.setDescription("Description one");
      adhocTask.setName("Name one");
      adhocTask.setDueDate(adhocTaskCreate.getTime());
      adhocTask.setPriority(100);
      taskService.saveTask(adhocTask);
      taskService.addUserIdentityLink(adhocTask.getId(), "misspiggy", IdentityLinkType.PARTICIPANT);
      taskIdList.add(adhocTask.getId());
    }
    Collections.sort(taskIdList);

    // Check filter-less to fetch all tasks
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_QUERY);
    ObjectNode requestNode = objectMapper.createObjectNode();
    String[] taskIds = new String[] { taskIdList.get(0), taskIdList.get(1), taskIdList.get(2) };
    assertResultsPresentInPostDataResponse(url + "?size=3&sort=id&order=asc", requestNode, taskIds);

    taskIds = new String[] { taskIdList.get(4), taskIdList.get(5), taskIdList.get(6), taskIdList.get(7) };
    assertResultsPresentInPostDataResponse(url + "?start=4&size=4&sort=id&order=asc", requestNode, taskIds);

    taskIds = new String[] { taskIdList.get(8), taskIdList.get(9) };
    assertResultsPresentInPostDataResponse(url + "?start=8&size=10&sort=id&order=asc", requestNode, taskIds);

  } finally {
    // Clean adhoc-tasks even if test fails
    List<Task> tasks = taskService.createTaskQuery().list();
    for (Task task : tasks) {
      if (task.getExecutionId() == null) {
        taskService.deleteTask(task.getId(), true);
      }
    }
  }
}