Java Code Examples for org.activiti.engine.task.TaskQuery#singleResult()

The following examples show how to use org.activiti.engine.task.TaskQuery#singleResult() . 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: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testSimple() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task userTask = taskQuery.singleResult();
    assertEquals("userTask1", userTask.getName());

    taskService.complete(userTask.getId(), CollectionUtil.singletonMap("myVar", "test789"));

    assertProcessEnded(processInstance.getId());

    List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
    assertEquals(1, variables.size());

    HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
    assertEquals("test456", historicVariable.getTextValue());

    assertEquals(5, historyService.createHistoricActivityInstanceQuery().count());
    assertEquals(3, historyService.createHistoricDetailQuery().count());
  }
}
 
Example 2
Source File: HistoryServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/examples/bpmn/callactivity/orderProcess.bpmn20.xml", "org/activiti/examples/bpmn/callactivity/checkCreditProcess.bpmn20.xml" })
public void testOrderProcessWithCallActivity() {
  // 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();

  // 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());

  // verify
  HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().superProcessInstanceId(pi.getId()).singleResult();
  assertNotNull(historicProcessInstance);
  assertTrue(historicProcessInstance.getProcessDefinitionId().contains("checkCreditProcess"));
}
 
Example 3
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testQueryByNameInOr() {
  final List<String> taskNameList = new ArrayList<String>(2);
  taskNameList.add("testTask");
  taskNameList.add("gonzoTask");

  TaskQuery query = taskService.createTaskQuery()
      .or()
      .taskNameIn(taskNameList)
      .taskId("invalid");
  assertEquals(7, query.list().size());
  assertEquals(7, query.count());

  try {
    query.singleResult();
    fail("expected exception");
  } catch (ActivitiException e) {
    // OK
  }
}
 
Example 4
Source File: HistoryServiceTest.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() {
  // 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();

  // 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());

  // verify
  HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().superProcessInstanceId(pi.getId()).singleResult();
  assertNotNull(historicProcessInstance);
  assertTrue(historicProcessInstance.getProcessDefinitionId().contains("checkCreditProcess"));
}
 
Example 5
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testQueryByNameInIgnoreCaseOr() {
  final List<String> taskNameList = new ArrayList<String>(2);
  taskNameList.add("testtask");
  taskNameList.add("gonzotask");

  TaskQuery query = taskService.createTaskQuery().or().taskNameInIgnoreCase(taskNameList).taskId("invalid");
  assertEquals(7, query.list().size());
  assertEquals(7, query.count());

  try {
    query.singleResult();
    fail("expected exception");
  } catch (ActivitiException e) {
    // OK
  }
}
 
Example 6
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testQueryByNameInIgnoreCase() {
  final List<String> taskNameList = new ArrayList<String>(2);
  taskNameList.add("testtask");
  taskNameList.add("gonzotask");

  TaskQuery query = taskService.createTaskQuery().taskNameInIgnoreCase(taskNameList);
  assertEquals(7, query.list().size());
  assertEquals(7, query.count());

  try {
    query.singleResult();
    fail("expected exception");
  } catch (ActivitiException e) {
    // OK
  }
}
 
Example 7
Source File: SubProcessTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * A test case that has a timer attached to the subprocess, where 2 concurrent paths are defined when the timer fires.
 */
@Deployment
public void IGNORE_testSimpleSubProcessWithConcurrentTimer() {

  // After staring the process, the task in the subprocess should be active
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("simpleSubProcessWithConcurrentTimer");
  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(pi.getId()).orderByTaskName().asc();

  Task subProcessTask = taskQuery.singleResult();
  assertEquals("Task in subprocess", subProcessTask.getName());

  // When the timer is fired (after 2 hours), two concurrent paths should be created
  Job job = managementService.createJobQuery().singleResult();
  managementService.executeJob(job.getId());

  List<Task> tasksAfterTimer = taskQuery.list();
  assertEquals(2, tasksAfterTimer.size());
  Task taskAfterTimer1 = tasksAfterTimer.get(0);
  Task taskAfterTimer2 = tasksAfterTimer.get(1);
  assertEquals("Task after timer 1", taskAfterTimer1.getName());
  assertEquals("Task after timer 2", taskAfterTimer2.getName());

  // Completing the two tasks should end the process instance
  taskService.complete(taskAfterTimer1.getId());
  taskService.complete(taskAfterTimer2.getId());
  assertProcessEnded(pi.getId());
}
 
Example 8
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByNameOr() {
  TaskQuery query = taskService.createTaskQuery().or().taskName("testTask").taskId("invalid");
  assertEquals(6, query.list().size());
  assertEquals(6, query.count());

  try {
    query.singleResult();
    fail("expected exception");
  } catch (ActivitiException e) {
    // OK
  }
}
 
