Java Code Examples for org.activiti.engine.task.Task

The following examples show how to use org.activiti.engine.task.Task. These examples are extracted from open source projects. 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 Project: activiti6-boot2   Source File: TaskServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testTaskAssignee() {
  Task task = taskService.newTask();
  task.setAssignee("johndoe");
  taskService.saveTask(task);

  // Fetch the task again and update
  task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
  assertEquals("johndoe", task.getAssignee());

  task.setAssignee("joesmoe");
  taskService.saveTask(task);

  task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
  assertEquals("joesmoe", task.getAssignee());

  // Finally, delete task
  taskService.deleteTask(task.getId(), true);
}
 
Example 2
@Deployment(resources={
  "org/activiti5/examples/bpmn/callactivity/orderProcess.bpmn20.xml",
  "org/activiti5/examples/bpmn/callactivity/checkCreditProcess.bpmn20.xml"       
})
public void testOrderProcessWithCallActivity() {
	if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
   // After the process has started, the 'verify credit history' task should be active
   ProcessInstance pi = runtimeService.startProcessInstanceByKey("orderProcess");
   TaskQuery taskQuery = taskService.createTaskQuery();
   Task verifyCreditTask = taskQuery.singleResult();
   assertEquals("Verify credit history", verifyCreditTask.getName());
   
   // Verify with Query API
   ProcessInstance subProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId(pi.getId()).singleResult();
   assertNotNull(subProcessInstance);
   assertEquals(pi.getId(), runtimeService.createProcessInstanceQuery().subProcessInstanceId(subProcessInstance.getId()).singleResult().getId());
   
   // Completing the task with approval, will end the subprocess and continue the original process
   taskService.complete(verifyCreditTask.getId(), CollectionUtil.singletonMap("creditApproved", true));
   Task prepareAndShipTask = taskQuery.singleResult();
   assertEquals("Prepare and Ship", prepareAndShipTask.getName());
	}
}
 
Example 3
Source Project: activiti6-boot2   Source File: TerminateEndEventTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment
public void testTerminateInSubProcessSequentialConcurrentMultiInstance() throws Exception {
  
  // Starting multi instance with 5 instances; terminating 2, finishing 3
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateEndEventExample");

  long remainingExecutions = runtimeService.createExecutionQuery().count();
  
  // outer execution still available
  assertEquals(1, remainingExecutions);
  
  // three finished
  assertEquals(3, serviceTaskInvokedCount2);
  
  Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).taskDefinitionKey("preNormalEnd").singleResult();
  taskService.complete(task.getId());
  
  // last task remaining
  assertProcessEnded(pi.getId());
}
 
Example 4
Source Project: activiti6-boot2   Source File: CallActivityAdvancedTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test case for deleting a sub process
 */
@Deployment(resources = {
  "org/activiti5/engine/test/bpmn/callactivity/CallActivity.testTwoSubProcesses.bpmn20.xml", 
  "org/activiti5/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml" })
public void testTwoSubProcesses() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callTwoSubProcesses");
  
  List<ProcessInstance> instanceList = runtimeService.createProcessInstanceQuery().list();
  assertNotNull(instanceList);
  assertEquals(3, instanceList.size());
  
  List<Task> taskList = taskService.createTaskQuery().list();
  assertNotNull(taskList);
  assertEquals(2, taskList.size());
  
  runtimeService.deleteProcessInstance(processInstance.getId(), "Test cascading");
  
  instanceList = runtimeService.createProcessInstanceQuery().list();
  assertNotNull(instanceList);
  assertEquals(0, instanceList.size());
  
  taskList = taskService.createTaskQuery().list();
  assertNotNull(taskList);
  assertEquals(0, taskList.size());
}
 
