Search in sources :

Example 71 with ExecutionTree

use of org.camunda.bpm.engine.test.util.ExecutionTree in project camunda-bpm-platform by camunda.

the class MigrationVariablesTest method testVariableAtConcurrentAndScopeExecutionBecomeNonScope.

@Test
public void testVariableAtConcurrentAndScopeExecutionBecomeNonScope() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(CONCURRENT_BOUNDARY_TASKS);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.PARALLEL_GATEWAY_PROCESS);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapEqualActivities().build();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    ExecutionTree executionTreeBeforeMigration = ExecutionTree.forExecution(processInstance.getId(), rule.getProcessEngine());
    ExecutionTree scopeExecution = executionTreeBeforeMigration.getLeafExecutions("userTask1").get(0);
    ExecutionTree concurrentExecution = scopeExecution.getParent();
    runtimeService.setVariableLocal(scopeExecution.getId(), "foo", 42);
    runtimeService.setVariableLocal(concurrentExecution.getId(), "foo", 42);
    // when
    try {
        testHelper.migrateProcessInstance(migrationPlan, processInstance);
        Assert.fail("expected exception");
    } catch (ProcessEngineException e) {
        Assert.assertThat(e.getMessage(), CoreMatchers.containsString("The variable 'foo' exists in both, this scope" + " and concurrent local in the parent scope. Migrating to a non-scope activity would overwrite one of them."));
    }
}
Also used : ExecutionTree(org.camunda.bpm.engine.test.util.ExecutionTree) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Test(org.junit.Test)

Example 72 with ExecutionTree

use of org.camunda.bpm.engine.test.util.ExecutionTree in project camunda-bpm-platform by camunda.

the class MigrationVariablesTest method testVariableAtConcurrentExecutionAddParentScopeBecomeNonConcurrent.

@Test
public void testVariableAtConcurrentExecutionAddParentScopeBecomeNonConcurrent() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.PARALLEL_GATEWAY_PROCESS);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(ProcessModels.PARALLEL_TASK_AND_SUBPROCESS_PROCESS).activityBuilder("subProcess").camundaInputParameter("foo", "subProcessValue").done());
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask1", "userTask1").mapActivities("userTask2", "userTask2").build();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    ExecutionTree executionTreeBeforeMigration = ExecutionTree.forExecution(processInstance.getId(), rule.getProcessEngine());
    ExecutionTree task1CcExecution = executionTreeBeforeMigration.getLeafExecutions("userTask1").get(0);
    ExecutionTree task2CcExecution = executionTreeBeforeMigration.getLeafExecutions("userTask2").get(0);
    runtimeService.setVariableLocal(task1CcExecution.getId(), "foo", "task1Value");
    runtimeService.setVariableLocal(task2CcExecution.getId(), "foo", "task2Value");
    // when
    testHelper.migrateProcessInstance(migrationPlan, processInstance);
    // then the io mapping variable was overwritten due to a compacted execution tree
    Assert.assertEquals(2, testHelper.snapshotAfterMigration.getVariables().size());
    List<String> values = new ArrayList<String>();
    for (VariableInstance variable : testHelper.snapshotAfterMigration.getVariables()) {
        values.add((String) variable.getValue());
    }
    Assert.assertTrue(values.contains("task1Value"));
    Assert.assertTrue(values.contains("task2Value"));
}
Also used : ExecutionTree(org.camunda.bpm.engine.test.util.ExecutionTree) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ArrayList(java.util.ArrayList) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 73 with ExecutionTree

use of org.camunda.bpm.engine.test.util.ExecutionTree in project camunda-bpm-platform by camunda.

the class MigrationVariablesTest method testVariableAtScopeExecutionBecomeNonScope.

@Test
public void testVariableAtScopeExecutionBecomeNonScope() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ONE_BOUNDARY_TASK);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapEqualActivities().build();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    ExecutionTree executionTreeBeforeMigration = ExecutionTree.forExecution(processInstance.getId(), rule.getProcessEngine());
    ExecutionTree scopeExecution = executionTreeBeforeMigration.getExecutions().get(0);
    runtimeService.setVariableLocal(scopeExecution.getId(), "foo", 42);
    // when
    testHelper.migrateProcessInstance(migrationPlan, processInstance);
    // then
    VariableInstance beforeMigration = testHelper.snapshotBeforeMigration.getSingleVariable("foo");
    Assert.assertEquals(1, testHelper.snapshotAfterMigration.getVariables().size());
    testHelper.assertVariableMigratedToExecution(beforeMigration, processInstance.getId());
    // and the variable is concurrent local, i.e. expands on tree expansion
    runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("userTask").execute();
    VariableInstance variableAfterExpansion = runtimeService.createVariableInstanceQuery().singleResult();
    Assert.assertNotNull(variableAfterExpansion);
    Assert.assertNotSame(processInstance.getId(), variableAfterExpansion.getExecutionId());
}
Also used : ExecutionTree(org.camunda.bpm.engine.test.util.ExecutionTree) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 74 with ExecutionTree

