use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class MigrationCompensationRemoveSubProcessTest method testCanRemoveEventScopeWithVariables.
@Test
public void testCanRemoveEventScopeWithVariables() {
// given
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.ONE_COMPENSATION_TASK_MODEL);
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask2", "userTask2").mapActivities("compensationBoundary", "compensationBoundary").build();
ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
Execution subProcessExecution = rule.getRuntimeService().createExecutionQuery().activityId("userTask1").singleResult();
rule.getRuntimeService().setVariableLocal(subProcessExecution.getId(), "foo", "bar");
testHelper.completeTask("userTask1");
// when
testHelper.migrateProcessInstance(migrationPlan, processInstance);
// then
Assert.assertEquals(0, rule.getRuntimeService().createVariableInstanceQuery().count());
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class MigrationCompensationAddSubProcessTest method testVariablesInParentEventScopeStillAccessible.
@Test
public void testVariablesInParentEventScopeStillAccessible() {
// given
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.DOUBLE_SUBPROCESS_MODEL);
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("subProcess", "outerSubProcess").mapActivities("compensationBoundary", "compensationBoundary").mapActivities("userTask2", "userTask2").build();
ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
Execution subProcessExecution = rule.getRuntimeService().createExecutionQuery().activityId("userTask1").singleResult();
rule.getRuntimeService().setVariableLocal(subProcessExecution.getId(), "foo", "bar");
testHelper.completeTask("userTask1");
testHelper.migrateProcessInstance(migrationPlan, processInstance);
// when throwing compensation
testHelper.completeAnyTask("userTask2");
// then the variable snapshot is available
Task compensationTask = rule.getTaskService().createTaskQuery().singleResult();
Assert.assertEquals("bar", rule.getTaskService().getVariable(compensationTask.getId(), "foo"));
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class MigrationCompensationTest method testCanMigrateSiblingEventScopeExecutions.
@Test
public void testCanMigrateSiblingEventScopeExecutions() {
// given
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.DOUBLE_SUBPROCESS_MODEL);
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask2", "userTask2").mapActivities("subProcess", "outerSubProcess").mapActivities("compensationBoundary", "compensationBoundary").build();
ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
// starting a second instances of the sub process
rule.getRuntimeService().createProcessInstanceModification(processInstance.getId()).startBeforeActivity("subProcess").execute();
List<Execution> subProcessExecutions = rule.getRuntimeService().createExecutionQuery().activityId("userTask1").list();
for (Execution subProcessExecution : subProcessExecutions) {
// set the same variable to a distinct value
rule.getRuntimeService().setVariableLocal(subProcessExecution.getId(), "var", subProcessExecution.getId());
}
testHelper.completeAnyTask("userTask1");
testHelper.completeAnyTask("userTask1");
// when
testHelper.migrateProcessInstance(migrationPlan, processInstance);
// then the variable snapshots during compensation are not shared
testHelper.completeAnyTask("userTask2");
List<Task> compensationTasks = rule.getTaskService().createTaskQuery().taskDefinitionKey("compensationHandler").list();
Assert.assertEquals(2, compensationTasks.size());
Object value1 = rule.getTaskService().getVariable(compensationTasks.get(0).getId(), "var");
Object value2 = rule.getTaskService().getVariable(compensationTasks.get(1).getId(), "var");
Assert.assertNotEquals(value1, value2);
}
use of org.camunda.bpm.engine.runtime.Execution 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.Execution in project camunda-bpm-platform by camunda.
the class BoundaryConditionalEventTest method testSubProcessVariableCondition.
@Test
@Deployment
public void testSubProcessVariableCondition() {
// given process with boundary conditional event on sub process
ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
Task task = taskQuery.singleResult();
assertNotNull(task);
assertEquals(TASK_IN_SUB_PROCESS, task.getName());
assertEquals(1, conditionEventSubscriptionQuery.list().size());
// when local variable is set on task with condition
taskService.setVariableLocal(task.getId(), VARIABLE_NAME, 1);
// then execution stays on user task
List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).list();
assertEquals(2, executions.size());
assertEquals(1, conditionEventSubscriptionQuery.list().size());
// when local variable is set on task execution
runtimeService.setVariableLocal(task.getExecutionId(), VARIABLE_NAME, 1);
// then process instance ends
tasksAfterVariableIsSet = taskQuery.list();
assertEquals(0, tasksAfterVariableIsSet.size());
}
Aggregations