Search in sources :

Example 21 with ExecutionQuery

use of org.activiti.engine.runtime.ExecutionQuery in project Activiti by Activiti.

the class ExecutionQueryTest method testQueryLongVariable.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryLongVariable() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("longVar", 12345L);
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("longVar", 12345L);
    vars.put("longVar2", 67890L);
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("longVar", 55555L);
    ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    // Query on single long variable, should result in 2 matches
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("longVar", 12345L);
    List<Execution> executions = query.list();
    assertThat(executions).isNotNull();
    assertThat(executions).hasSize(2);
    // Query on two long variables, should result in single match
    query = runtimeService.createExecutionQuery().variableValueEquals("longVar", 12345L).variableValueEquals("longVar2", 67890L);
    Execution execution = query.singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance2.getId());
    // Query with unexisting variable value
    execution = runtimeService.createExecutionQuery().variableValueEquals("longVar", 999L).singleResult();
    assertThat(execution).isNull();
    // Test NOT_EQUALS
    execution = runtimeService.createExecutionQuery().variableValueNotEquals("longVar", 12345L).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    // Test GREATER_THAN
    execution = runtimeService.createExecutionQuery().variableValueGreaterThan("longVar", 44444L).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    assertThat(runtimeService.createExecutionQuery().variableValueGreaterThan("longVar", 55555L).count()).isEqualTo(0);
    assertThat(runtimeService.createExecutionQuery().variableValueGreaterThan("longVar", 1L).count()).isEqualTo(3);
    // Test GREATER_THAN_OR_EQUAL
    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("longVar", 44444L).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("longVar", 55555L).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    assertThat(runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("longVar", 1L).count()).isEqualTo(3);
    // Test LESS_THAN
    executions = runtimeService.createExecutionQuery().variableValueLessThan("longVar", 55555L).list();
    assertThat(executions).hasSize(2);
    List<String> expectedIds = asList(processInstance1.getId(), processInstance2.getId());
    List<String> ids = new ArrayList<String>(asList(executions.get(0).getId(), executions.get(1).getId()));
    ids.removeAll(expectedIds);
    assertThat(ids.isEmpty()).isTrue();
    assertThat(runtimeService.createExecutionQuery().variableValueLessThan("longVar", 12345L).count()).isEqualTo(0);
    assertThat(runtimeService.createExecutionQuery().variableValueLessThan("longVar", 66666L).count()).isEqualTo(3);
    // Test LESS_THAN_OR_EQUAL
    executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("longVar", 55555L).list();
    assertThat(executions).hasSize(3);
    assertThat(runtimeService.createExecutionQuery().variableValueLessThanOrEqual("longVar", 12344L).count()).isEqualTo(0);
    // Test value-only matching
    execution = runtimeService.createExecutionQuery().variableValueEquals(55555L).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    executions = runtimeService.createExecutionQuery().variableValueEquals(12345L).list();
    assertThat(executions).hasSize(2);
    expectedIds = asList(processInstance1.getId(), processInstance2.getId());
    ids = new ArrayList<String>(asList(executions.get(0).getId(), executions.get(1).getId()));
    ids.removeAll(expectedIds);
    assertThat(ids.isEmpty()).isTrue();
    execution = runtimeService.createExecutionQuery().variableValueEquals(99999L).singleResult();
    assertThat(execution).isNull();
    runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery) Deployment(org.activiti.engine.test.Deployment)

Example 22 with ExecutionQuery

use of org.activiti.engine.runtime.ExecutionQuery in project Activiti by Activiti.

the class ExecutionQueryTest method testQueryByInvalidProcessDefinitionName.

public void testQueryByInvalidProcessDefinitionName() {
    ExecutionQuery query = runtimeService.createExecutionQuery().processDefinitionName("invalid");
    assertThat(query.singleResult()).isNull();
    assertThat(query.list()).hasSize(0);
    assertThat(query.count()).isEqualTo(0);
}
Also used : ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery)

Example 23 with ExecutionQuery

use of org.activiti.engine.runtime.ExecutionQuery in project Activiti by Activiti.

the class ExecutionQueryTest method testQueryByInvalidExecutionId.

public void testQueryByInvalidExecutionId() {
    ExecutionQuery query = runtimeService.createExecutionQuery().executionId("invalid");
    assertThat(query.singleResult()).isNull();
    assertThat(query.list()).hasSize(0);
    assertThat(query.count()).isEqualTo(0);
}
Also used : ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery)

Example 24 with ExecutionQuery

use of org.activiti.engine.runtime.ExecutionQuery in project Activiti by Activiti.

