use of org.activiti.engine.runtime.ExecutionQuery in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryByParentId.
public void testQueryByParentId() {
// when parentId is used
for (String processInstanceId : concurrentProcessInstanceIds) {
ExecutionQuery query = runtimeService.createExecutionQuery().parentId(processInstanceId);
assertThat(query.list()).hasSize(2);
assertThat(query.count()).isEqualTo(2);
}
}
use of org.activiti.engine.runtime.ExecutionQuery in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryByInvalidProcessDefinitionKey.
public void testQueryByInvalidProcessDefinitionKey() {
ExecutionQuery query = runtimeService.createExecutionQuery().processDefinitionKey("invalid");
assertThat(query.singleResult()).isNull();
assertThat(query.list()).hasSize(0);
assertThat(query.count()).isEqualTo(0);
}
use of org.activiti.engine.runtime.ExecutionQuery in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryByActivityId.
public void testQueryByActivityId() {
ExecutionQuery query = runtimeService.createExecutionQuery().activityId("receivePayment");
assertThat(query.list()).hasSize(4);
assertThat(query.count()).isEqualTo(4);
assertThatExceptionOfType(ActivitiException.class).isThrownBy(() -> query.singleResult());
}
use of org.activiti.engine.runtime.ExecutionQuery 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();
assertThat(executions).isNotNull();
assertThat(executions).hasSize(2);
// 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();
assertThat(execution).isNotNull();
assertThat(execution.getId()).isEqualTo(processInstance2.getId());
// Query with unexisting variable value
execution = runtimeService.createExecutionQuery().variableValueEquals("doubleVar", 9999.99).singleResult();
assertThat(execution).isNull();
// Test NOT_EQUALS
execution = runtimeService.createExecutionQuery().variableValueNotEquals("doubleVar", 12345.6789).singleResult();
assertThat(execution).isNotNull();
assertThat(execution.getId()).isEqualTo(processInstance3.getId());
// Test GREATER_THAN
execution = runtimeService.createExecutionQuery().variableValueGreaterThan("doubleVar", 44444.4444).singleResult();
assertThat(execution).isNotNull();
assertThat(execution.getId()).isEqualTo(processInstance3.getId());
assertThat(runtimeService.createExecutionQuery().variableValueGreaterThan("doubleVar", 55555.5555).count()).isEqualTo(0);
assertThat(runtimeService.createExecutionQuery().variableValueGreaterThan("doubleVar", 1.234).count()).isEqualTo(3);
// Test GREATER_THAN_OR_EQUAL
execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("doubleVar", 44444.4444).singleResult();
assertThat(execution).isNotNull();
assertThat(execution.getId()).isEqualTo(processInstance3.getId());
execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("doubleVar", 55555.5555).singleResult();
assertThat(execution).isNotNull();
assertThat(execution.getId()).isEqualTo(processInstance3.getId());
assertThat(runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("doubleVar", 1.234).count()).isEqualTo(3);
// Test LESS_THAN
executions = runtimeService.createExecutionQuery().variableValueLessThan("doubleVar", 55555.5555).list();
assertThat(executions).hasSize(2);
List<String> expecedIds = asList(processInstance1.getId(), processInstance2.getId());
List<String> ids = new ArrayList<String>(asList(executions.get(0).getId(), executions.get(1).getId()));
ids.removeAll(expecedIds);
assertThat(ids.isEmpty()).isTrue();
assertThat(runtimeService.createExecutionQuery().variableValueLessThan("doubleVar", 12345.6789).count()).isEqualTo(0);
assertThat(runtimeService.createExecutionQuery().variableValueLessThan("doubleVar", 66666.6666).count()).isEqualTo(3);
// Test LESS_THAN_OR_EQUAL
executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("doubleVar", 55555.5555).list();
assertThat(executions).hasSize(3);
assertThat(runtimeService.createExecutionQuery().variableValueLessThanOrEqual("doubleVar", 12344.6789).count()).isEqualTo(0);
// Test value-only matching
execution = runtimeService.createExecutionQuery().variableValueEquals(55555.5555).singleResult();
assertThat(execution).isNotNull();
assertThat(execution.getId()).isEqualTo(processInstance3.getId());
executions = runtimeService.createExecutionQuery().variableValueEquals(12345.6789).list();
assertThat(executions).hasSize(2);
expecedIds = asList(processInstance1.getId(), processInstance2.getId());
ids = new ArrayList<String>(asList(executions.get(0).getId(), executions.get(1).getId()));
ids.removeAll(expecedIds);
assertThat(ids.isEmpty()).isTrue();
execution = runtimeService.createExecutionQuery().variableValueEquals(9999.9999).singleResult();
assertThat(execution).isNull();
runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
use of org.activiti.engine.runtime.ExecutionQuery in project herd by FINRAOS.
the class ActivitiRuntimeHelperTest method testSignal.
@Test
public void testSignal() {
// Create variables required for testing.
final String processInstanceId = ACTIVITI_ID;
final String signalTaskId = ACTIVITI_ID_2;
final String executionId = ACTIVITI_ID_3;
// Mock dependencies.
ExecutionQuery executionQuery = mock(ExecutionQuery.class);
Execution execution = mock(Execution.class);
when(runtimeService.createExecutionQuery()).thenReturn(executionQuery);
when(executionQuery.processInstanceId(processInstanceId)).thenReturn(executionQuery);
when(executionQuery.activityId(signalTaskId)).thenReturn(executionQuery);
when(executionQuery.singleResult()).thenReturn(execution);
when(execution.getId()).thenReturn(executionId);
// Call the method under test.
activitiRuntimeHelper.signal(processInstanceId, signalTaskId);
// Verify the calls.
verify(runtimeService).createExecutionQuery();
verify(executionQuery).processInstanceId(processInstanceId);
verify(executionQuery).activityId(signalTaskId);
verify(executionQuery).singleResult();
verify(execution).getId();
verify(runtimeService).signal(executionId);
verifyNoMoreInteractions(executionQuery, execution, runtimeService);
}
Aggregations