Example 5
Source Project: crnk-framework   Source File: ActivitiResourceMapperTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void checkForm() {
	Map<String, Object> variables = mapper.mapToVariables(formResource);
	Assert.assertEquals(1, variables.size());
	Assert.assertEquals(Boolean.TRUE, variables.get("approved"));

	TestForm resourceCopy = new TestForm();
	mapper.mapFromVariables(resourceCopy, variables);
	checkFormResource(resourceCopy);

	List<FormProperty> formProperties = new ArrayList<>();
	FormProperty formProperty = Mockito.mock(FormProperty.class);
	Mockito.when(formProperty.getId()).thenReturn("approved");
	Mockito.when(formProperty.getValue()).thenReturn("true");
	formProperties.add(formProperty);

	TaskFormData formData = Mockito.mock(TaskFormData.class);
	Mockito.when(formData.getFormProperties()).thenReturn(formProperties);
	Task task = Mockito.mock(Task.class);
	Mockito.when(task.getId()).thenReturn("someTask");
	Mockito.when(formData.getTask()).thenReturn(task);
	TestForm formCopy = mapper.mapToResource(TestForm.class, formData);
	checkFormResource(formCopy);
	Assert.assertEquals("someTask", formCopy.getId());
}
 
Example 6
Source Project: activiti6-boot2   Source File: TaskServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment
public void testFormKeyExpression() {
  runtimeService.startProcessInstanceByKey("testFormExpression", CollectionUtil.singletonMap("var", "abc"));

  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("first-form.json", task.getFormKey());
  taskService.complete(task.getId());

  task = taskService.createTaskQuery().singleResult();
  assertEquals("form-abc.json", task.getFormKey());

  task.setFormKey("form-changed.json");
  taskService.saveTask(task);
  task = taskService.createTaskQuery().singleResult();
  assertEquals("form-changed.json", task.getFormKey());

  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).singleResult();
    assertEquals("form-changed.json", historicTaskInstance.getFormKey());
  }
}
 
Example 7
Source Project: activiti6-boot2   Source File: TerminateEndEventTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources={
  "org/activiti5/engine/test/bpmn/event/end/TerminateEndEventTest.testTerminateInCallActivity.bpmn", 
  "org/activiti5/engine/test/bpmn/event/end/TerminateEndEventTest.subProcessTerminate.bpmn" 
})
public void testTerminateInCallActivity() throws Exception {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateEndEventExample");

  // should terminate the called process and continue the parent
  long executionEntities = runtimeService.createExecutionQuery().count();
  assertEquals(1, executionEntities);
  
  Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).taskDefinitionKey("preNormalEnd").singleResult();
  taskService.complete(task.getId());
  
  assertProcessEnded(pi.getId());
}
 
Example 8
Source Project: activiti6-boot2   Source File: TaskQueryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml"})
public void testProcessCategoryNotInOr() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

  final Task task = taskService.createTaskQuery()
      .or()
      .taskId("invalid")
      .processCategoryNotIn(Collections.singletonList("unexisting")).singleResult();
  assertNotNull(task);
  assertEquals("theTask", task.getTaskDefinitionKey());
  assertEquals(processInstance.getId(), task.getProcessInstanceId());

  assertEquals(0, taskService.createTaskQuery()
      .or()
      .taskId("invalid")
      .processCategoryNotIn(Collections.singletonList("Examples")).count());
}
 
Example 9
Source Project: activiti6-boot2   Source File: CallActivityAdvancedTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/callactivity/CallActivity.testCallParallelSubProcess.bpmn20.xml",
    "org/activiti/engine/test/bpmn/callactivity/simpleParallelSubProcess.bpmn20.xml" })
public void testCallParallelSubProcess() {
  runtimeService.startProcessInstanceByKey("callParallelSubProcess");

  // The two tasks in the parallel subprocess should be active
  TaskQuery taskQuery = taskService.createTaskQuery().orderByTaskName().asc();
  List<Task> tasks = taskQuery.list();
  assertEquals(2, tasks.size());

  Task taskA = tasks.get(0);
  Task taskB = tasks.get(1);
  assertEquals("Task A", taskA.getName());
  assertEquals("Task B", taskB.getName());

  // Completing the first task should not end the subprocess
  taskService.complete(taskA.getId());
  assertEquals(1, taskQuery.list().size());

  // Completing the second task should end the subprocess and end the
  // whole process instance
  taskService.complete(taskB.getId());
  assertEquals(0, runtimeService.createExecutionQuery().count());
}
 