Example 9
Source File: CallActivityBasedOnSpringBeansExpressionTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti5/spring/test/expression/callactivity/CallActivityBasedOnSpringBeansExpressionTest.testCallActivityByExpression.bpmn20.xml",
    "org/activiti5/spring/test/expression/callactivity/simpleSubProcess.bpmn20.xml" })
public void testCallActivityByExpression() throws Exception {
  // Start process (main)
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testCallActivityByExpression");

  // one task in the subprocess should be active after starting the
  // process instance
  TaskQuery taskQuery = taskService.createTaskQuery();
  Task taskBeforeSubProcess = taskQuery.singleResult();
  assertEquals("Task before subprocess", taskBeforeSubProcess.getName());

  // Completing the task continues the process which leads to calling the
  // subprocess. The sub process we want to
  // call is passed in as a variable into this task
  taskService.complete(taskBeforeSubProcess.getId());
  Task taskInSubProcess = taskQuery.singleResult();
  assertEquals("Task in subprocess", taskInSubProcess.getName());

  // Completing the task in the subprocess, finishes the subprocess
  taskService.complete(taskInSubProcess.getId());
  Task taskAfterSubProcess = taskQuery.singleResult();
  assertEquals("Task after subprocess", taskAfterSubProcess.getName());

  // Completing this task end the process instance
  taskService.complete(taskAfterSubProcess.getId());
  assertProcessEnded(processInstance.getId());
}
 
Example 10
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByName() {
  TaskQuery query = taskService.createTaskQuery().taskName("testTask");
  assertEquals(6, query.list().size());
  assertEquals(6, query.count());

  try {
    query.singleResult();
    fail("expected exception");
  } catch (ActivitiException e) {
    // OK
  }
}
 
Example 11
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryNoCriteria() {
  TaskQuery query = taskService.createTaskQuery();
  assertEquals(12, query.count());
  assertEquals(12, query.list().size());
  try {
    query.singleResult();
    fail("expected exception");
  } catch (ActivitiException e) {
    // OK
  }
}
 
Example 12
Source File: CallActivityAdvancedTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti5/engine/test/bpmn/callactivity/CallActivity.testCallSimpleSubProcessWithExpressions.bpmn20.xml",
"org/activiti5/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml" })
public void testCallSimpleSubProcessWithExpressions() {

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callSimpleSubProcess");

  // one task in the subprocess should be active after starting the process
  // instance
  TaskQuery taskQuery = taskService.createTaskQuery();
  Task taskBeforeSubProcess = taskQuery.singleResult();
  assertEquals("Task before subprocess", taskBeforeSubProcess.getName());

  // Completing the task continues the process which leads to calling the
  // subprocess. The sub process we want to call is passed in as a variable
  // into this task
  taskService.setVariable(taskBeforeSubProcess.getId(), "simpleSubProcessExpression", "simpleSubProcess");
  taskService.complete(taskBeforeSubProcess.getId());
  Task taskInSubProcess = taskQuery.singleResult();
  assertEquals("Task in subprocess", taskInSubProcess.getName());

  // Completing the task in the subprocess, finishes the subprocess
  taskService.complete(taskInSubProcess.getId());
  Task taskAfterSubProcess = taskQuery.singleResult();
  assertEquals("Task after subprocess", taskAfterSubProcess.getName());

  // Completing this task end the process instance
  taskService.complete(taskAfterSubProcess.getId());
  assertProcessEnded(processInstance.getId());
}
 
Example 13
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByPriority() {
  TaskQuery query = taskService.createTaskQuery().taskPriority(10);
  assertEquals(2, query.list().size());
  assertEquals(2, query.count());

  try {
    query.singleResult();
    fail();
  } catch (ActivitiException e) {
  }

  query = taskService.createTaskQuery().taskPriority(100);
  assertNull(query.singleResult());
  assertEquals(0, query.list().size());
  assertEquals(0, query.count());

  query = taskService.createTaskQuery().taskMinPriority(50);
  assertEquals(3, query.list().size());

  query = taskService.createTaskQuery().taskMinPriority(10);
  assertEquals(5, query.list().size());

  query = taskService.createTaskQuery().taskMaxPriority(10);
  assertEquals(9, query.list().size());

  query = taskService.createTaskQuery().taskMaxPriority(3);
  assertEquals(6, query.list().size());
}
 
