Search in sources :

Example 56 with ExecutionQuery

use of org.camunda.bpm.engine.runtime.ExecutionQuery in project camunda-bpm-platform by camunda.

the class ExecutionAuthorizationTest method testQueryShouldReturnAllExecutions.

public void testQueryShouldReturnAllExecutions() {
    // given
    ProcessInstance processInstance = startProcessInstanceByKey(MESSAGE_BOUNDARY_PROCESS_KEY);
    createGrantAuthorization(PROCESS_INSTANCE, processInstance.getId(), userId, READ);
    // when
    ExecutionQuery query = runtimeService.createExecutionQuery();
    // then
    verifyQueryResults(query, 2);
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ExecutionQuery(org.camunda.bpm.engine.runtime.ExecutionQuery)

Example 57 with ExecutionQuery

use of org.camunda.bpm.engine.runtime.ExecutionQuery in project camunda-bpm-platform by camunda.

the class ExecutionQueryTest method testQueryByProcessInstanceId.

public void testQueryByProcessInstanceId() {
    for (String processInstanceId : concurrentProcessInstanceIds) {
        ExecutionQuery query = runtimeService.createExecutionQuery().processInstanceId(processInstanceId);
        assertEquals(3, query.list().size());
        assertEquals(3, query.count());
    }
    assertEquals(1, runtimeService.createExecutionQuery().processInstanceId(sequentialProcessInstanceIds.get(0)).list().size());
}
Also used : ExecutionQuery(org.camunda.bpm.engine.runtime.ExecutionQuery)

Example 58 with ExecutionQuery

use of org.camunda.bpm.engine.runtime.ExecutionQuery in project camunda-bpm-platform by camunda.

the class ExecutionQueryTest method testQueryDateVariable.

@Deployment(resources = { "org/camunda/bpm/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);
    Date date2 = Calendar.getInstance().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
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("dateVar", date1);
    List<Execution> executions = query.list();
    Assert.assertNotNull(executions);
    Assert.assertEquals(2, executions.size());
    // Query on two short variables, should result in single value
    query = runtimeService.createExecutionQuery().variableValueEquals("dateVar", date1).variableValueEquals("dateVar2", date2);
    Execution execution = query.singleResult();
    Assert.assertNotNull(execution);
    Assert.assertEquals(processInstance2.getId(), execution.getId());
    // Query with unexisting variable value
    Date unexistingDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/01/1989 12:00:00");
    execution = runtimeService.createExecutionQuery().variableValueEquals("dateVar", unexistingDate).singleResult();
    Assert.assertNull(execution);
    // Test NOT_EQUALS
    execution = runtimeService.createExecutionQuery().variableValueNotEquals("dateVar", date1).singleResult();
    Assert.assertNotNull(execution);
    Assert.assertEquals(processInstance3.getId(), execution.getId());
    // Test GREATER_THAN
    execution = runtimeService.createExecutionQuery().variableValueGreaterThan("dateVar", nextMonth.getTime()).singleResult();
    Assert.assertNotNull(execution);
    Assert.assertEquals(processInstance3.getId(), execution.getId());
    Assert.assertEquals(0, runtimeService.createExecutionQuery().variableValueGreaterThan("dateVar", nextYear.getTime()).count());
    Assert.assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThan("dateVar", oneYearAgo.getTime()).count());
    // Test GREATER_THAN_OR_EQUAL
    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("dateVar", nextMonth.getTime()).singleResult();
    Assert.assertNotNull(execution);
    Assert.assertEquals(processInstance3.getId(), execution.getId());
    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("dateVar", nextYear.getTime()).singleResult();
    Assert.assertNotNull(execution);
    Assert.assertEquals(processInstance3.getId(), execution.getId());
    Assert.assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("dateVar", oneYearAgo.getTime()).count());
    // Test LESS_THAN
    executions = runtimeService.createExecutionQuery().variableValueLessThan("dateVar", nextYear.getTime()).list();
    Assert.assertEquals(2, executions.size());
    List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
    List<String> ids = new ArrayList<String>(Arrays.asList(executions.get(0).getId(), executions.get(1).getId()));
    ids.removeAll(expecedIds);
    assertTrue(ids.isEmpty());
    Assert.assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThan("dateVar", date1).count());
    Assert.assertEquals(3, runtimeService.createExecutionQuery().variableValueLessThan("dateVar", twoYearsLater.getTime()).count());
    // Test LESS_THAN_OR_EQUAL
    executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("dateVar", nextYear.getTime()).list();
    Assert.assertEquals(3, executions.size());
    Assert.assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThanOrEqual("dateVar", oneYearAgo.getTime()).count());
    runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
Also used : HashMap(java.util.HashMap) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ExecutionQuery(org.camunda.bpm.engine.runtime.ExecutionQuery) Date(java.util.Date) Execution(org.camunda.bpm.engine.runtime.Execution) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SimpleDateFormat(java.text.SimpleDateFormat) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 59 with ExecutionQuery

use of org.camunda.bpm.engine.runtime.ExecutionQuery in project camunda-bpm-platform by camunda.

the class ExecutionQueryTest method testQueryVariablesUpdatedToNullValue.

@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("booleanVar", true);
    variables.put("dateVar", new Date());
    variables.put("nullVar", null);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("longVar", null).variableValueEquals("shortVar", null).variableValueEquals("integerVar", null).variableValueEquals("stringVar", null).variableValueEquals("booleanVar", null).variableValueEquals("dateVar", null);
    ExecutionQuery notQuery = runtimeService.createExecutionQuery().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(), "booleanVar", null);
    runtimeService.setVariable(processInstance.getId(), "dateVar", null);
    runtimeService.setVariable(processInstance.getId(), "nullVar", null);
    Execution queryResult = query.singleResult();
    assertNotNull(queryResult);
    assertEquals(processInstance.getId(), queryResult.getId());
    assertNull(notQuery.singleResult());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ExecutionQuery(org.camunda.bpm.engine.runtime.ExecutionQuery) Date(java.util.Date) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ExecutionQuery (org.camunda.bpm.engine.runtime.ExecutionQuery)59 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)27 Deployment (org.camunda.bpm.engine.test.Deployment)26 Execution (org.camunda.bpm.engine.runtime.Execution)17 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)17 JobQuery (org.camunda.bpm.engine.runtime.JobQuery)14 ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)12 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)7 Job (org.camunda.bpm.engine.runtime.Job)6 Test (org.junit.Test)4 Date (java.util.Date)2 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 CountResultDto (org.camunda.bpm.engine.rest.dto.CountResultDto)1 ExecutionDto (org.camunda.bpm.engine.rest.dto.runtime.ExecutionDto)1 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)1 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)1