Example 10
Source Project: activiti6-boot2   Source File: TaskAssigneeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment
public void testTaskAssignee() {

  // Start process instance
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("taskAssigneeExampleProcess");

  // Get task list
  List<Task> tasks = taskService.createTaskQuery().taskAssignee("kermit").list();
  assertEquals(1, tasks.size());
  Task myTask = tasks.get(0);
  assertEquals("Schedule meeting", myTask.getName());
  assertEquals("Schedule an engineering meeting for next week with the new hire.", myTask.getDescription());

  // Complete task. Process is now finished
  taskService.complete(myTask.getId());
  // assert if the process instance completed
  assertProcessEnded(processInstance.getId());
}
 
Example 11
Source Project: activiti6-boot2   Source File: ParallelGatewayTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment
public void testForkJoin() {

  ProcessInstance pi = runtimeService.startProcessInstanceByKey("forkJoin");
  TaskQuery query = taskService.createTaskQuery().processInstanceId(pi.getId()).orderByTaskName().asc();

  List<Task> tasks = query.list();
  assertEquals(2, tasks.size());
  // the tasks are ordered by name (see above)
  Task task1 = tasks.get(0);
  assertEquals("Receive Payment", task1.getName());
  Task task2 = tasks.get(1);
  assertEquals("Ship Order", task2.getName());

  // Completing both tasks will join the concurrent executions
  taskService.complete(tasks.get(0).getId());
  taskService.complete(tasks.get(1).getId());

  tasks = query.list();
  assertEquals(1, tasks.size());
  assertEquals("Archive Order", tasks.get(0).getName());
}
 
Example 12
Source Project: activiti6-boot2   Source File: StandaloneTaskTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testRevisionUpdatedOnSaveWhenFetchedUsingQuery() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  assertEquals(1, ((TaskEntity) task).getRevision());
  
  task.setAssignee("kermit");
  taskService.saveTask(task);
  assertEquals(2, ((TaskEntity) task).getRevision());
  
  // Now fetch the task through the query api
  task = taskService.createTaskQuery().singleResult();
  assertEquals(2, ((TaskEntity) task).getRevision());
  task.setPriority(1);
  taskService.saveTask(task);
  
  assertEquals(3, ((TaskEntity) task).getRevision());
  
  taskService.deleteTask(task.getId(), true);
}
 
Example 13
Source Project: activiti6-boot2   Source File: TaskAndVariablesQueryTest.java    License: 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 14
Source Project: activiti6-boot2   Source File: BoundaryErrorEventTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorThrownByCallActivityOnCallActivity.bpmn20.xml",
    "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.subprocess2ndLevel.bpmn20.xml", "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.subprocess.bpmn20.xml" })
public void testCatchErrorThrownByCallActivityOnCallActivity() throws InterruptedException {
  String procId = runtimeService.startProcessInstanceByKey("catchErrorOnCallActivity2ndLevel").getId();

  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("Task in subprocess", task.getName());

  taskService.complete(task.getId());

  task = taskService.createTaskQuery().singleResult();
  assertEquals("Escalated Task", task.getName());

  // Completing the task will end the process instance
  taskService.complete(task.getId());
  assertProcessEnded(procId);
}
 
Example 15
Source Project: activiti6-boot2   Source File: TaskServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { 
"org/activiti5/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testRemoveVariableLocal() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  
  Task currentTask = taskService.createTaskQuery().singleResult();
  
  taskService.setVariableLocal(currentTask.getId(), "variable1", "value1");
  assertEquals("value1", taskService.getVariable(currentTask.getId(), "variable1"));
  assertEquals("value1", taskService.getVariableLocal(currentTask.getId(), "variable1"));
  
  taskService.removeVariableLocal(currentTask.getId(), "variable1");
  
  assertNull(taskService.getVariable(currentTask.getId(), "variable1"));
  assertNull(taskService.getVariableLocal(currentTask.getId(), "variable1"));
  
  checkHistoricVariableUpdateEntity("variable1", processInstance.getId());
}
 
