use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class ProcessInstanceQueryTest method testQueryByProcessDefinitionKeySingleResult.
@Test
public void testQueryByProcessDefinitionKeySingleResult() {
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processDefinitionKey(PROCESS_DEFINITION_KEY_2);
assertEquals(1, query.count());
assertEquals(1, query.list().size());
assertNotNull(query.singleResult());
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class ProcessInstanceQueryTest method testQueryByLeafActivityId.
@Test
public void testQueryByLeafActivityId() {
// given
ProcessDefinition oneTaskDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
ProcessDefinition gatewaySubProcessDefinition = testHelper.deployAndGetDefinition(FORK_JOIN_SUB_PROCESS_MODEL);
// when
ProcessInstance oneTaskInstance1 = runtimeService.startProcessInstanceById(oneTaskDefinition.getId());
ProcessInstance oneTaskInstance2 = runtimeService.startProcessInstanceById(oneTaskDefinition.getId());
ProcessInstance gatewaySubProcessInstance1 = runtimeService.startProcessInstanceById(gatewaySubProcessDefinition.getId());
ProcessInstance gatewaySubProcessInstance2 = runtimeService.startProcessInstanceById(gatewaySubProcessDefinition.getId());
Task task = engineRule.getTaskService().createTaskQuery().processInstanceId(gatewaySubProcessInstance2.getId()).taskName("completeMe").singleResult();
engineRule.getTaskService().complete(task.getId());
// then
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().activityIdIn("userTask");
assertReturnedProcessInstances(query, oneTaskInstance1, oneTaskInstance2);
query = runtimeService.createProcessInstanceQuery().activityIdIn("userTask1", "userTask2");
assertReturnedProcessInstances(query, gatewaySubProcessInstance1, gatewaySubProcessInstance2);
query = runtimeService.createProcessInstanceQuery().activityIdIn("userTask", "userTask1");
assertReturnedProcessInstances(query, oneTaskInstance1, oneTaskInstance2, gatewaySubProcessInstance1);
query = runtimeService.createProcessInstanceQuery().activityIdIn("userTask", "userTask1", "userTask2");
assertReturnedProcessInstances(query, oneTaskInstance1, oneTaskInstance2, gatewaySubProcessInstance1, gatewaySubProcessInstance2);
query = runtimeService.createProcessInstanceQuery().activityIdIn("join");
assertReturnedProcessInstances(query, gatewaySubProcessInstance2);
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class ProcessInstanceQueryTest method testQueryByProcessDefinitionKeyMultipleResults.
@Test
public void testQueryByProcessDefinitionKeyMultipleResults() {
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processDefinitionKey(PROCESS_DEFINITION_KEY);
assertEquals(4, query.count());
assertEquals(4, query.list().size());
try {
query.singleResult();
fail();
} catch (ProcessEngineException e) {
// Exception is expected
}
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class ProcessInstanceQueryTest method testQueryVariablesUpdatedToNullValue.
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryVariablesUpdatedToNullValue() {
// Start process instance with different types of variables
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("longVar", 928374L);
variables.put("shortVar", (short) 123);
variables.put("integerVar", 1234);
variables.put("stringVar", "coca-cola");
variables.put("dateVar", new Date());
variables.put("booleanVar", true);
variables.put("nullVar", null);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("longVar", null).variableValueEquals("shortVar", null).variableValueEquals("integerVar", null).variableValueEquals("stringVar", null).variableValueEquals("booleanVar", null).variableValueEquals("dateVar", null);
ProcessInstanceQuery notQuery = runtimeService.createProcessInstanceQuery().variableValueNotEquals("longVar", null).variableValueNotEquals("shortVar", null).variableValueNotEquals("integerVar", null).variableValueNotEquals("stringVar", null).variableValueNotEquals("booleanVar", null).variableValueNotEquals("dateVar", null);
assertNull(query.singleResult());
assertNotNull(notQuery.singleResult());
// Set all existing variables values to null
runtimeService.setVariable(processInstance.getId(), "longVar", null);
runtimeService.setVariable(processInstance.getId(), "shortVar", null);
runtimeService.setVariable(processInstance.getId(), "integerVar", null);
runtimeService.setVariable(processInstance.getId(), "stringVar", null);
runtimeService.setVariable(processInstance.getId(), "dateVar", null);
runtimeService.setVariable(processInstance.getId(), "nullVar", null);
runtimeService.setVariable(processInstance.getId(), "booleanVar", null);
Execution queryResult = query.singleResult();
assertNotNull(queryResult);
assertEquals(processInstance.getId(), queryResult.getId());
assertNull(notQuery.singleResult());
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class ProcessInstanceQueryTest method testQueryByActive.
@Test
public void testQueryByActive() throws Exception {
ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery();
assertEquals(5, processInstanceQuery.active().count());
repositoryService.suspendProcessDefinitionByKey(PROCESS_DEFINITION_KEY);
assertEquals(5, processInstanceQuery.active().count());
repositoryService.suspendProcessDefinitionByKey(PROCESS_DEFINITION_KEY, true, null);
assertEquals(1, processInstanceQuery.active().count());
}
Aggregations