use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.
the class ProcessInstanceQueryTest 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
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("nullVar", null);
List<ProcessInstance> processInstances = query.list();
assertNotNull(processInstances);
assertEquals(1, processInstances.size());
assertEquals(processInstance1.getId(), processInstances.get(0).getId());
// Test NOT_EQUALS null
assertEquals(1, runtimeService.createProcessInstanceQuery().variableValueNotEquals("nullVar", null).count());
assertEquals(1, runtimeService.createProcessInstanceQuery().variableValueNotEquals("nullVarLong", null).count());
assertEquals(1, runtimeService.createProcessInstanceQuery().variableValueNotEquals("nullVarDouble", null).count());
// When a byte-array refrence is present, the variable is not considered null
assertEquals(1, runtimeService.createProcessInstanceQuery().variableValueNotEquals("nullVarByte", null).count());
// Test value-only
assertEquals(1, runtimeService.createProcessInstanceQuery().variableValueEquals(null).count());
// All other variable queries with null should throw exception
try {
runtimeService.createProcessInstanceQuery().variableValueGreaterThan("nullVar", null);
fail("Excetion expected");
} catch (ActivitiIllegalArgumentException ae) {
assertTextPresent("Booleans and null cannot be used in 'greater than' condition", ae.getMessage());
}
try {
runtimeService.createProcessInstanceQuery().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.createProcessInstanceQuery().variableValueLessThan("nullVar", null);
fail("Excetion expected");
} catch (ActivitiIllegalArgumentException ae) {
assertTextPresent("Booleans and null cannot be used in 'less than' condition", ae.getMessage());
}
try {
runtimeService.createProcessInstanceQuery().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.createProcessInstanceQuery().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, no more null-variables exist
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueEquals(null).count());
}
use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.
the class ProcessInstanceQueryTest method testQueryIntegerVariable.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryIntegerVariable() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("integerVar", 12345);
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("integerVar", 12345);
vars.put("integerVar2", 67890);
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("integerVar", 55555);
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
// Query on single integer variable, should result in 2 matches
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("integerVar", 12345);
List<ProcessInstance> processInstances = query.list();
assertNotNull(processInstances);
assertEquals(2, processInstances.size());
// Query on two integer variables, should result in single value
query = runtimeService.createProcessInstanceQuery().variableValueEquals("integerVar", 12345).variableValueEquals("integerVar2", 67890);
ProcessInstance resultInstance = query.singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance2.getId(), resultInstance.getId());
// Query with unexisting variable value
resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("integerVar", 9999).singleResult();
assertNull(resultInstance);
// Test NOT_EQUALS
resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("integerVar", 12345).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
// Test GREATER_THAN
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar", 44444).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar", 55555).count());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar", 1).count());
// Test GREATER_THAN_OR_EQUAL
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar", 44444).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar", 55555).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar", 1).count());
// Test LESS_THAN
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar", 55555).list();
assertEquals(2, processInstances.size());
List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
List<String> ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar", 12345).count());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar", 66666).count());
// Test LESS_THAN_OR_EQUAL
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("integerVar", 55555).list();
assertEquals(3, processInstances.size());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("integerVar", 12344).count());
// Test value-only matching
resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(55555).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
processInstances = runtimeService.createProcessInstanceQuery().variableValueEquals(12345).list();
assertEquals(2, processInstances.size());
expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(9999).singleResult();
assertNull(resultInstance);
runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.
the class ProcessInstanceQueryTest method testQueryNoSpecificsSingleResult.
public void testQueryNoSpecificsSingleResult() {
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
try {
query.singleResult();
fail();
} catch (ActivitiException e) {
// Exception is expected
}
}
use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.
the class ProcessInstanceQueryTest method testQueryByProcessDefinitionKeyMultipleResults.
public void testQueryByProcessDefinitionKeyMultipleResults() {
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processDefinitionKey(PROCESS_DEFINITION_KEY);
assertEquals(PROCESS_DEFINITION_KEY_DEPLOY_COUNT, query.count());
assertEquals(PROCESS_DEFINITION_KEY_DEPLOY_COUNT, query.list().size());
try {
query.singleResult();
fail();
} catch (ActivitiException e) {
// Exception is expected
}
}
use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.
the class ProcessInstanceQueryTest method testQueryByProcessDefinitionId.
public void testQueryByProcessDefinitionId() {
final ProcessDefinition processDefinition1 = repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_DEFINITION_KEY).singleResult();
ProcessInstanceQuery query1 = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition1.getId());
assertEquals(PROCESS_DEFINITION_KEY_DEPLOY_COUNT, query1.count());
assertEquals(PROCESS_DEFINITION_KEY_DEPLOY_COUNT, query1.list().size());
try {
query1.singleResult();
fail();
} catch (ActivitiException e) {
// Exception is expected
}
final ProcessDefinition processDefinition2 = repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_DEFINITION_KEY_2).singleResult();
ProcessInstanceQuery query2 = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition2.getId());
assertEquals(PROCESS_DEFINITION_KEY_2_DEPLOY_COUNT, query2.count());
assertEquals(PROCESS_DEFINITION_KEY_2_DEPLOY_COUNT, query2.list().size());
assertNotNull(query2.singleResult());
}
Aggregations