Example 14
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testParallel() {
	if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
   ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
   TaskQuery taskQuery = taskService.createTaskQuery();
   Task userTask = taskQuery.singleResult();
   assertEquals("userTask1", userTask.getName());
   
   taskService.complete(userTask.getId(), CollectionUtil.singletonMap("myVar", "test789"));
   
   assertProcessEnded(processInstance.getId());
   
   List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc().list();
   assertEquals(2, variables.size());
   
   HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
   assertEquals("myVar", historicVariable.getName());
   assertEquals("test789", historicVariable.getTextValue());
   
   HistoricVariableInstanceEntity historicVariable1 = (HistoricVariableInstanceEntity) variables.get(1);
   assertEquals("myVar1", historicVariable1.getName());
   assertEquals("test456", historicVariable1.getTextValue());
   
   assertEquals(8, historyService.createHistoricActivityInstanceQuery().count());
   assertEquals(5, historyService.createHistoricDetailQuery().count());
	}
}
 
Example 15
Source File: CallActivityAdvancedTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/callactivity/CallActivity.testCallSimpleSubProcessWithExpressions.bpmn20.xml",
    "org/activiti/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml" })
public void testCallSimpleSubProcessWithExpressions() {

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callSimpleSubProcess");

  // one task in the subprocess should be active after starting the
  // process
  // instance
  TaskQuery taskQuery = taskService.createTaskQuery();
  Task taskBeforeSubProcess = taskQuery.singleResult();
  assertEquals("Task before subprocess", taskBeforeSubProcess.getName());

  // Completing the task continues the process which leads to calling the
  // subprocess. The sub process we want to call is passed in as a
  // variable
  // into this task
  taskService.setVariable(taskBeforeSubProcess.getId(), "simpleSubProcessExpression", "simpleSubProcess");
  taskService.complete(taskBeforeSubProcess.getId());
  Task taskInSubProcess = taskQuery.singleResult();
  assertEquals("Task in subprocess", taskInSubProcess.getName());

  // Completing the task in the subprocess, finishes the subprocess
  taskService.complete(taskInSubProcess.getId());
  Task taskAfterSubProcess = taskQuery.singleResult();
  assertEquals("Task after subprocess", taskAfterSubProcess.getName());

  // Completing this task end the process instance
  taskService.complete(taskAfterSubProcess.getId());
  assertProcessEnded(processInstance.getId());
}
 
Example 16
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByCandidateGroupOr() {
  TaskQuery query = taskService.createTaskQuery().or().taskId("invalid").taskCandidateGroup("management");
  assertEquals(3, query.count());
  assertEquals(3, query.list().size());
  try {
    query.singleResult();
    fail("expected exception");
  } catch (ActivitiException e) {
    // OK
  }

  query = taskService.createTaskQuery().or().taskId("invalid").taskCandidateGroup("sales");
  assertEquals(0, query.count());
  assertEquals(0, query.list().size());
}
 
Example 17
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByCandidateGroupIn() {
  List<String> groups = Arrays.asList("management", "accountancy");
  TaskQuery query = taskService.createTaskQuery().taskCandidateGroupIn(groups);
  assertEquals(5, query.count());
  assertEquals(5, query.list().size());
  
  try {
    query.singleResult();
    fail("expected exception");
  } catch (ActivitiException e) {
    // OK
  }
  
  query = taskService.createTaskQuery().taskCandidateUser("kermit").taskCandidateGroupIn(groups);
  assertEquals(11, query.count());
  assertEquals(11, query.list().size());
  
  query = taskService.createTaskQuery().taskCandidateUser("kermit").taskCandidateGroup("unexisting");
  assertEquals(6, query.count());
  assertEquals(6, query.list().size());
  
  query = taskService.createTaskQuery().taskCandidateUser("unexisting").taskCandidateGroup("unexisting");
  assertEquals(0, query.count());
  assertEquals(0, query.list().size());

  // Unexisting groups or groups that don't have candidate tasks shouldn't influence other results
  groups = Arrays.asList("management", "accountancy", "sales", "unexising");
  query = taskService.createTaskQuery().taskCandidateGroupIn(groups);
  assertEquals(5, query.count());
  assertEquals(5, query.list().size());
}
 
Example 18
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByCandidateGroupInOr() {
  List<String> groups = Arrays.asList("management", "accountancy");
  TaskQuery query = taskService.createTaskQuery().or().taskId("invalid").taskCandidateGroupIn(groups);
  assertEquals(5, query.count());
  assertEquals(5, query.list().size());
  
  try {
    query.singleResult();
    fail("expected exception");
  } catch (ActivitiException e) {
    // OK
  }
  
  query = taskService.createTaskQuery().or().taskCandidateUser("kermit").taskCandidateGroupIn(groups).endOr();
  assertEquals(11, query.count());
  assertEquals(11, query.list().size());
  
  query = taskService.createTaskQuery().or().taskCandidateUser("kermit").taskCandidateGroup("unexisting").endOr();
  assertEquals(6, query.count());
  assertEquals(6, query.list().size());
  
  query = taskService.createTaskQuery().or().taskCandidateUser("unexisting").taskCandidateGroup("unexisting").endOr();
  assertEquals(0, query.count());
  assertEquals(0, query.list().size());
  
  query = taskService.createTaskQuery().or().taskCandidateUser("kermit").taskCandidateGroupIn(groups).endOr()
      .or().taskCandidateUser("gonzo").taskCandidateGroupIn(groups);
  assertEquals(5, query.count());
  assertEquals(5, query.list().size());
  
  // Unexisting groups or groups that don't have candidate tasks shouldn't influence other results
  groups = Arrays.asList("management", "accountancy", "sales", "unexising");
  query = taskService.createTaskQuery().or().taskId("invalid").taskCandidateGroupIn(groups);
  assertEquals(5, query.count());
  assertEquals(5, query.list().size());
}
 
