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();
}
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);
}
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);
}
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");
}
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();
}
Aggregations