Example 16
Source Project: activiti6-boot2   Source File: TaskListenerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {"org/activiti5/examples/bpmn/tasklistener/TaskListenerTest.bpmn20.xml"})
public void testTaskCreateListener() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("taskListenerProcess");
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("Schedule meeting", task.getName());
  assertEquals("TaskCreateListener is listening!", task.getDescription());

  //Manually cleanup the process instance.  If we don't do this, the following actions will occur:
  //   1. The cleanup rule will delete the process
  //   2. The process deletion will fire a DELETE event to the TaskAllEventsListener
  //   3. The TaskAllEventsListener will set a variable on the Task
  //   4. Setting that variable will result in an entry in the ACT_HI_DETAIL table
  //   5. The AbstractActivitiTestCase will fail the test because the DB is not clean
  //By triggering the DELETE event from within the test, we ensure that all of the records
  //are written before the test cleanup begins
  runtimeService.deleteProcessInstance(processInstance.getProcessInstanceId(), "");
}
 
Example 17
Source Project: activiti-learn   Source File: GatewayTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources="me/chanjar/gateway/gateway-none.bpmn")
public void gatewayNone() {
  String processDefinitionKey = "gateway-none";
  runtimeService.startProcessInstanceByKey(processDefinitionKey);
  // 完成一个任务
  Task usertask1 = taskService.createTaskQuery().processDefinitionKey(processDefinitionKey).taskDefinitionKey("usertask1").singleResult();
  taskService.complete(usertask1.getId());
  
  Task usertask2 = taskService.createTaskQuery().processDefinitionKey(processDefinitionKey).taskDefinitionKey("usertask2").singleResult();
  taskService.complete(usertask2.getId());
  
  Task usertask3 = taskService.createTaskQuery().processDefinitionKey(processDefinitionKey).taskDefinitionKey("usertask3").singleResult();
  taskService.complete(usertask3.getId());

  assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(processDefinitionKey).count());
 
}
 
Example 18
Source Project: activiti6-boot2   Source File: TaskServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testGetIdentityLinksWithCandidateGroup() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  String taskId = task.getId();

  identityService.saveGroup(identityService.newGroup("muppets"));

  taskService.addCandidateGroup(taskId, "muppets");
  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  assertEquals(1, identityLinks.size());
  assertEquals("muppets", identityLinks.get(0).getGroupId());
  assertNull(identityLinks.get(0).getUserId());
  assertEquals(IdentityLinkType.CANDIDATE, identityLinks.get(0).getType());

  // cleanup
  taskService.deleteTask(taskId, true);
  identityService.deleteGroup("muppets");
}
 
Example 19
Source Project: activiti6-boot2   Source File: StandaloneTaskTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testOptimisticLockingThrownOnMultipleUpdates() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  String taskId = task.getId();

  // first modification
  Task task1 = taskService.createTaskQuery().taskId(taskId).singleResult();
  Task task2 = taskService.createTaskQuery().taskId(taskId).singleResult();

  task1.setDescription("first modification");
  taskService.saveTask(task1);

  // second modification on the initial instance
  task2.setDescription("second modification");
  try {
    taskService.saveTask(task2);
    fail("should get an exception here as the task was modified by someone else.");
  } catch (ActivitiOptimisticLockingException expected) {
    // exception was thrown as expected
  }

  taskService.deleteTask(taskId, true);
}
 
Example 20
/**
 * Test to validate fix for ACT-1549: endTime of joining parallel gateway is not set
 */
@Deployment
public void testParallelJoinEndTime() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("forkJoin");

  List<Task> tasksToComplete = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
  assertEquals(2, tasksToComplete.size());

  // Complete both tasks, second task-complete should end the fork-gateway
  // and set time
  taskService.complete(tasksToComplete.get(0).getId());
  taskService.complete(tasksToComplete.get(1).getId());

  List<HistoricActivityInstance> historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("join").processInstanceId(processInstance.getId()).list();

  assertNotNull(historicActivityInstance);

  // History contains 2 entries for parallel join (one for each path
  // arriving in the join), should contain end-time
  assertEquals(2, historicActivityInstance.size());
  assertNotNull(historicActivityInstance.get(0).getEndTime());
  assertNotNull(historicActivityInstance.get(1).getEndTime());
}
 
