org.activiti.engine.task.Task Java Examples

The following examples show how to use org.activiti.engine.task.Task. 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: StandaloneTaskTest.java    From activiti6-boot2 with 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 #2
Source File: CallActivityAdvancedTest.java    From activiti6-boot2 with 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 #3
Source File: ActivitiResourceMapperTest.java    From crnk-framework with 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 #4
Source File: TaskVariablesCollectionResourceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #5
Source File: TaskServiceTest.java    From activiti6-boot2 with 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 #6
Source File: DeleteReasonTest.java    From activiti6-boot2 with 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 #7
Source File: TerminateEndEventTest.java    From activiti6-boot2 with 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 #8
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: TaskServiceTest.java    From activiti6-boot2 with 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 #10
Source File: BoundaryErrorEventTest.java    From activiti6-boot2 with 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 #11
Source File: TaskVariableBaseResource.java    From activiti6-boot2 with 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 #12
Source File: StandaloneTaskTest.java    From activiti6-boot2 with 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 #13
Source File: TaskServiceTest.java    From activiti6-boot2 with 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 #14
Source File: HistoricActivityInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #15
Source File: ParallelGatewayTest.java    From activiti6-boot2 with 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 #16
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 #17
Source File: TaskAssigneeTest.java    From activiti6-boot2 with 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 #18
Source File: BoundaryErrorEventTest.java    From activiti6-boot2 with 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 #19
Source File: CallActivityAdvancedTest.java    From activiti6-boot2 with 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 #20
Source File: TaskServiceTest.java    From activiti6-boot2 with 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 #21
Source File: TaskQueryTest.java    From activiti6-boot2 with 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 #22
Source File: TaskListenerTest.java    From activiti6-boot2 with 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 #23
Source File: GatewayTest.java    From activiti-learn with 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 #24
Source File: TerminateEndEventTest.java    From activiti6-boot2 with 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 #25
Source File: BoundaryTimerNonInterruptingEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testTimerOnConcurrentSubprocess() {
  String procId = runtimeService.startProcessInstanceByKey("testTimerOnConcurrentSubprocess").getId();
  assertEquals(4, taskService.createTaskQuery().count());
  
  Job timer = managementService.createTimerJobQuery().singleResult();
  managementService.moveTimerToExecutableJob(timer.getId());
  managementService.executeJob(timer.getId());
  assertEquals(5, taskService.createTaskQuery().count());
  
  // Complete 4 tasks that will trigger the join
  Task task = taskService.createTaskQuery().taskDefinitionKey("sub1task1").singleResult();
  taskService.complete(task.getId());
  task = taskService.createTaskQuery().taskDefinitionKey("sub1task2").singleResult();
  taskService.complete(task.getId());
  task = taskService.createTaskQuery().taskDefinitionKey("sub2task1").singleResult();
  taskService.complete(task.getId());
  task = taskService.createTaskQuery().taskDefinitionKey("sub2task2").singleResult();
  taskService.complete(task.getId());
  assertEquals(1, taskService.createTaskQuery().count());
  
  // Finally, complete the task that was created due to the timer 
  task = taskService.createTaskQuery().taskDefinitionKey("timerFiredTask").singleResult();
  taskService.complete(task.getId());
  
  assertProcessEnded(procId);
}
 
Example #26
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 #27
Source File: InclusiveGatewayTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testDecideBasedOnBeanProperty() {
  runtimeService.startProcessInstanceByKey("inclusiveDecisionBasedOnBeanProperty", CollectionUtil.singletonMap("order", new InclusiveGatewayTestOrder(150)));
  List<Task> tasks = taskService.createTaskQuery().list();
  assertEquals(2, tasks.size());
  Map<String, String> expectedNames = new HashMap<String, String>();
  expectedNames.put(BEAN_TASK2_NAME, BEAN_TASK2_NAME);
  expectedNames.put(BEAN_TASK3_NAME, BEAN_TASK3_NAME);
  for (Task task : tasks) {
    expectedNames.remove(task.getName());
  }
  assertEquals(0, expectedNames.size());
}
 
Example #28
Source File: TaskResourceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test updating a task that is part of a process. PUT runtime/tasks/{taskId}
 */
@Deployment
public void testDeleteTaskInProcess() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertNotNull(task);

  HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId()));
  closeResponse(executeRequest(httpDelete, HttpStatus.SC_FORBIDDEN));
}
 
Example #29
Source File: TerminateEndEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testTerminateInSubProcessWithBoundaryTerminateAll() throws Exception {
  // Test terminating subprocess
  
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateEndEventWithBoundary");

  assertEquals(3, taskService.createTaskQuery().processInstanceId(pi.getId()).count());
  
  // Complete sub process task that leads to a terminate end event
  Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).taskDefinitionKey("preTermInnerTask").singleResult();
  taskService.complete(task.getId());
  
  assertProcessEnded(pi.getId());
}
 
Example #30
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml"})
public void testProcessDefinitionKey() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  
  List<Task> tasks = taskService.createTaskQuery().processDefinitionKey("oneTaskProcess").list();
  assertEquals(1, tasks.size());
  assertEquals(processInstance.getId(), tasks.get(0).getProcessInstanceId());
  
  assertEquals(0, taskService.createTaskQuery().processDefinitionKey("unexisting").count());
}