Example 19
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testParallel() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task userTask = taskQuery.singleResult();
    assertEquals("userTask1", userTask.getName());

    taskService.complete(userTask.getId(), CollectionUtil.singletonMap("myVar", "test789"));

    assertProcessEnded(processInstance.getId());

    List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc().list();
    assertEquals(2, variables.size());

    HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
    assertEquals("myVar", historicVariable.getName());
    assertEquals("test789", historicVariable.getTextValue());

    HistoricVariableInstanceEntity historicVariable1 = (HistoricVariableInstanceEntity) variables.get(1);
    assertEquals("myVar1", historicVariable1.getName());
    assertEquals("test456", historicVariable1.getTextValue());

    assertEquals(8, historyService.createHistoricActivityInstanceQuery().count());
    assertEquals(5, historyService.createHistoricDetailQuery().count());
  }
}
 
Example 20
Source File: CallActivityAdvancedTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for handing over process variables to a sub process
 */
@Deployment(resources = { "org/activiti/engine/test/bpmn/callactivity/CallActivity.testSubProcessDataInputOutput.bpmn20.xml",
    "org/activiti/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml" })
public void testSubProcessWithDataInputOutput() {
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("superVariable", "Hello from the super process.");

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("subProcessDataInputOutput", vars);

  // one task in the subprocess should be active after starting the
  // process instance
  TaskQuery taskQuery = taskService.createTaskQuery();
  Task taskBeforeSubProcess = taskQuery.singleResult();
  assertEquals("Task in subprocess", taskBeforeSubProcess.getName());
  assertEquals("Hello from the super process.", runtimeService.getVariable(taskBeforeSubProcess.getProcessInstanceId(), "subVariable"));
  assertEquals("Hello from the super process.", taskService.getVariable(taskBeforeSubProcess.getId(), "subVariable"));

  runtimeService.setVariable(taskBeforeSubProcess.getProcessInstanceId(), "subVariable", "Hello from sub process.");

  // super variable is unchanged
  assertEquals("Hello from the super process.", runtimeService.getVariable(processInstance.getId(), "superVariable"));

  // Completing this task ends the subprocess which leads to a task in the
  // super process
  taskService.complete(taskBeforeSubProcess.getId());

  // one task in the subprocess should be active after starting the
  // process instance
  Task taskAfterSubProcess = taskQuery.singleResult();
  assertEquals("Task in super process", taskAfterSubProcess.getName());
  assertEquals("Hello from sub process.", runtimeService.getVariable(processInstance.getId(), "superVariable"));
  assertEquals("Hello from sub process.", taskService.getVariable(taskAfterSubProcess.getId(), "superVariable"));

  vars.clear();
  vars.put("x", 5l);

  // Completing this task ends the super process which leads to a task in
  // the super process
  taskService.complete(taskAfterSubProcess.getId(), vars);

  // now we are the second time in the sub process but passed variables
  // via expressions
  Task taskInSecondSubProcess = taskQuery.singleResult();
  assertEquals("Task in subprocess", taskInSecondSubProcess.getName());
  assertEquals(10l, runtimeService.getVariable(taskInSecondSubProcess.getProcessInstanceId(), "y"));
  assertEquals(10l, taskService.getVariable(taskInSecondSubProcess.getId(), "y"));

  // Completing this task ends the subprocess which leads to a task in the
  // super process
  taskService.complete(taskInSecondSubProcess.getId());

  // one task in the subprocess should be active after starting the
  // process instance
  Task taskAfterSecondSubProcess = taskQuery.singleResult();
  assertEquals("Task in super process", taskAfterSecondSubProcess.getName());
  assertEquals(15l, runtimeService.getVariable(taskAfterSecondSubProcess.getProcessInstanceId(), "z"));
  assertEquals(15l, taskService.getVariable(taskAfterSecondSubProcess.getId(), "z"));

  // and end last task in Super process
  taskService.complete(taskAfterSecondSubProcess.getId());

  assertProcessEnded(processInstance.getId());
  assertEquals(0, runtimeService.createExecutionQuery().list().size());
}