Example 21
Source Project: activiti6-boot2   Source File: TaskVariableBaseResource.java    License: Apache License 2.0 6 votes vote down vote up
protected void setVariable(Task task, String name, Object value, RestVariableScope scope, boolean isNew) {
  // Create can only be done on new variables. Existing variables should
  // be updated using PUT
  boolean hasVariable = hasVariableOnScope(task, name, scope);
  if (isNew && hasVariable) {
    throw new ActivitiException("Variable '" + name + "' is already present on task '" + task.getId() + "'.");
  }

  if (!isNew && !hasVariable) {
    throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a variable with name: '" + name + "'.", null);
  }

  if (scope == RestVariableScope.LOCAL) {
    taskService.setVariableLocal(task.getId(), name, value);
  } else {
    if (task.getExecutionId() != null) {
      // Explicitly set on execution, setting non-local variable on
      // task will override local-variable if exists
      runtimeService.setVariable(task.getExecutionId(), name, value);
    } else {
      // Standalone task, no global variables possible
      throw new ActivitiIllegalArgumentException("Cannot set global variable '" + name + "' on task '" + task.getId() + "', task is not part of process.");
    }
  }
}
 
Example 22
Source Project: activiti6-boot2   Source File: BoundaryErrorEventTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorThrownByCallActivityOnSubprocess.bpmn20.xml",
    "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.subprocess.bpmn20.xml" })
public void testCatchErrorThrownByCallActivityOnSubprocess() {
  String procId = runtimeService.startProcessInstanceByKey("catchErrorOnSubprocess").getId();
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("Task in subprocess", task.getName());

  // Completing the task will reach the end error event,
  // which is caught on the call activity boundary
  taskService.complete(task.getId());
  task = taskService.createTaskQuery().singleResult();
  assertEquals("Escalated Task", task.getName());

  // Completing the task will end the process instance
  taskService.complete(task.getId());
  assertProcessEnded(procId);
}
 
Example 23
/**
 * Test deleting all local task variables. DELETE runtime/tasks/{taskId}/variables
 */
@Deployment
public void testDeleteAllLocalVariables() throws Exception {
  // Start process with all types of variables
  Map<String, Object> processVariables = new HashMap<String, Object>();
  processVariables.put("var1", "This is a ProcVariable");
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);

  // Set local task variables
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  Map<String, Object> taskVariables = new HashMap<String, Object>();
  taskVariables.put("var1", "This is a TaskVariable");
  taskVariables.put("var2", 123);
  taskService.setVariablesLocal(task.getId(), taskVariables);
  assertEquals(2, taskService.getVariablesLocal(task.getId()).size());

  HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
  closeResponse(executeBinaryRequest(httpDelete, HttpStatus.SC_NO_CONTENT));

  // Check if local variables are gone and global remain unchanged
  assertEquals(0, taskService.getVariablesLocal(task.getId()).size());
  assertEquals(1, taskService.getVariables(task.getId()).size());
}
 
Example 24
Source Project: activiti6-boot2   Source File: DeleteReasonTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment
public void testInterruptingBoundaryEvent() {
  ProcessInstance  processInstance = runtimeService.startProcessInstanceByKey("deleteReasonProcess");
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("A", task.getName());
  taskService.complete(task.getId());
  
  // Timer firing should delete all tasks
  Job timerJob = managementService.createTimerJobQuery().singleResult();
  managementService.moveTimerToExecutableJob(timerJob.getId());
  managementService.executeJob(timerJob.getId());
  
  assertHistoricTasksDeleteReason(processInstance, null, "A");
  assertHistoricTasksDeleteReason(processInstance, DeleteReason.BOUNDARY_EVENT_INTERRUPTING, "B", "C", "D");
  assertHistoricActivitiesDeleteReason(processInstance, null, "A");
  assertHistoricActivitiesDeleteReason(processInstance, DeleteReason.BOUNDARY_EVENT_INTERRUPTING, "B", "C", "D", "theSubprocess");
}
 
