use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.
the class VariableInstanceQueryTest method testSequentialMultiInstanceSubProcess.
@Deployment
public void testSequentialMultiInstanceSubProcess() {
// given a process instance in sequential MI
ProcessInstance instance = runtimeService.startProcessInstanceByKey("miSequentialSubprocess");
// when
VariableInstance nrOfInstances = runtimeService.createVariableInstanceQuery().variableName("nrOfInstances").singleResult();
VariableInstance nrOfActiveInstances = runtimeService.createVariableInstanceQuery().variableName("nrOfActiveInstances").singleResult();
VariableInstance nrOfCompletedInstances = runtimeService.createVariableInstanceQuery().variableName("nrOfCompletedInstances").singleResult();
VariableInstance loopCounter = runtimeService.createVariableInstanceQuery().variableName("loopCounter").singleResult();
// then the activity instance ids of the variable instances should be correct
ActivityInstance tree = runtimeService.getActivityInstance(instance.getId());
assertEquals(tree.getActivityInstances("miSubProcess#multiInstanceBody")[0].getId(), nrOfInstances.getActivityInstanceId());
assertEquals(tree.getActivityInstances("miSubProcess#multiInstanceBody")[0].getId(), nrOfActiveInstances.getActivityInstanceId());
assertEquals(tree.getActivityInstances("miSubProcess#multiInstanceBody")[0].getId(), nrOfCompletedInstances.getActivityInstanceId());
assertEquals(tree.getActivityInstances("miSubProcess#multiInstanceBody")[0].getId(), loopCounter.getActivityInstanceId());
}
use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.
the class VariableInstanceQueryTest method testParallelGatewayVariables.
@Test
@Deployment
public void testParallelGatewayVariables() {
// given
Map<String, Object> processVariables = new HashMap<String, Object>();
processVariables.put("processVariable", "aProcessVariable");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("parallelGatewayProcess", processVariables);
Execution execution = runtimeService.createExecutionQuery().activityId("task1").singleResult();
runtimeService.setVariableLocal(execution.getId(), "aLocalVariable", "aLocalValue");
ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
assertEquals(2, tree.getChildActivityInstances().length);
ActivityInstance task1Instance = tree.getActivityInstances("task1")[0];
VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableName("aLocalVariable").activityInstanceIdIn(task1Instance.getId());
VariableInstance localVariable = query.singleResult();
assertNotNull(localVariable);
assertEquals("aLocalVariable", localVariable.getName());
assertEquals("aLocalValue", localVariable.getValue());
Task task = taskService.createTaskQuery().executionId(execution.getId()).singleResult();
taskService.complete(task.getId());
tree = runtimeService.getActivityInstance(processInstance.getId());
assertEquals(2, tree.getChildActivityInstances().length);
ActivityInstance task3Instance = tree.getActivityInstances("task3")[0];
query = runtimeService.createVariableInstanceQuery().variableName("aLocalVariable").activityInstanceIdIn(task3Instance.getId());
localVariable = query.singleResult();
assertNotNull(localVariable);
assertEquals("aLocalVariable", localVariable.getName());
assertEquals("aLocalValue", localVariable.getValue());
}
use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.
the class VariableInstanceQueryTest method testSubProcessVariablesWithParallelGateway.
@Test
@Deployment
public void testSubProcessVariablesWithParallelGateway() {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processWithSubProcess");
ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
assertNotNull(tree);
ActivityInstance[] subprocessInstances = tree.getActivityInstances("SubProcess_1");
assertEquals(5, subprocessInstances.length);
// when
String activityInstanceId1 = subprocessInstances[0].getId();
VariableInstanceQuery query1 = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(activityInstanceId1);
String activityInstanceId2 = subprocessInstances[1].getId();
VariableInstanceQuery query2 = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(activityInstanceId2);
String activityInstanceId3 = subprocessInstances[2].getId();
VariableInstanceQuery query3 = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(activityInstanceId3);
String activityInstanceId4 = subprocessInstances[3].getId();
VariableInstanceQuery query4 = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(activityInstanceId4);
String activityInstanceId5 = subprocessInstances[4].getId();
VariableInstanceQuery query5 = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(activityInstanceId5);
// then
checkVariables(query1.list());
checkVariables(query2.list());
checkVariables(query3.list());
checkVariables(query4.list());
checkVariables(query5.list());
}
use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.
the class MigrationMultiInstanceTest method testMigrateParallelMultiInstancePartiallyComplete.
@Test
public void testMigrateParallelMultiInstancePartiallyComplete() {
// given
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(MultiInstanceProcessModels.PAR_MI_ONE_TASK_PROCESS);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(MultiInstanceProcessModels.PAR_MI_ONE_TASK_PROCESS);
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities(miBodyOf("userTask"), miBodyOf("userTask")).mapActivities("userTask", "userTask").build();
// when
ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
testHelper.completeAnyTask("userTask");
testHelper.migrateProcessInstance(migrationPlan, processInstance);
// then
testHelper.assertExecutionTreeAfterMigration().hasProcessDefinitionId(targetProcessDefinition.getId()).matches(describeExecutionTree(null).scope().id(testHelper.snapshotBeforeMigration.getProcessInstanceId()).child(null).scope().id(testHelper.getSingleExecutionIdForActivityBeforeMigration(miBodyOf("userTask"))).child("userTask").concurrent().noScope().up().child("userTask").concurrent().noScope().up().child("userTask").concurrent().noScope().up().done());
ActivityInstance[] userTaskInstances = testHelper.snapshotBeforeMigration.getActivityTree().getActivityInstances("userTask");
testHelper.assertActivityTreeAfterMigration().hasStructure(describeActivityInstanceTree(targetProcessDefinition.getId()).beginMiBody("userTask", testHelper.getSingleActivityInstanceBeforeMigration(miBodyOf("userTask")).getId()).activity("userTask", userTaskInstances[0].getId()).activity("userTask", userTaskInstances[1].getId()).transition(// bug CAM-5609
"userTask").done());
List<Task> migratedTasks = testHelper.snapshotAfterMigration.getTasks();
Assert.assertEquals(2, migratedTasks.size());
for (Task migratedTask : migratedTasks) {
assertEquals(targetProcessDefinition.getId(), migratedTask.getProcessDefinitionId());
}
// and it is possible to successfully complete the migrated instance
for (Task migratedTask : migratedTasks) {
rule.getTaskService().complete(migratedTask.getId());
}
testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());
}
use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.
the class AsyncTaskTest method assertTransitionInstances.
protected void assertTransitionInstances(String processInstanceId, String activityId, int numInstances) {
ActivityInstance tree = runtimeService.getActivityInstance(processInstanceId);
assertEquals(numInstances, tree.getTransitionInstances(activityId).length);
}
Aggregations