use of org.activiti.engine.runtime.ExecutionQuery in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryStringVariable.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryStringVariable() {
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", singletonMap("stringVar", "abcdef"));
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", map("stringVar", "abcdef", "stringVar2", "ghijkl"));
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", singletonMap("stringVar", "azerty"));
// Test EQUAL on single string variable, should result in 2 matches
ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("stringVar", "abcdef");
List<Execution> executions = query.list();
assertThat(executions).isNotNull();
assertThat(executions).hasSize(2);
// Test EQUAL on two string variables, should result in single match
query = runtimeService.createExecutionQuery().variableValueEquals("stringVar", "abcdef").variableValueEquals("stringVar2", "ghijkl");
Execution execution = query.singleResult();
assertThat(execution).isNotNull();
assertThat(execution.getId()).isEqualTo(processInstance2.getId());
// Test NOT_EQUAL, should return only 1 execution
execution = runtimeService.createExecutionQuery().variableValueNotEquals("stringVar", "abcdef").singleResult();
assertThat(execution).isNotNull();
assertThat(execution.getId()).isEqualTo(processInstance3.getId());
// Test GREATER_THAN, should return only matching 'azerty'
execution = runtimeService.createExecutionQuery().variableValueGreaterThan("stringVar", "abcdef").singleResult();
assertThat(execution).isNotNull();
assertThat(execution.getId()).isEqualTo(processInstance3.getId());
execution = runtimeService.createExecutionQuery().variableValueGreaterThan("stringVar", "z").singleResult();
assertThat(execution).isNull();
// Test GREATER_THAN_OR_EQUAL, should return 3 results
assertThat(runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("stringVar", "abcdef").count()).isEqualTo(3);
assertThat(runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("stringVar", "z").count()).isEqualTo(0);
// Test LESS_THAN, should return 2 results
executions = runtimeService.createExecutionQuery().variableValueLessThan("stringVar", "abcdeg").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("stringVar", "abcdef").count()).isEqualTo(0);
assertThat(runtimeService.createExecutionQuery().variableValueLessThanOrEqual("stringVar", "z").count()).isEqualTo(3);
// Test LESS_THAN_OR_EQUAL
executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("stringVar", "abcdef").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();
assertThat(runtimeService.createExecutionQuery().variableValueLessThanOrEqual("stringVar", "z").count()).isEqualTo(3);
assertThat(runtimeService.createExecutionQuery().variableValueLessThanOrEqual("stringVar", "aa").count()).isEqualTo(0);
// Test LIKE
execution = runtimeService.createExecutionQuery().variableValueLike("stringVar", "azert%").singleResult();
assertThat(execution).isNotNull();
assertThat(execution.getId()).isEqualTo(processInstance3.getId());
execution = runtimeService.createExecutionQuery().variableValueLike("stringVar", "%y").singleResult();
assertThat(execution).isNotNull();
assertThat(execution.getId()).isEqualTo(processInstance3.getId());
execution = runtimeService.createExecutionQuery().variableValueLike("stringVar", "%zer%").singleResult();
assertThat(execution).isNotNull();
assertThat(execution.getId()).isEqualTo(processInstance3.getId());
assertThat(runtimeService.createExecutionQuery().variableValueLike("stringVar", "a%").count()).isEqualTo(3);
assertThat(runtimeService.createExecutionQuery().variableValueLike("stringVar", "%x%").count()).isEqualTo(0);
// Test value-only matching
execution = runtimeService.createExecutionQuery().variableValueEquals("azerty").singleResult();
assertThat(execution).isNotNull();
assertThat(execution.getId()).isEqualTo(processInstance3.getId());
executions = runtimeService.createExecutionQuery().variableValueEquals("abcdef").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("notmatchinganyvalues").singleResult();
assertThat(execution).isNull();
runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
Aggregations