use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class ProcessInstanceModificationMultiInstanceTest method testStartBeforeInnerActivityWithMiBodySequentialSubprocess.
@Deployment(resources = SEQUENTIAL_MULTI_INSTANCE_SUBPROCESS_PROCESS)
public void testStartBeforeInnerActivityWithMiBodySequentialSubprocess() {
// given the mi body is not yet instantiated
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("miSequentialSubprocess");
// when
ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("subProcessTask").execute();
// then the mi variables should be correct
Execution leafExecution = runtimeService.createExecutionQuery().activityId("subProcessTask").singleResult();
assertNotNull(leafExecution);
assertVariable(leafExecution, "loopCounter", 0);
assertVariable(leafExecution, "nrOfInstances", 1);
assertVariable(leafExecution, "nrOfCompletedInstances", 0);
assertVariable(leafExecution, "nrOfActiveInstances", 1);
// and the trees should be correct
tree = runtimeService.getActivityInstance(processInstance.getId());
assertThat(tree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("beforeTask").beginMiBody("miSubProcess").beginScope("miSubProcess").activity("subProcessTask").endScope().done());
ExecutionTree executionTree = ExecutionTree.forExecution(processInstance.getId(), processEngine);
assertThat(executionTree).matches(describeExecutionTree(null).scope().child("beforeTask").concurrent().noScope().up().child(null).concurrent().noScope().child(null).scope().child("subProcessTask").scope().done());
// and the process is able to complete successfully
completeTasksInOrder("subProcessTask", "afterTask", "beforeTask", "subProcessTask", "subProcessTask", "subProcessTask", "afterTask");
assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class ProcessInstanceModificationMultiInstanceTest method testStartBeforeInnerActivityWithMiBodySetNrOfInstancesSequentialSubprocess.
@Deployment(resources = SEQUENTIAL_MULTI_INSTANCE_SUBPROCESS_PROCESS)
public void testStartBeforeInnerActivityWithMiBodySetNrOfInstancesSequentialSubprocess() {
// given the mi body is not yet instantiated
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("miSequentialSubprocess");
// when
ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("subProcessTask").setVariable("nrOfInstances", 3).execute();
// then the mi variables should be correct
Execution leafExecution = runtimeService.createExecutionQuery().activityId("subProcessTask").singleResult();
assertNotNull(leafExecution);
assertVariable(leafExecution, "loopCounter", 0);
assertVariable(leafExecution, "nrOfInstances", 3);
assertVariable(leafExecution, "nrOfCompletedInstances", 0);
assertVariable(leafExecution, "nrOfActiveInstances", 1);
// and the trees should be correct
tree = runtimeService.getActivityInstance(processInstance.getId());
assertThat(tree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("beforeTask").beginMiBody("miSubProcess").beginScope("miSubProcess").activity("subProcessTask").endScope().done());
ExecutionTree executionTree = ExecutionTree.forExecution(processInstance.getId(), processEngine);
assertThat(executionTree).matches(describeExecutionTree(null).scope().child("beforeTask").concurrent().noScope().up().child(null).concurrent().noScope().child(null).scope().child("subProcessTask").scope().done());
// and two following sequential instances should be created
completeTasksInOrder("subProcessTask");
tree = runtimeService.getActivityInstance(processInstance.getId());
assertThat(tree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("beforeTask").beginMiBody("miSubProcess").beginScope("miSubProcess").activity("subProcessTask").done());
leafExecution = runtimeService.createExecutionQuery().activityId("subProcessTask").singleResult();
assertNotNull(leafExecution);
assertVariable(leafExecution, "loopCounter", 1);
assertVariable(leafExecution, "nrOfInstances", 3);
assertVariable(leafExecution, "nrOfCompletedInstances", 1);
assertVariable(leafExecution, "nrOfActiveInstances", 1);
completeTasksInOrder("subProcessTask");
// and the remainder of the process completes successfully
completeTasksInOrder("subProcessTask", "beforeTask", "subProcessTask", "subProcessTask", "subProcessTask", "afterTask", "afterTask");
assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class ExecutionQueryTest method testQueryIntegerVariable.
@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
ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("integerVar", 12345);
List<Execution> executions = query.list();
Assert.assertNotNull(executions);
Assert.assertEquals(2, executions.size());
// Query on two integer variables, should result in single value
query = runtimeService.createExecutionQuery().variableValueEquals("integerVar", 12345).variableValueEquals("integerVar2", 67890);
Execution execution = query.singleResult();
Assert.assertNotNull(execution);
Assert.assertEquals(processInstance2.getId(), execution.getId());
// Query with unexisting variable value
execution = runtimeService.createExecutionQuery().variableValueEquals("integerVar", 9999).singleResult();
Assert.assertNull(execution);
// Test NOT_EQUALS
execution = runtimeService.createExecutionQuery().variableValueNotEquals("integerVar", 12345).singleResult();
Assert.assertNotNull(execution);
Assert.assertEquals(processInstance3.getId(), execution.getId());
// Test GREATER_THAN
execution = runtimeService.createExecutionQuery().variableValueGreaterThan("integerVar", 44444).singleResult();
Assert.assertNotNull(execution);
Assert.assertEquals(processInstance3.getId(), execution.getId());
Assert.assertEquals(0, runtimeService.createExecutionQuery().variableValueGreaterThan("integerVar", 55555).count());
Assert.assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThan("integerVar", 1).count());
// Test GREATER_THAN_OR_EQUAL
execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("integerVar", 44444).singleResult();
Assert.assertNotNull(execution);
Assert.assertEquals(processInstance3.getId(), execution.getId());
execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("integerVar", 55555).singleResult();
Assert.assertNotNull(execution);
Assert.assertEquals(processInstance3.getId(), execution.getId());
Assert.assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("integerVar", 1).count());
// Test LESS_THAN
executions = runtimeService.createExecutionQuery().variableValueLessThan("integerVar", 55555).list();
Assert.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());
Assert.assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThan("integerVar", 12345).count());
Assert.assertEquals(3, runtimeService.createExecutionQuery().variableValueLessThan("integerVar", 66666).count());
// Test LESS_THAN_OR_EQUAL
executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("integerVar", 55555).list();
Assert.assertEquals(3, executions.size());
Assert.assertEquals(0, runtimeService.createExecutionQuery().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.Execution in project camunda-bpm-platform by camunda.
the class ExecutionQueryTest method testQueryAllVariableTypes.
@Deployment(resources = { "org/camunda/bpm/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();
Assert.assertNotNull(executions);
Assert.assertEquals(1, executions.size());
Assert.assertEquals(processInstance.getId(), executions.get(0).getId());
runtimeService.deleteProcessInstance(processInstance.getId(), "test");
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class ExecutionQueryTest method testQueryForExecutionsWithMessageEventSubscriptionsOverlappingFilters.
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/oneMessageCatchProcess.bpmn20.xml")
public void testQueryForExecutionsWithMessageEventSubscriptionsOverlappingFilters() {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneMessageCatchProcess");
Execution execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("newInvoiceMessage").messageEventSubscription().singleResult();
assertNotNull(execution);
assertEquals(instance.getId(), execution.getProcessInstanceId());
runtimeService.createExecutionQuery().messageEventSubscription().messageEventSubscriptionName("newInvoiceMessage").list();
assertNotNull(execution);
assertEquals(instance.getId(), execution.getProcessInstanceId());
}
Aggregations