use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.
the class TaskAndVariablesQueryTest method testOrQueryMultipleVariableValues.
@Deployment
public void testOrQueryMultipleVariableValues() {
Map<String, Object> startMap = new HashMap<String, Object>();
startMap.put("aProcessVar", 1);
startMap.put("anotherProcessVar", 123);
runtimeService.startProcessInstanceByKey("oneTaskProcess", startMap);
TaskQuery query0 = taskService.createTaskQuery().includeProcessVariables().or();
for (int i = 0; i < 20; i++) {
query0 = query0.processVariableValueEquals("anotherProcessVar", i);
}
query0 = query0.endOr();
assertNull(query0.singleResult());
TaskQuery query1 = taskService.createTaskQuery().includeProcessVariables().or().processVariableValueEquals("anotherProcessVar", 123);
for (int i = 0; i < 20; i++) {
query1 = query1.processVariableValueEquals("anotherProcessVar", i);
}
query1 = query1.endOr();
Task task = query1.singleResult();
assertEquals(2, task.getProcessVariables().size());
assertEquals(123, task.getProcessVariables().get("anotherProcessVar"));
}
use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.
the class CallActivityTest method testOrderProcessWithCallActivity.
@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();
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());
}
use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.
the class ParallelGatewayTest method testUnbalancedForkJoin.
@Deployment
public void testUnbalancedForkJoin() {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("UnbalancedForkJoin");
TaskQuery query = taskService.createTaskQuery().processInstanceId(pi.getId()).orderByTaskName().asc();
List<Task> tasks = query.list();
assertEquals(3, tasks.size());
// the tasks are ordered by name (see above)
Task task1 = tasks.get(0);
assertEquals("Task 1", task1.getName());
Task task2 = tasks.get(1);
assertEquals("Task 2", task2.getName());
// Completing the first task should *not* trigger the join
taskService.complete(task1.getId());
// Completing the second task should trigger the first join
taskService.complete(task2.getId());
tasks = query.list();
Task task3 = tasks.get(0);
assertEquals(2, tasks.size());
assertEquals("Task 3", task3.getName());
Task task4 = tasks.get(1);
assertEquals("Task 4", task4.getName());
// Completing the remaing tasks should trigger the second join and end the process
taskService.complete(task3.getId());
taskService.complete(task4.getId());
assertProcessEnded(pi.getId());
}
use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.
the class CallActivityBasedOnSpringBeansExpressionTest method testCallActivityByExpression.
@Deployment(resources = { "org/activiti/spring/test/expression/callactivity/CallActivityBasedOnSpringBeansExpressionTest.testCallActivityByExpression.bpmn20.xml", "org/activiti/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());
}
use of org.activiti.engine.task.TaskQuery in project Activiti by Activiti.
the class SubProcessTest method testTwoNestedSubProcessesInParallelWithTimer.
@Deployment
public void testTwoNestedSubProcessesInParallelWithTimer() {
// Date startTime = new Date();
ProcessInstance pi = runtimeService.startProcessInstanceByKey("nestedParallelSubProcessesWithTimer");
TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(pi.getId()).orderByTaskName().asc();
List<Task> tasks = taskQuery.list();
// After process start, both tasks in the subprocesses should be active
Task taskA = tasks.get(0);
Task taskB = tasks.get(1);
assertEquals("Task in subprocess A", taskA.getName());
assertEquals("Task in subprocess B", taskB.getName());
// Firing the timer should destroy all three subprocesses and activate the task after the timer
// processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + (2 * 60 * 60 * 1000 ) + 1000));
// waitForJobExecutorToProcessAllJobs(5000L, 50L);
Job job = managementService.createJobQuery().singleResult();
managementService.executeJob(job.getId());
Task taskAfterTimer = taskQuery.singleResult();
assertEquals("Task after timer", taskAfterTimer.getName());
// Completing the task should end the process instance
taskService.complete(taskAfterTimer.getId());
assertProcessEnded(pi.getId());
}
Aggregations