Search in sources :

Example 46 with ProcessInstanceQuery

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());
}
Also used : ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) Test(org.junit.Test)

Example 47 with ProcessInstanceQuery

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);
}
Also used : Task(org.camunda.bpm.engine.task.Task) ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 48 with ProcessInstanceQuery

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
    }
}
Also used : ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Test(org.junit.Test)

Example 49 with ProcessInstanceQuery

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());
}
Also used : ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Date(java.util.Date) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 50 with ProcessInstanceQuery

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());
}
Also used : ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) Test(org.junit.Test)

Aggregations

ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)201 Test (org.junit.Test)127 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)59 Deployment (org.camunda.bpm.engine.test.Deployment)42 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)34 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)27 HashMap (java.util.HashMap)24 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)19 Batch (org.camunda.bpm.engine.batch.Batch)18 JobQuery (org.camunda.bpm.engine.runtime.JobQuery)17 ArrayList (java.util.ArrayList)16 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)15 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)15 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)14 ExecutionQuery (org.camunda.bpm.engine.runtime.ExecutionQuery)12 HistoricProcessInstanceQueryDto (org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto)9 Job (org.camunda.bpm.engine.runtime.Job)9 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)8 AbstractAsyncOperationsTest (org.camunda.bpm.engine.test.api.AbstractAsyncOperationsTest)8 Response (com.jayway.restassured.response.Response)7