use of org.camunda.bpm.engine.test.util.ExecutionTree in project camunda-bpm-platform by camunda.

the class MigrationVariablesTest method testAddScopeWithInputMappingAndVariableOnConcurrentExecutions.

@Test
public void testAddScopeWithInputMappingAndVariableOnConcurrentExecutions() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.PARALLEL_GATEWAY_PROCESS);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(ProcessModels.PARALLEL_GATEWAY_SUBPROCESS_PROCESS).activityBuilder("subProcess").camundaInputParameter("foo", "inputOutputValue").done());
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask1", "userTask1").mapActivities("userTask2", "userTask2").build();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    ExecutionTree executionTreeBeforeMigration = ExecutionTree.forExecution(processInstance.getId(), rule.getProcessEngine());
    ExecutionTree userTask1CCExecutionBefore = executionTreeBeforeMigration.getLeafExecutions("userTask1").get(0);
    ExecutionTree userTask2CCExecutionBefore = executionTreeBeforeMigration.getLeafExecutions("userTask2").get(0);
    runtimeService.setVariableLocal(userTask1CCExecutionBefore.getId(), "foo", "customValue");
    runtimeService.setVariableLocal(userTask2CCExecutionBefore.getId(), "foo", "customValue");
    // when
    testHelper.migrateProcessInstance(migrationPlan, processInstance);
    // then the scope variable instance has been overwritten during compaction (conform to prior behavior);
    // although this is tested here, changing this behavior may be ok in the future
    Collection<VariableInstance> variables = testHelper.snapshotAfterMigration.getVariables();
    Assert.assertEquals(2, variables.size());
    for (VariableInstance variable : variables) {
        Assert.assertEquals("customValue", variable.getValue());
    }
    ExecutionTree subProcessExecution = testHelper.snapshotAfterMigration.getExecutionTree().getLeafExecutions("userTask2").get(0).getParent();
    Assert.assertNotNull(testHelper.snapshotAfterMigration.getSingleVariable(subProcessExecution.getId(), "foo"));
}
Also used : ExecutionTree(org.camunda.bpm.engine.test.util.ExecutionTree) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 75 with ExecutionTree

use of org.camunda.bpm.engine.test.util.ExecutionTree in project camunda-bpm-platform by camunda.

the class MigrationVariablesTest method testVariableAtScopeExecutionInScopeActivityAddParentScope.

@Test
public void testVariableAtScopeExecutionInScopeActivityAddParentScope() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ONE_BOUNDARY_TASK);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(SUBPROCESS_CONCURRENT_BOUNDARY_TASKS);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask", "userTask1").build();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    ExecutionTree executionTreeBeforeMigration = ExecutionTree.forExecution(processInstance.getId(), rule.getProcessEngine());
    ExecutionTree scopeExecution = executionTreeBeforeMigration.getExecutions().get(0);
    runtimeService.setVariableLocal(scopeExecution.getId(), "foo", 42);
    // when
    testHelper.migrateProcessInstance(migrationPlan, processInstance);
    // then
    VariableInstance beforeMigration = testHelper.snapshotBeforeMigration.getSingleVariable("foo");
    Assert.assertEquals(1, testHelper.snapshotAfterMigration.getVariables().size());
    testHelper.assertVariableMigratedToExecution(beforeMigration, beforeMigration.getExecutionId());
}
Also used : ExecutionTree(org.camunda.bpm.engine.test.util.ExecutionTree) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Aggregations

ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)155 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)149 Deployment (org.camunda.bpm.engine.test.Deployment)134 ExecutionAssert.describeExecutionTree (org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree)134 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)130 Task (org.camunda.bpm.engine.task.Task)40 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)20 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)20 Test (org.junit.Test)20 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)17 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)15 Execution (org.camunda.bpm.engine.runtime.Execution)9 Job (org.camunda.bpm.engine.runtime.Job)6 TransitionInstance (org.camunda.bpm.engine.runtime.TransitionInstance)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 RequiredHistoryLevel (org.camunda.bpm.engine.test.RequiredHistoryLevel)2 RecorderExecutionListener (org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener)2 RecordedEvent (org.camunda.bpm.engine.test.bpmn.executionlistener.RecorderExecutionListener.RecordedEvent)2 ArrayList (java.util.ArrayList)1 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)1