Example 25
Source Project: activiti6-boot2   Source File: MultiInstanceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public void testParallelUserTasks() {
  String procId = runtimeService.startProcessInstanceByKey("miParallelUserTasks").getId();

  List<Task> tasks = taskService.createTaskQuery().orderByTaskName().asc().list();
  assertEquals(3, tasks.size());
  assertEquals("My Task 0", tasks.get(0).getName());
  assertEquals("My Task 1", tasks.get(1).getName());
  assertEquals("My Task 2", tasks.get(2).getName());

  checkInnerInstanceVariables(tasks.get(0), 0, LOOP_COUNTER_KEY);
  checkInnerInstanceVariables(tasks.get(1), 1, LOOP_COUNTER_KEY);
  checkInnerInstanceVariables(tasks.get(2), 2, LOOP_COUNTER_KEY);

  Execution outerExecution = retrieveOuterExecution(procId);

  checkBuiltInOuterVariables(outerExecution, 3, 0);
  taskService.complete(tasks.get(0).getId());

  checkBuiltInOuterVariables(outerExecution, 2, 1);
  taskService.complete(tasks.get(1).getId());

  checkBuiltInOuterVariables(outerExecution, 1, 2);
  taskService.complete(tasks.get(2).getId());

  assertProcessEnded(procId);
}
 
Example 26
Source Project: activiti6-boot2   Source File: TaskServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testCompleteTaskWithParametersNullParameters() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  
  String taskId = task.getId();
  taskService.complete(taskId, null);

  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    historyService.deleteHistoricTaskInstance(taskId);
  }
  
  // Fetch the task again
  task = taskService.createTaskQuery().taskId(taskId).singleResult();
  assertNull(task);
}
 
Example 27
Source Project: activiti6-boot2   Source File: TaskServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testGetIdentityLinksWithNonExistingAssignee() {
  Task task = taskService.newTask();
  taskService.saveTask(task);
  String taskId = task.getId();
  
  taskService.claim(taskId, "nonExistingAssignee");
  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
  assertEquals(1, identityLinks.size());
  assertEquals("nonExistingAssignee", identityLinks.get(0).getUserId());
  assertNull(identityLinks.get(0).getGroupId());
  assertEquals(IdentityLinkType.ASSIGNEE, identityLinks.get(0).getType());
  
  //cleanup
  taskService.deleteTask(taskId, true);
}
 
Example 28
@Deployment(resources = "org/activiti/engine/test/history/HistoricVariableInstanceTest.testSimple.bpmn20.xml")
public void testNativeHistoricDetailQuery() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
    assertEquals("ACT_HI_DETAIL", managementService.getTableName(HistoricDetail.class));
    assertEquals("ACT_HI_DETAIL", managementService.getTableName(HistoricVariableUpdate.class));

    String tableName = managementService.getTableName(HistoricDetail.class);
    String baseQuerySql = "SELECT * FROM " + tableName;

    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("var1", "value1");
    variables.put("var2", "value2");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc", variables);
    assertNotNull(processInstance);

    assertEquals(3, historyService.createNativeHistoricDetailQuery().sql(baseQuerySql).list().size());

    String sqlWithConditions = baseQuerySql + " where NAME_ = #{name} and TYPE_ = #{type}";
    assertNotNull(historyService.createNativeHistoricDetailQuery().sql(sqlWithConditions).parameter("name", "myVar").parameter("type", "VariableUpdate").singleResult());

    sqlWithConditions = baseQuerySql + " where NAME_ like #{name}";
    assertEquals(2, historyService.createNativeHistoricDetailQuery().sql(sqlWithConditions).parameter("name", "var%").list().size());

    Task task = taskService.createTaskQuery().singleResult();
    Map<String, String> formDatas = new HashMap<String, String>();
    formDatas.put("field1", "field value 1");
    formDatas.put("field2", "field value 2");
    formService.submitTaskFormData(task.getId(), formDatas);

    String countSql = "select count(*) from " + tableName + " where TYPE_ = #{type} and PROC_INST_ID_ = #{pid}";
    assertEquals(2, historyService.createNativeHistoricDetailQuery().sql(countSql).parameter("type", "FormProperty").parameter("pid", processInstance.getId()).count());

    // paging
    assertEquals(3, historyService.createNativeHistoricDetailQuery().sql(baseQuerySql).listPage(0, 3).size());
    assertEquals(3, historyService.createNativeHistoricDetailQuery().sql(baseQuerySql).listPage(1, 3).size());
    sqlWithConditions = baseQuerySql + " where TYPE_ = #{type} and PROC_INST_ID_ = #{pid}";
    assertEquals(2, historyService.createNativeHistoricDetailQuery().sql(sqlWithConditions).parameter("type", "FormProperty").parameter("pid", processInstance.getId()).listPage(0, 2).size());
  }
}
 
