use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryAllVariableTypes.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryAllVariableTypes() throws Exception {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("nullVar", null);
vars.put("stringVar", "string");
vars.put("longVar", 10L);
vars.put("doubleVar", 1.2);
vars.put("integerVar", 1234);
vars.put("booleanVar", true);
vars.put("shortVar", (short) 123);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("nullVar", null).variableValueEquals("stringVar", "string").variableValueEquals("longVar", 10L).variableValueEquals("doubleVar", 1.2).variableValueEquals("integerVar", 1234).variableValueEquals("booleanVar", true).variableValueEquals("shortVar", (short) 123);
List<Execution> executions = query.list();
assertNotNull(executions);
assertEquals(1, executions.size());
assertEquals(processInstance.getId(), executions.get(0).getId());
runtimeService.deleteProcessInstance(processInstance.getId(), "test");
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryByActivityIdAndBusinessKeyWithChildren.
/**
* Validate fix for ACT-1896
*/
public void testQueryByActivityIdAndBusinessKeyWithChildren() {
ExecutionQuery query = runtimeService.createExecutionQuery().activityId("receivePayment").processInstanceBusinessKey("BUSINESS-KEY-1", true);
assertEquals(1, query.list().size());
assertEquals(1, query.count());
Execution execution = query.singleResult();
assertNotNull(execution);
assertEquals("receivePayment", execution.getActivityId());
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionQueryTest method testBooleanVariable.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testBooleanVariable() throws Exception {
// TEST EQUALS
HashMap<String, Object> vars = new HashMap<String, Object>();
vars.put("booleanVar", true);
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("booleanVar", false);
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
List<ProcessInstance> instances = runtimeService.createProcessInstanceQuery().variableValueEquals("booleanVar", true).list();
assertNotNull(instances);
assertEquals(1, instances.size());
assertEquals(processInstance1.getId(), instances.get(0).getId());
instances = runtimeService.createProcessInstanceQuery().variableValueEquals("booleanVar", false).list();
assertNotNull(instances);
assertEquals(1, instances.size());
assertEquals(processInstance2.getId(), instances.get(0).getId());
// TEST NOT_EQUALS
instances = runtimeService.createProcessInstanceQuery().variableValueNotEquals("booleanVar", true).list();
assertNotNull(instances);
assertEquals(1, instances.size());
assertEquals(processInstance2.getId(), instances.get(0).getId());
instances = runtimeService.createProcessInstanceQuery().variableValueNotEquals("booleanVar", false).list();
assertNotNull(instances);
assertEquals(1, instances.size());
assertEquals(processInstance1.getId(), instances.get(0).getId());
// Test value-only matching
Execution execution = runtimeService.createExecutionQuery().variableValueEquals(true).singleResult();
assertNotNull(execution);
assertEquals(processInstance1.getId(), execution.getId());
// Test unsupported operations
try {
runtimeService.createProcessInstanceQuery().variableValueGreaterThan("booleanVar", true);
fail("Excetion expected");
} catch (ActivitiIllegalArgumentException ae) {
assertTextPresent("Booleans and null cannot be used in 'greater than' condition", ae.getMessage());
}
try {
runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("booleanVar", true);
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("booleanVar", true);
fail("Excetion expected");
} catch (ActivitiIllegalArgumentException ae) {
assertTextPresent("Booleans and null cannot be used in 'less than' condition", ae.getMessage());
}
try {
runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("booleanVar", true);
fail("Excetion expected");
} catch (ActivitiIllegalArgumentException ae) {
assertTextPresent("Booleans and null cannot be used in 'less than or equal' condition", ae.getMessage());
}
runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryLike.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryLike() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("var1", "aaaaa");
vars.put("var2", "bbbbb");
vars.put("var3", "ccccc");
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
Execution execution = runtimeService.createExecutionQuery().variableValueLike("var1", "aa%").singleResult();
assertNotNull(execution);
assertEquals(processInstance1.getId(), execution.getId());
execution = runtimeService.createExecutionQuery().variableValueLike("var2", "bb%").singleResult();
assertNotNull(execution);
assertEquals(processInstance1.getId(), execution.getId());
// Pass in null-value, should cause exception
try {
execution = runtimeService.createExecutionQuery().variableValueLike("var1", null).singleResult();
fail("Exception expected");
} catch (ActivitiIllegalArgumentException ae) {
assertEquals("Only string values can be used with 'like' condition", ae.getMessage());
}
// Pass in null name, should cause exception
try {
execution = runtimeService.createExecutionQuery().variableValueLike(null, "abcdefg").singleResult();
fail("Exception expected");
} catch (ActivitiIllegalArgumentException ae) {
assertEquals("name is null", ae.getMessage());
}
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ProcessInstanceQueryTest 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("dateVar", new Date());
variables.put("booleanVar", true);
variables.put("nullVar", null);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("longVar", null).variableValueEquals("shortVar", null).variableValueEquals("integerVar", null).variableValueEquals("stringVar", null).variableValueEquals("booleanVar", null).variableValueEquals("dateVar", null);
ProcessInstanceQuery notQuery = runtimeService.createProcessInstanceQuery().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(), "dateVar", null);
runtimeService.setVariable(processInstance.getId(), "nullVar", null);
runtimeService.setVariable(processInstance.getId(), "booleanVar", null);
Execution queryResult = query.singleResult();
assertNotNull(queryResult);
assertEquals(processInstance.getId(), queryResult.getId());
assertNull(notQuery.singleResult());
}
Aggregations