use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class ProcessInstanceQueryTest method testQueryIntegerVariable.
@Test
@Deployment(resources = { "org/camunda/bpm/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);
Assert.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);
Assert.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);
Assert.assertEquals(processInstance3.getId(), resultInstance.getId());
// Test GREATER_THAN
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar", 44444).singleResult();
assertNotNull(resultInstance);
Assert.assertEquals(processInstance3.getId(), resultInstance.getId());
Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar", 55555).count());
Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar", 1).count());
// Test GREATER_THAN_OR_EQUAL
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar", 44444).singleResult();
assertNotNull(resultInstance);
Assert.assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar", 55555).singleResult();
assertNotNull(resultInstance);
Assert.assertEquals(processInstance3.getId(), resultInstance.getId());
Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar", 1).count());
// Test LESS_THAN
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar", 55555).list();
Assert.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());
Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar", 12345).count());
Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar", 66666).count());
// Test LESS_THAN_OR_EQUAL
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("integerVar", 55555).list();
Assert.assertEquals(3, processInstances.size());
Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("integerVar", 12344).count());
runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class ProcessInstanceQueryTest method testQueryNullVariable.
@Test
@Deployment(resources = { "org/camunda/bpm/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);
Assert.assertEquals(1, processInstances.size());
Assert.assertEquals(processInstance1.getId(), processInstances.get(0).getId());
// Test NOT_EQUALS null
Assert.assertEquals(1, runtimeService.createProcessInstanceQuery().variableValueNotEquals("nullVar", null).count());
Assert.assertEquals(1, runtimeService.createProcessInstanceQuery().variableValueNotEquals("nullVarLong", null).count());
Assert.assertEquals(1, runtimeService.createProcessInstanceQuery().variableValueNotEquals("nullVarDouble", null).count());
// When a byte-array refrence is present, the variable is not considered null
Assert.assertEquals(1, runtimeService.createProcessInstanceQuery().variableValueNotEquals("nullVarByte", null).count());
// All other variable queries with null should throw exception
try {
runtimeService.createProcessInstanceQuery().variableValueGreaterThan("nullVar", null);
fail("Excetion expected");
} catch (ProcessEngineException ae) {
assertThat(ae.getMessage(), containsString("Booleans and null cannot be used in 'greater than' condition"));
}
try {
runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("nullVar", null);
fail("Excetion expected");
} catch (ProcessEngineException ae) {
assertThat(ae.getMessage(), containsString("Booleans and null cannot be used in 'greater than or equal' condition"));
}
try {
runtimeService.createProcessInstanceQuery().variableValueLessThan("nullVar", null);
fail("Excetion expected");
} catch (ProcessEngineException ae) {
assertThat(ae.getMessage(), containsString("Booleans and null cannot be used in 'less than' condition"));
}
try {
runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("nullVar", null);
fail("Excetion expected");
} catch (ProcessEngineException ae) {
assertThat(ae.getMessage(), containsString("Booleans and null cannot be used in 'less than or equal' condition"));
}
try {
runtimeService.createProcessInstanceQuery().variableValueLike("nullVar", null);
fail("Excetion expected");
} catch (ProcessEngineException ae) {
assertThat(ae.getMessage(), containsString("Booleans and null cannot be used in '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");
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class ProcessInstanceQueryTest method testQueryStringVariable.
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryStringVariable() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("stringVar", "abcdef");
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("stringVar", "abcdef");
vars.put("stringVar2", "ghijkl");
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("stringVar", "azerty");
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
// Test EQUAL on single string variable, should result in 2 matches
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("stringVar", "abcdef");
List<ProcessInstance> processInstances = query.list();
assertNotNull(processInstances);
Assert.assertEquals(2, processInstances.size());
// Test EQUAL on two string variables, should result in single match
query = runtimeService.createProcessInstanceQuery().variableValueEquals("stringVar", "abcdef").variableValueEquals("stringVar2", "ghijkl");
ProcessInstance resultInstance = query.singleResult();
assertNotNull(resultInstance);
Assert.assertEquals(processInstance2.getId(), resultInstance.getId());
// Test NOT_EQUAL, should return only 1 resultInstance
resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("stringVar", "abcdef").singleResult();
assertNotNull(resultInstance);
Assert.assertEquals(processInstance3.getId(), resultInstance.getId());
// Test GREATER_THAN, should return only matching 'azerty'
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("stringVar", "abcdef").singleResult();
assertNotNull(resultInstance);
Assert.assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("stringVar", "z").singleResult();
assertNull(resultInstance);
// Test GREATER_THAN_OR_EQUAL, should return 3 results
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("stringVar", "abcdef").count());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("stringVar", "z").count());
// Test LESS_THAN, should return 2 results
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("stringVar", "abcdeg").list();
Assert.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("stringVar", "abcdef").count());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("stringVar", "z").count());
// Test LESS_THAN_OR_EQUAL
processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("stringVar", "abcdef").list();
Assert.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());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("stringVar", "z").count());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("stringVar", "aa").count());
// Test LIKE
resultInstance = runtimeService.createProcessInstanceQuery().variableValueLike("stringVar", "azert%").singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = runtimeService.createProcessInstanceQuery().variableValueLike("stringVar", "%y").singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = runtimeService.createProcessInstanceQuery().variableValueLike("stringVar", "%zer%").singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLike("stringVar", "a%").count());
assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLike("stringVar", "%x%").count());
runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class ProcessInstanceQueryTest method testQueryNoSpecificsList.
@Test
public void testQueryNoSpecificsList() {
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
assertEquals(5, query.count());
assertEquals(5, query.list().size());
}
use of org.camunda.bpm.engine.runtime.ProcessInstanceQuery in project camunda-bpm-platform by camunda.
the class ProcessInstanceQueryTest method testQueryBySuspended.
@Test
public void testQueryBySuspended() throws Exception {
ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery();
assertEquals(0, processInstanceQuery.suspended().count());
repositoryService.suspendProcessDefinitionByKey(PROCESS_DEFINITION_KEY);
assertEquals(0, processInstanceQuery.suspended().count());
repositoryService.suspendProcessDefinitionByKey(PROCESS_DEFINITION_KEY, true, null);
assertEquals(4, processInstanceQuery.suspended().count());
}
Aggregations