Example 29
Source Project: activiti6-boot2   Source File: TerminateEndEventTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public void testNestedCallActivitiesTerminateAll() {
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("TestNestedCallActivities");
	
	// Verify the tasks
	List<Task> tasks = assertTaskNames(processInstance, 
			Arrays.asList("B", "B", "B", "B", "Before A", "Before A", "Before A", "Before A", "Before B", "Before C"));
	
	// Completing 'Before B' should lead to process instance termination
	taskService.complete(tasks.get(8).getId());
	assertProcessEnded(processInstance.getId());
	assertHistoricProcessInstanceDetails(processInstance);
	
	// Completing 'Before C' too
	processInstance = runtimeService.startProcessInstanceByKey("TestNestedCallActivities");
	tasks = assertTaskNames(processInstance, 
			Arrays.asList("B", "B", "B", "B", "Before A", "Before A", "Before A", "Before A", "Before B", "Before C"));
	taskService.complete(tasks.get(9).getId());
	assertProcessEnded(processInstance.getId());
	assertHistoricProcessInstanceDetails(processInstance);
	
	// Now the tricky one. 'Before A' leads to 'callActivity A', which calls subprocess02 which terminates
	processInstance = runtimeService.startProcessInstanceByKey("TestNestedCallActivities");
	tasks = assertTaskNames(processInstance, 
			Arrays.asList("B", "B", "B", "B", "Before A", "Before A", "Before A", "Before A", "Before B", "Before C"));
	taskService.complete(tasks.get(5).getId());
	Task task = taskService.createTaskQuery().taskName("subprocess1_task").singleResult();
	assertNotNull(task);
	taskService.complete(task.getId());
	assertProcessEnded(processInstance.getId());
	assertHistoricProcessInstanceDetails(processInstance);
	
}
 
Example 30
Source Project: activiti6-boot2   Source File: TaskQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testQueryByInvolvedUserOr() {
  try {
    Task adhocTask = taskService.newTask();
    adhocTask.setAssignee("kermit");
    adhocTask.setOwner("fozzie");
    taskService.saveTask(adhocTask);
    taskService.addUserIdentityLink(adhocTask.getId(), "gonzo", "customType");
    
    assertEquals(3, taskService.getIdentityLinksForTask(adhocTask.getId()).size());
    
    assertEquals(1, taskService.createTaskQuery().taskId(adhocTask.getId())
        .or()
        .taskId("invalid")
        .taskInvolvedUser("gonzo").count());
    assertEquals(1, taskService.createTaskQuery().taskId(adhocTask.getId())
        .or()
        .taskId("invalid")
        .taskInvolvedUser("kermit").count());
    assertEquals(1, taskService.createTaskQuery().taskId(adhocTask.getId())
        .or()
        .taskId("invalid")
        .taskInvolvedUser("fozzie").count());
    
  } finally {
    List<Task> allTasks = taskService.createTaskQuery().list();
    for(Task task : allTasks) {
      if(task.getExecutionId() == null) {
        taskService.deleteTask(task.getId());
        if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
          historyService.deleteHistoricTaskInstance(task.getId());
        }
      }
    }
  }
}