use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class ProcessInstanceQueryTest method testQueryBySubProcessInstanceIdNested.
//Nested subprocess make the query complexer, hence this test
@Deployment(resources = { "org/activiti/engine/test/api/runtime/superProcessWithNestedSubProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/nestedSubProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/subProcess.bpmn20.xml" })
public void testQueryBySubProcessInstanceIdNested() {
ProcessInstance superProcessInstance = runtimeService.startProcessInstanceByKey("nestedSubProcessQueryTest");
ProcessInstance subProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId(superProcessInstance.getId()).singleResult();
assertEquals(superProcessInstance.getId(), runtimeService.createProcessInstanceQuery().subProcessInstanceId(subProcessInstance.getId()).singleResult().getId());
ProcessInstance nestedSubProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId(subProcessInstance.getId()).singleResult();
assertEquals(subProcessInstance.getId(), runtimeService.createProcessInstanceQuery().subProcessInstanceId(nestedSubProcessInstance.getId()).singleResult().getId());
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class ProcessInstanceQueryTest method testQueryDateVariable.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryDateVariable() throws Exception {
Map<String, Object> vars = new HashMap<String, Object>();
Date date1 = Calendar.getInstance().getTime();
vars.put("dateVar", date1);
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
Calendar cal2 = Calendar.getInstance();
cal2.add(Calendar.SECOND, 1);
Date date2 = cal2.getTime();
vars = new HashMap<String, Object>();
vars.put("dateVar", date1);
vars.put("dateVar2", date2);
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
vars = new HashMap<String, Object>();
vars.put("dateVar", nextYear.getTime());
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
Calendar nextMonth = Calendar.getInstance();
nextMonth.add(Calendar.MONTH, 1);
Calendar twoYearsLater = Calendar.getInstance();
twoYearsLater.add(Calendar.YEAR, 2);
Calendar oneYearAgo = Calendar.getInstance();
oneYearAgo.add(Calendar.YEAR, -1);
// Query on single short variable, should result in 2 matches
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("dateVar", date1);
List<ProcessInstance> processInstances = query.list();
assertNotNull(processInstances);
assertEquals(2, processInstances.size());
// Query on two short variables, should result in single value
query = runtimeService.createProcessInstanceQuery().variableValueEquals("dateVar", date1).variableValueEquals("dateVar2", date2);
ProcessInstance resultInstance = query.singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance2.getId(), resultInstance.getId());
// Query with unexisting variable value
Date unexistingDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/01/1989 12:00:00");
resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("dateVar", unexistingDate).singleResult();
assertNull(resultInstance);
// Test NOT_EQUALS
resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("dateVar", date1).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
// Test GREATER_THAN
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("dateVar", nextMonth.getTime()).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("dateVar", nextYear.getTime()).count());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("dateVar", oneYearAgo.getTime()).count());
// Test GREATER_THAN_OR_EQUAL
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("dateVar", nextMonth.getTime()).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("dateVar", nextYear.getTime()).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("dateVar", oneYearAgo.getTime()).count());
// Test LESS_THAN
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("dateVar", nextYear.getTime()).list();
assertEquals(2, processInstances.size());
List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
List<String> ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("dateVar", date1).count());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("dateVar", twoYearsLater.getTime()).count());
// Test LESS_THAN_OR_EQUAL
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("dateVar", nextYear.getTime()).list();
assertEquals(3, processInstances.size());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("dateVar", oneYearAgo.getTime()).count());
// Test value-only matching
resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(nextYear.getTime()).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
processInstances = runtimeService.createProcessInstanceQuery().variableValueEquals(date1).list();
assertEquals(2, processInstances.size());
expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(twoYearsLater.getTime()).singleResult();
assertNull(resultInstance);
runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class ProcessInstanceSuspensionTest method testCannotActivateActiveProcessInstance.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testCannotActivateActiveProcessInstance() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
runtimeService.startProcessInstanceByKey(processDefinition.getKey());
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
assertFalse(processInstance.isSuspended());
try {
//activate
runtimeService.activateProcessInstanceById(processInstance.getId());
fail("Expected activiti exception");
} catch (ActivitiException e) {
// expected
}
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class ProcessInstanceSuspensionTest method testChildExecutionsSuspendedAfterProcessInstanceSuspend.
@Deployment
public void testChildExecutionsSuspendedAfterProcessInstanceSuspend() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testChildExecutionsSuspended");
runtimeService.suspendProcessInstanceById(processInstance.getId());
List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
for (Execution execution : executions) {
assertTrue(execution.isSuspended());
}
// Activate again
runtimeService.activateProcessInstanceById(processInstance.getId());
executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
for (Execution execution : executions) {
assertFalse(execution.isSuspended());
}
// Finish process
while (taskService.createTaskQuery().count() > 0) {
for (Task task : taskService.createTaskQuery().list()) {
taskService.complete(task.getId());
}
}
assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class ExecutionQueryTest method testExecutionQueryWithProcessVariable.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/concurrentExecution.bpmn20.xml" })
public void testExecutionQueryWithProcessVariable() {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("x", "parent");
variables.put("xIgnoreCase", "PaReNt");
ProcessInstance pi = runtimeService.startProcessInstanceByKey("concurrent", variables);
List<Execution> concurrentExecutions = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).list();
assertEquals(3, concurrentExecutions.size());
for (Execution execution : concurrentExecutions) {
if (!((ExecutionEntity) execution).isProcessInstanceType()) {
// only the concurrent executions, not the root one, would be cooler to query that directly, see https://activiti.atlassian.net/browse/ACT-1373
runtimeService.setVariableLocal(execution.getId(), "x", "child");
runtimeService.setVariableLocal(execution.getId(), "xIgnoreCase", "ChILD");
}
}
assertEquals(2, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).variableValueEquals("x", "child").count());
assertEquals(1, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).variableValueEquals("x", "parent").count());
assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEquals("x", "parent").count());
assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueNotEquals("x", "xxx").count());
// Test value-only query
assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEquals("child").count());
assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEquals("parent").count());
// Test ignore-case queries
assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEqualsIgnoreCase("xIgnoreCase", "CHILD").count());
assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEqualsIgnoreCase("xIgnoreCase", "PARENT").count());
// Test ignore-case queries
assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueNotEqualsIgnoreCase("xIgnoreCase", "paRent").count());
assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueNotEqualsIgnoreCase("xIgnoreCase", "chilD").count());
}
Aggregations