use of org.activiti.engine.runtime.ProcessInstance 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();
assertNotNull(executions);
assertEquals(1, executions.size());
assertEquals(processInstance1.getId(), executions.get(0).getId());
// Test NOT_EQUALS null
assertEquals(1, runtimeService.createExecutionQuery().variableValueNotEquals("nullVar", null).count());
assertEquals(1, runtimeService.createExecutionQuery().variableValueNotEquals("nullVarLong", null).count());
assertEquals(1, runtimeService.createExecutionQuery().variableValueNotEquals("nullVarDouble", null).count());
// When a byte-array refrence is present, the variable is not considered null
assertEquals(1, runtimeService.createExecutionQuery().variableValueNotEquals("nullVarByte", null).count());
// Test value-only matching
Execution execution = runtimeService.createExecutionQuery().variableValueEquals(null).singleResult();
assertNotNull(execution);
assertEquals(processInstance1.getId(), execution.getId());
// All other variable queries with null should throw exception
try {
runtimeService.createExecutionQuery().variableValueGreaterThan("nullVar", null);
fail("Excetion expected");
} catch (ActivitiIllegalArgumentException ae) {
assertTextPresent("Booleans and null cannot be used in 'greater than' condition", ae.getMessage());
}
try {
runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("nullVar", null);
fail("Excetion expected");
} catch (ActivitiIllegalArgumentException ae) {
assertTextPresent("Booleans and null cannot be used in 'greater than or equal' condition", ae.getMessage());
}
try {
runtimeService.createExecutionQuery().variableValueLessThan("nullVar", null);
fail("Excetion expected");
} catch (ActivitiIllegalArgumentException ae) {
assertTextPresent("Booleans and null cannot be used in 'less than' condition", ae.getMessage());
}
try {
runtimeService.createExecutionQuery().variableValueLessThanOrEqual("nullVar", null);
fail("Excetion expected");
} catch (ActivitiIllegalArgumentException ae) {
assertTextPresent("Booleans and null cannot be used in 'less than or equal' condition", ae.getMessage());
}
try {
runtimeService.createExecutionQuery().variableValueLike("nullVar", null);
fail("Excetion expected");
} catch (ActivitiIllegalArgumentException ae) {
assertTextPresent("Only string values can be used with 'like' condition", ae.getMessage());
}
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();
assertNull(execution);
}
use of org.activiti.engine.runtime.ProcessInstance 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);
assertNull(query.singleResult());
assertNotNull(notQuery.singleResult());
// 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();
assertNotNull(queryResult);
assertEquals(processInstance.getId(), queryResult.getId());
assertNull(notQuery.singleResult());
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryLikeIgnoreCase.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryLikeIgnoreCase() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("mixed", "AbCdEfG");
vars.put("lower", "ABCDEFG");
vars.put("upper", "abcdefg");
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
Execution execution = runtimeService.createExecutionQuery().variableValueLikeIgnoreCase("mixed", "abcde%").singleResult();
assertNotNull(execution);
assertEquals(processInstance1.getId(), execution.getId());
execution = runtimeService.createExecutionQuery().variableValueLikeIgnoreCase("lower", "abcd%").singleResult();
assertNotNull(execution);
assertEquals(processInstance1.getId(), execution.getId());
execution = runtimeService.createExecutionQuery().variableValueLikeIgnoreCase("upper", "abcd%").singleResult();
assertNotNull(execution);
assertEquals(processInstance1.getId(), execution.getId());
// Pass in non-lower-case string
execution = runtimeService.createExecutionQuery().variableValueLikeIgnoreCase("upper", "ABCde%").singleResult();
assertNotNull(execution);
assertEquals(processInstance1.getId(), execution.getId());
// Pass in null-value, should cause exception
try {
execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase("upper", null).singleResult();
fail("Exception expected");
} catch (ActivitiIllegalArgumentException ae) {
assertEquals("value is null", ae.getMessage());
}
// Pass in null name, should cause exception
try {
execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase(null, "abcdefg").singleResult();
fail("Exception expected");
} catch (ActivitiIllegalArgumentException ae) {
assertEquals("name is null", ae.getMessage());
}
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryDoubleVariable.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryDoubleVariable() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("doubleVar", 12345.6789);
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("doubleVar", 12345.6789);
vars.put("doubleVar2", 9876.54321);
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("doubleVar", 55555.5555);
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
// Query on single double variable, should result in 2 matches
ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("doubleVar", 12345.6789);
List<Execution> executions = query.list();
assertNotNull(executions);
assertEquals(2, executions.size());
// Query on two double variables, should result in single value
query = runtimeService.createExecutionQuery().variableValueEquals("doubleVar", 12345.6789).variableValueEquals("doubleVar2", 9876.54321);
Execution execution = query.singleResult();
assertNotNull(execution);
assertEquals(processInstance2.getId(), execution.getId());
// Query with unexisting variable value
execution = runtimeService.createExecutionQuery().variableValueEquals("doubleVar", 9999.99).singleResult();
assertNull(execution);
// Test NOT_EQUALS
execution = runtimeService.createExecutionQuery().variableValueNotEquals("doubleVar", 12345.6789).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
// Test GREATER_THAN
execution = runtimeService.createExecutionQuery().variableValueGreaterThan("doubleVar", 44444.4444).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
assertEquals(0, runtimeService.createExecutionQuery().variableValueGreaterThan("doubleVar", 55555.5555).count());
assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThan("doubleVar", 1.234).count());
// Test GREATER_THAN_OR_EQUAL
execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("doubleVar", 44444.4444).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("doubleVar", 55555.5555).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("doubleVar", 1.234).count());
// Test LESS_THAN
executions = runtimeService.createExecutionQuery().variableValueLessThan("doubleVar", 55555.5555).list();
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());
assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThan("doubleVar", 12345.6789).count());
assertEquals(3, runtimeService.createExecutionQuery().variableValueLessThan("doubleVar", 66666.6666).count());
// Test LESS_THAN_OR_EQUAL
executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("doubleVar", 55555.5555).list();
assertEquals(3, executions.size());
assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThanOrEqual("doubleVar", 12344.6789).count());
// Test value-only matching
execution = runtimeService.createExecutionQuery().variableValueEquals(55555.5555).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
executions = runtimeService.createExecutionQuery().variableValueEquals(12345.6789).list();
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()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
execution = runtimeService.createExecutionQuery().variableValueEquals(9999.9999).singleResult();
assertNull(execution);
runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryShortVariable.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryShortVariable() {
Map<String, Object> vars = new HashMap<String, Object>();
short shortVar = 1234;
vars.put("shortVar", shortVar);
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
short shortVar2 = 6789;
vars = new HashMap<String, Object>();
vars.put("shortVar", shortVar);
vars.put("shortVar2", shortVar2);
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("shortVar", (short) 5555);
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
// Query on single short variable, should result in 2 matches
ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("shortVar", shortVar);
List<Execution> executions = query.list();
assertNotNull(executions);
assertEquals(2, executions.size());
// Query on two short variables, should result in single value
query = runtimeService.createExecutionQuery().variableValueEquals("shortVar", shortVar).variableValueEquals("shortVar2", shortVar2);
Execution execution = query.singleResult();
assertNotNull(execution);
assertEquals(processInstance2.getId(), execution.getId());
// Query with unexisting variable value
short unexistingValue = (short) 9999;
execution = runtimeService.createExecutionQuery().variableValueEquals("shortVar", unexistingValue).singleResult();
assertNull(execution);
// Test NOT_EQUALS
execution = runtimeService.createExecutionQuery().variableValueNotEquals("shortVar", (short) 1234).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
// Test GREATER_THAN
execution = runtimeService.createExecutionQuery().variableValueGreaterThan("shortVar", (short) 4444).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
assertEquals(0, runtimeService.createExecutionQuery().variableValueGreaterThan("shortVar", (short) 5555).count());
assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThan("shortVar", (short) 1).count());
// Test GREATER_THAN_OR_EQUAL
execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("shortVar", (short) 4444).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("shortVar", (short) 5555).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("shortVar", (short) 1).count());
// Test LESS_THAN
executions = runtimeService.createExecutionQuery().variableValueLessThan("shortVar", (short) 5555).list();
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());
assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThan("shortVar", (short) 1234).count());
assertEquals(3, runtimeService.createExecutionQuery().variableValueLessThan("shortVar", (short) 6666).count());
// Test LESS_THAN_OR_EQUAL
executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("shortVar", (short) 5555).list();
assertEquals(3, executions.size());
assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThanOrEqual("shortVar", (short) 1233).count());
// Test value-only matching
execution = runtimeService.createExecutionQuery().variableValueEquals((short) 5555).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
executions = runtimeService.createExecutionQuery().variableValueEquals((short) 1234).list();
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()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
execution = runtimeService.createExecutionQuery().variableValueEquals((short) 999).singleResult();
assertNull(execution);
runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
Aggregations