the class ExecutionQueryTest method testQueryIntegerVariable.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryIntegerVariable() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("integerVar", 12345);
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("integerVar", 12345);
    vars.put("integerVar2", 67890);
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("integerVar", 55555);
    ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    // Query on single integer variable, should result in 2 matches
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("integerVar", 12345);
    List<Execution> executions = query.list();
    assertThat(executions).isNotNull();
    assertThat(executions).hasSize(2);
    // Query on two integer variables, should result in single value
    query = runtimeService.createExecutionQuery().variableValueEquals("integerVar", 12345).variableValueEquals("integerVar2", 67890);
    Execution execution = query.singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance2.getId());
    // Query with unexisting variable value
    execution = runtimeService.createExecutionQuery().variableValueEquals("integerVar", 9999).singleResult();
    assertThat(execution).isNull();
    // Test NOT_EQUALS
    execution = runtimeService.createExecutionQuery().variableValueNotEquals("integerVar", 12345).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    // Test GREATER_THAN
    execution = runtimeService.createExecutionQuery().variableValueGreaterThan("integerVar", 44444).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    assertThat(runtimeService.createExecutionQuery().variableValueGreaterThan("integerVar", 55555).count()).isEqualTo(0);
    assertThat(runtimeService.createExecutionQuery().variableValueGreaterThan("integerVar", 1).count()).isEqualTo(3);
    // Test GREATER_THAN_OR_EQUAL
    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("integerVar", 44444).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("integerVar", 55555).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    assertThat(runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("integerVar", 1).count()).isEqualTo(3);
    // Test LESS_THAN
    executions = runtimeService.createExecutionQuery().variableValueLessThan("integerVar", 55555).list();
    assertThat(executions).hasSize(2);
    List<String> expectedIds = asList(processInstance1.getId(), processInstance2.getId());
    List<String> ids = new ArrayList<String>(asList(executions.get(0).getId(), executions.get(1).getId()));
    ids.removeAll(expectedIds);
    assertThat(ids.isEmpty()).isTrue();
    assertThat(runtimeService.createExecutionQuery().variableValueLessThan("integerVar", 12345).count()).isEqualTo(0);
    assertThat(runtimeService.createExecutionQuery().variableValueLessThan("integerVar", 66666).count()).isEqualTo(3);
    // Test LESS_THAN_OR_EQUAL
    executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("integerVar", 55555).list();
    assertThat(executions).hasSize(3);
    assertThat(runtimeService.createExecutionQuery().variableValueLessThanOrEqual("integerVar", 12344).count()).isEqualTo(0);
    // Test value-only matching
    execution = runtimeService.createExecutionQuery().variableValueEquals(55555).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    executions = runtimeService.createExecutionQuery().variableValueEquals(12345).list();
    assertThat(executions).hasSize(2);
    expectedIds = asList(processInstance1.getId(), processInstance2.getId());
    ids = new ArrayList<String>(asList(executions.get(0).getId(), executions.get(1).getId()));
    ids.removeAll(expectedIds);
    assertThat(ids.isEmpty()).isTrue();
    execution = runtimeService.createExecutionQuery().variableValueEquals(99999).singleResult();
    assertThat(execution).isNull();
    runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery) Deployment(org.activiti.engine.test.Deployment)

Example 25 with ExecutionQuery

use of org.activiti.engine.runtime.ExecutionQuery in project Activiti by Activiti.

the class ExecutionQueryTest method testQueryByRootProcessInstanceId.

public void testQueryByRootProcessInstanceId() {
    for (String processInstanceId : concurrentProcessInstanceIds) {
        ExecutionQuery query = runtimeService.createExecutionQuery().rootProcessInstanceId(processInstanceId);
        assertThat(query.list()).hasSize(3);
        assertThat(query.count()).isEqualTo(3);
    }
    assertThat(runtimeService.createExecutionQuery().rootProcessInstanceId(sequentialProcessInstanceIds.get(0)).list()).hasSize(2);
}
Also used : ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery)

Aggregations

ExecutionQuery (org.activiti.engine.runtime.ExecutionQuery)26 Execution (org.activiti.engine.runtime.Execution)14 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 Deployment (org.activiti.engine.test.Deployment)9 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)2 RuntimeService (org.activiti.engine.RuntimeService)2 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)2 Test (org.junit.Test)2 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Response (javax.ws.rs.core.Response)1 ActivitiException (org.activiti.engine.ActivitiException)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 AbstractQuery (org.activiti.engine.impl.AbstractQuery)1 QueryProperty (org.activiti.engine.query.QueryProperty)1 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)1