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());
// Test value-only matching
execution = runtimeService.createExecutionQuery().variableValueEquals(nextYear.getTime()).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
executions = runtimeService.createExecutionQuery().variableValueEquals(date1).list();
Assert.assertEquals(2, executions.size());
expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
ids = new ArrayList<String>(Arrays.asList(executions.get(0).getId(), executions.get(1).getId()));