Search in sources :

Example 6 with ExecutionQuery

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

the class ExecutionQueryTest method testQueryNullVariable.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryNullVariable() throws Exception {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("nullVar", null);
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("nullVar", "notnull");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("nullVarLong", "notnull");
    ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("nullVarDouble", "notnull");
    ProcessInstance processInstance4 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("nullVarByte", "testbytes".getBytes());
    ProcessInstance processInstance5 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    // Query on null value, should return one value
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("nullVar", null);
    List<Execution> executions = query.list();
    assertThat(executions).isNotNull();
    assertThat(executions).hasSize(1);
    assertThat(executions.get(0).getId()).isEqualTo(processInstance1.getId());
    // Test NOT_EQUALS null
    assertThat(runtimeService.createExecutionQuery().variableValueNotEquals("nullVar", null).count()).isEqualTo(1);
    assertThat(runtimeService.createExecutionQuery().variableValueNotEquals("nullVarLong", null).count()).isEqualTo(1);
    assertThat(runtimeService.createExecutionQuery().variableValueNotEquals("nullVarDouble", null).count()).isEqualTo(1);
    // When a byte-array reference is present, the variable is not considered
    // null
    assertThat(runtimeService.createExecutionQuery().variableValueNotEquals("nullVarByte", null).count()).isEqualTo(1);
    // Test value-only matching
    Execution execution = runtimeService.createExecutionQuery().variableValueEquals(null).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance1.getId());
    // All other variable queries with null should throw exception
    assertThatExceptionOfType(ActivitiIllegalArgumentException.class).isThrownBy(() -> runtimeService.createExecutionQuery().variableValueGreaterThan("nullVar", null)).withMessageContaining("Booleans and null cannot be used in 'greater than' condition");
    assertThatExceptionOfType(ActivitiIllegalArgumentException.class).isThrownBy(() -> runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("nullVar", null)).withMessageContaining("Booleans and null cannot be used in 'greater than or equal' condition");
    assertThatExceptionOfType(ActivitiIllegalArgumentException.class).isThrownBy(() -> runtimeService.createExecutionQuery().variableValueLessThan("nullVar", null)).withMessageContaining("Booleans and null cannot be used in 'less than' condition");
    assertThatExceptionOfType(ActivitiIllegalArgumentException.class).isThrownBy(() -> runtimeService.createExecutionQuery().variableValueLessThanOrEqual("nullVar", null)).withMessageContaining("Booleans and null cannot be used in 'less than or equal' condition");
    assertThatExceptionOfType(ActivitiIllegalArgumentException.class).isThrownBy(() -> runtimeService.createExecutionQuery().variableValueLike("nullVar", null)).withMessageContaining("Only string values can be used with 'like' condition");
    runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance4.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance5.getId(), "test");
    // Test value-only matching, non-null processes exist
    execution = runtimeService.createExecutionQuery().variableValueEquals(null).singleResult();
    assertThat(execution).isNull();
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery) Deployment(org.activiti.engine.test.Deployment)

Example 7 with ExecutionQuery

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

the class ExecutionQueryTest method testQueryByInvalidProcessInstanceId.

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

Example 8 with ExecutionQuery

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

the class ExecutionQueryTest method testQueryByInvalidActivityId.

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

Example 9 with ExecutionQuery

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

the class ExecutionQueryTest 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
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("dateVar", date1);
    List<Execution> executions = query.list();
    assertThat(executions).isNotNull();
    assertThat(executions).hasSize(2);
    // Query on two short variables, should result in single value
    query = runtimeService.createExecutionQuery().variableValueEquals("dateVar", date1).variableValueEquals("dateVar2", date2);
    Execution execution = query.singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance2.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();
    assertThat(execution).isNull();
    // Test NOT_EQUALS
    execution = runtimeService.createExecutionQuery().variableValueNotEquals("dateVar", date1).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    // Test GREATER_THAN
    execution = runtimeService.createExecutionQuery().variableValueGreaterThan("dateVar", nextMonth.getTime()).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    assertThat(runtimeService.createExecutionQuery().variableValueGreaterThan("dateVar", nextYear.getTime()).count()).isEqualTo(0);
    assertThat(runtimeService.createExecutionQuery().variableValueGreaterThan("dateVar", oneYearAgo.getTime()).count()).isEqualTo(3);
    // Test GREATER_THAN_OR_EQUAL
    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("dateVar", nextMonth.getTime()).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("dateVar", nextYear.getTime()).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    assertThat(runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("dateVar", oneYearAgo.getTime()).count()).isEqualTo(3);
    // Test LESS_THAN
    executions = runtimeService.createExecutionQuery().variableValueLessThan("dateVar", nextYear.getTime()).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("dateVar", date1).count()).isEqualTo(0);
    assertThat(runtimeService.createExecutionQuery().variableValueLessThan("dateVar", twoYearsLater.getTime()).count()).isEqualTo(3);
    // Test LESS_THAN_OR_EQUAL
    executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("dateVar", nextYear.getTime()).list();
    assertThat(executions).hasSize(3);
    assertThat(runtimeService.createExecutionQuery().variableValueLessThanOrEqual("dateVar", oneYearAgo.getTime()).count()).isEqualTo(0);
    // Test value-only matching
    execution = runtimeService.createExecutionQuery().variableValueEquals(nextYear.getTime()).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());
    executions = runtimeService.createExecutionQuery().variableValueEquals(date1).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(twoYearsLater.getTime()).singleResult();
    assertThat(execution).isNull();
    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) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery) Date(java.util.Date) Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SimpleDateFormat(java.text.SimpleDateFormat) Deployment(org.activiti.engine.test.Deployment)

Example 10 with ExecutionQuery

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

the class ExecutionQueryTest method testQueryVariablesUpdatedToNullValue.

@Deployment(resources = { "org/activiti/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);
    assertThat(query.singleResult()).isNull();
    assertThat(notQuery.singleResult()).isNotNull();
    // 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();
    assertThat(queryResult).isNotNull();
    assertThat(queryResult.getId()).isEqualTo(processInstance.getId());
    assertThat(notQuery.singleResult()).isNull();
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

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