use of org.camunda.bpm.engine.migration.MigrationPlan in project camunda-bpm-platform by camunda.
the class MigrationUserTaskTest method testAccessModelInTaskListenerAfterMigration.
@Test
public void testAccessModelInTaskListenerAfterMigration() {
BpmnModelInstance targetModel = modify(ProcessModels.ONE_TASK_PROCESS).changeElementId("userTask", "newUserTask");
addTaskListener(targetModel, "newUserTask", TaskListener.EVENTNAME_ASSIGNMENT, AccessModelInstanceTaskListener.class.getName());
// given
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetModel);
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask", "newUserTask").build();
ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
testHelper.migrateProcessInstance(migrationPlan, processInstance);
// when
Task task = rule.getTaskService().createTaskQuery().singleResult();
rule.getTaskService().setAssignee(task.getId(), "foo");
// then the task listener was able to access the bpmn model instance and set a variable
String variableValue = (String) rule.getRuntimeService().getVariable(processInstance.getId(), AccessModelInstanceTaskListener.VARIABLE_NAME);
Assert.assertEquals("newUserTask", variableValue);
}
use of org.camunda.bpm.engine.migration.MigrationPlan in project camunda-bpm-platform by camunda.
the class MigrationUserTaskTest method testChangeActivityId.
@Test
public void testChangeActivityId() {
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.PARALLEL_GATEWAY_PROCESS);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.PARALLEL_GATEWAY_PROCESS);
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask1", "userTask2").build();
ProcessInstance processInstance = rule.getRuntimeService().createProcessInstanceById(sourceProcessDefinition.getId()).startBeforeActivity("userTask1").execute();
// when
testHelper.migrateProcessInstance(migrationPlan, processInstance);
// then
testHelper.assertExecutionTreeAfterMigration().hasProcessDefinitionId(targetProcessDefinition.getId()).matches(describeExecutionTree("userTask2").scope().id(testHelper.snapshotBeforeMigration.getProcessInstanceId()).done());
testHelper.assertActivityTreeAfterMigration().hasStructure(describeActivityInstanceTree(targetProcessDefinition.getId()).activity("userTask2", testHelper.getSingleActivityInstanceBeforeMigration("userTask1").getId()).done());
Task migratedTask = testHelper.snapshotAfterMigration.getTaskForKey("userTask2");
Assert.assertNotNull(migratedTask);
Assert.assertEquals(targetProcessDefinition.getId(), migratedTask.getProcessDefinitionId());
Assert.assertEquals("userTask2", migratedTask.getTaskDefinitionKey());
// and it is possible to successfully complete the migrated instance
rule.getTaskService().complete(migratedTask.getId());
testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());
}
use of org.camunda.bpm.engine.migration.MigrationPlan in project camunda-bpm-platform by camunda.
the class MigrationWithoutTriggerConditionTest method testBoundaryConditionalEventWithSetVariableOnEndListener.
@Test
public void testBoundaryConditionalEventWithSetVariableOnEndListener() {
// given
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(modify(Bpmn.createExecutableProcess(PROC_DEF_KEY).startEvent().subProcess(SUB_PROCESS_ID).camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, SetVariableDelegate.class.getName()).embeddedSubProcess().startEvent().userTask(USER_TASK_ID).endEvent().subProcessDone().endEvent().done()).userTaskBuilder(USER_TASK_ID).boundaryEvent(BOUNDARY_ID).condition(VAR_CONDITION).endEvent().moveToActivity(SUB_PROCESS_ID).boundaryEvent().condition(VAR_CONDITION).userTask(TASK_AFTER_CONDITION_ID).endEvent().done());
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(ProcessModels.ONE_TASK_PROCESS).userTaskBuilder(USER_TASK_ID).boundaryEvent(BOUNDARY_ID).condition(VAR_CONDITION).userTask(TASK_AFTER_CONDITION_ID).endEvent().done());
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities(USER_TASK_ID, USER_TASK_ID).mapActivities(BOUNDARY_ID, BOUNDARY_ID).updateEventTrigger().build();
// when sub process is removed, end listener is called and sets variable
ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan);
testHelper.assertEventSubscriptionMigrated(BOUNDARY_ID, BOUNDARY_ID, null);
assertEquals(1, rule.getRuntimeService().getVariable(processInstance.getId(), VARIABLE_NAME));
// then conditional event is not triggered
assertEquals(USER_TASK_ID, rule.getTaskService().createTaskQuery().singleResult().getTaskDefinitionKey());
// when any var is set
testHelper.setAnyVariable(processInstance.getId());
// then condition is satisfied, since variable is already set which satisfies condition
testHelper.completeTask(TASK_AFTER_CONDITION_ID);
testHelper.assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.migration.MigrationPlan in project camunda-bpm-platform by camunda.
the class MigrationWithoutTriggerConditionTest method tesConditionalEventSubProcessWithSetVariableOnStartListener.
@Test
public void tesConditionalEventSubProcessWithSetVariableOnStartListener() {
// given
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(modify(ProcessModels.ONE_TASK_PROCESS).addSubProcessTo(PROC_DEF_KEY).triggerByEvent().embeddedSubProcess().startEvent(EVENT_SUB_PROCESS_START_ID).condition(VAR_CONDITION).userTask(TASK_AFTER_CONDITION_ID).endEvent().done());
BpmnModelInstance targetModel = modify(Bpmn.createExecutableProcess(PROC_DEF_KEY).startEvent().subProcess(SUB_PROCESS_ID).camundaExecutionListenerClass(ExecutionListener.EVENTNAME_START, SetVariableDelegate.class.getName()).embeddedSubProcess().startEvent().userTask(USER_TASK_ID).endEvent().subProcessDone().endEvent().done()).addSubProcessTo(SUB_PROCESS_ID).triggerByEvent().embeddedSubProcess().startEvent().condition(VAR_CONDITION).endEvent().done();
targetModel = modify(targetModel).addSubProcessTo(PROC_DEF_KEY).triggerByEvent().embeddedSubProcess().startEvent(EVENT_SUB_PROCESS_START_ID).condition(VAR_CONDITION).userTask(TASK_AFTER_CONDITION_ID).endEvent().done();
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetModel);
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities(USER_TASK_ID, USER_TASK_ID).mapActivities(EVENT_SUB_PROCESS_START_ID, EVENT_SUB_PROCESS_START_ID).updateEventTrigger().build();
// when sub process is added, start listener is called and sets variable
ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan);
testHelper.assertEventSubscriptionMigrated(EVENT_SUB_PROCESS_START_ID, EVENT_SUB_PROCESS_START_ID, null);
assertEquals(1, rule.getRuntimeService().getVariable(processInstance.getId(), VARIABLE_NAME));
// then conditional event is not triggered
assertEquals(USER_TASK_ID, rule.getTaskService().createTaskQuery().singleResult().getTaskDefinitionKey());
// when any var is set
testHelper.setAnyVariable(processInstance.getId());
// then condition is satisfied, since variable is already set which satisfies condition
testHelper.completeTask(TASK_AFTER_CONDITION_ID);
testHelper.assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.migration.MigrationPlan in project camunda-bpm-platform by camunda.
the class MigrationPlanGenerationTest method assertGeneratedMigrationPlan.
protected MigrationPlanAssert assertGeneratedMigrationPlan(BpmnModelInstance sourceProcess, BpmnModelInstance targetProcess, boolean updateEventTriggers) {
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceProcess);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetProcess);
MigrationInstructionsBuilder migrationInstructionsBuilder = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapEqualActivities();
if (updateEventTriggers) {
migrationInstructionsBuilder.updateEventTriggers();
}
MigrationPlan migrationPlan = migrationInstructionsBuilder.build();
assertThat(migrationPlan).hasSourceProcessDefinition(sourceProcessDefinition).hasTargetProcessDefinition(targetProcessDefinition);
return assertThat(migrationPlan);
}
Aggregations