use of org.activiti.engine.runtime.Execution 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.Execution 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.Execution 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");
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryDateVariable.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryDateVariable() throws Exception {
Map<String, Object> vars = new HashMap<String, Object>();
Date date1 = Calendar.getInstance().getTime();
vars.put("dateVar", date1);
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
Calendar cal2 = Calendar.getInstance();
cal2.add(Calendar.SECOND, 1);
Date date2 = cal2.getTime();
vars = new HashMap<String, Object>();
vars.put("dateVar", date1);
vars.put("dateVar2", date2);
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
vars = new HashMap<String, Object>();
vars.put("dateVar", nextYear.getTime());
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
Calendar nextMonth = Calendar.getInstance();
nextMonth.add(Calendar.MONTH, 1);
Calendar twoYearsLater = Calendar.getInstance();
twoYearsLater.add(Calendar.YEAR, 2);
Calendar oneYearAgo = Calendar.getInstance();
oneYearAgo.add(Calendar.YEAR, -1);
// Query on single short variable, should result in 2 matches
ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("dateVar", date1);
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("dateVar", date1).variableValueEquals("dateVar2", date2);
Execution execution = query.singleResult();
assertNotNull(execution);
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();
assertNull(execution);
// Test NOT_EQUALS
execution = runtimeService.createExecutionQuery().variableValueNotEquals("dateVar", date1).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
// Test GREATER_THAN
execution = runtimeService.createExecutionQuery().variableValueGreaterThan("dateVar", nextMonth.getTime()).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
assertEquals(0, runtimeService.createExecutionQuery().variableValueGreaterThan("dateVar", nextYear.getTime()).count());
assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThan("dateVar", oneYearAgo.getTime()).count());
// Test GREATER_THAN_OR_EQUAL
execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("dateVar", nextMonth.getTime()).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("dateVar", nextYear.getTime()).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("dateVar", oneYearAgo.getTime()).count());
// Test LESS_THAN
executions = runtimeService.createExecutionQuery().variableValueLessThan("dateVar", nextYear.getTime()).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("dateVar", date1).count());
assertEquals(3, runtimeService.createExecutionQuery().variableValueLessThan("dateVar", twoYearsLater.getTime()).count());
// Test LESS_THAN_OR_EQUAL
executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("dateVar", nextYear.getTime()).list();
assertEquals(3, executions.size());
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();
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(twoYearsLater.getTime()).singleResult();
assertNull(execution);
runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryBySignalSubscriptionName.
@Deployment
public void testQueryBySignalSubscriptionName() {
runtimeService.startProcessInstanceByKey("catchSignal");
// it finds subscribed instances
Execution execution = runtimeService.createExecutionQuery().signalEventSubscription("alert").singleResult();
assertNotNull(execution);
// test query for nonexisting subscription
execution = runtimeService.createExecutionQuery().signalEventSubscription("nonExisitng").singleResult();
assertNull(execution);
// it finds more than one
runtimeService.startProcessInstanceByKey("catchSignal");
assertEquals(2, runtimeService.createExecutionQuery().signalEventSubscription("alert").count());
}
Aggregations