Example #1
0
        public virtual void testStartBeforeEventSubProcess()
        {
            var processInstance   = runtimeService.StartProcessInstanceByKey("process");
            var ProcessInstanceId = processInstance.Id;

            runtimeService.CreateProcessInstanceModification(ProcessInstanceId)
            .StartBeforeActivity("eventSubProcess")
            .Execute();

            var updatedTree = runtimeService.GetActivityInstance(ProcessInstanceId);

            Assert.NotNull(updatedTree);
            Assert.AreEqual(ProcessInstanceId, updatedTree.ProcessInstanceId);

            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processInstance.ProcessDefinitionId)
                          .BeginScope("eventSubProcess")
                          .Activity("eventSubProcessTask")
                          .EndScope()
                          .Done());

            var executionTree = ExecutionTree.ForExecution(ProcessInstanceId, ProcessEngine);

            ExecutionAssert.That(executionTree)
            .Matches(ExecutionAssert.DescribeExecutionTree(null)
                     .Scope()
                     .Child("eventSubProcessTask")
                     .Scope()
                     .Done());

            completeTasksInOrder("eventSubProcessTask");
            AssertProcessEnded(ProcessInstanceId);
        }
        public virtual void testCase1AssertActivityInstance()
        {
            // given
            var sourceProcessDefinition =
                testHelper.DeployAndGetDefinition(CompensationModels.COMPENSATION_TWO_TASKS_SUBPROCESS_MODEL);
            var targetProcessDefinition =
                testHelper.DeployAndGetDefinition(CompensationModels.ONE_COMPENSATION_TASK_MODEL);

            var migrationPlan =
                rule.RuntimeService.CreateMigrationPlan(sourceProcessDefinition.Id, targetProcessDefinition.Id)
                .MapActivities("userTask2", "userTask2")
                .MapActivities("compensationBoundary", "compensationBoundary")
                .Build();

            var processInstance = rule.RuntimeService.StartProcessInstanceById(sourceProcessDefinition.Id);

            testHelper.CompleteTask("userTask1");
            testHelper.MigrateProcessInstance(migrationPlan, processInstance);

            // when
            testHelper.CompleteTask("userTask2");

            // then
            var activityInstance = rule.RuntimeService.GetActivityInstance(processInstance.Id);

            ActivityInstanceAssert.That(activityInstance)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(targetProcessDefinition.Id)
                          .Activity("compensationEvent")
                          .Activity("compensationHandler")
                          .Done());
        }
        public virtual void shouldRestartProcessInstanceUsingHistoricProcessInstanceQuery()
        {
            // given
            var processDefinition = testRule.DeployAndGetDefinition(ProcessModels.TwoTasksProcess);
            var processInstance   = runtimeService.StartProcessInstanceByKey("Process");

            runtimeService.DeleteProcessInstance(processInstance.Id, "test");

            // when
            var historicProcessInstanceQuery = engineRule.HistoryService.CreateHistoricProcessInstanceQuery(c => c.ProcessDefinitionId == processDefinition.Id);

            runtimeService.RestartProcessInstances(processDefinition.Id)
            .StartBeforeActivity("userTask1")
            .SetHistoricProcessInstanceQuery(historicProcessInstanceQuery)
            .Execute();

            // then
            var restartedProcessInstance = runtimeService.CreateProcessInstanceQuery(c => c.SuspensionState == SuspensionStateFields.Active.StateCode)
                                           .First();

            var updatedTree = runtimeService.GetActivityInstance(restartedProcessInstance.Id);

            Assert.NotNull(updatedTree);
            Assert.AreEqual(restartedProcessInstance.Id, updatedTree.ProcessInstanceId);
            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processDefinition.Id)
                          .Activity("userTask1")
                          .Done());
        }
        public virtual void testModificationJobsExecutionByJobExecutorWithAuthorizationEnabledAndTenant()
        {
            var processEngineConfiguration = rule.ProcessEngineConfiguration;

            processEngineConfiguration.SetAuthorizationEnabled(true);
            var processDefinition = testRule.DeployForTenantAndGetDefinition("tenantId", instance);

            try
            {
                var batch = helper.StartAfterAsync("process1", 10, "user1", processDefinition.Id);
                helper.ExecuteSeedJob(batch);

                testRule.WaitForJobExecutorToProcessAllJobs();

                // then all process instances where modified
                foreach (var ProcessInstanceId in helper.CurrentProcessInstances)
                {
                    var updatedTree = runtimeService.GetActivityInstance(ProcessInstanceId);
                    Assert.NotNull(updatedTree);
                    Assert.AreEqual(ProcessInstanceId, updatedTree.ProcessInstanceId);

                    ActivityInstanceAssert.That(updatedTree)
                    .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processDefinition.Id)
                                  .Activity("user1")
                                  .Activity("user2")
                                  .Done());
                }
            }
            finally
            {
                processEngineConfiguration.SetAuthorizationEnabled(false);
            }
        }
        public virtual void testStartBeforeNoneEndEvent()
        {
            var processInstance   = runtimeService.StartProcessInstanceByKey("oneTaskProcess");
            var ProcessInstanceId = processInstance.Id;

            // when I start before the none end event
            runtimeService.CreateProcessInstanceModification(ProcessInstanceId)
            .StartBeforeActivity("theEnd")
            .Execute();

            // then there is no effect
            var updatedTree = runtimeService.GetActivityInstance(ProcessInstanceId);

            Assert.NotNull(updatedTree);
            Assert.AreEqual(ProcessInstanceId, updatedTree.ProcessInstanceId);

            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processInstance.ProcessDefinitionId)
                          .Activity("theTask")
                          .Done());

            var executionTree = ExecutionTree.ForExecution(ProcessInstanceId, ProcessEngine);

            ExecutionAssert.That(executionTree)
            .Matches(ExecutionAssert.DescribeExecutionTree("theTask")
                     .Scope()
                     .Done());

            completeTasksInOrder("theTask");
            AssertProcessEnded(ProcessInstanceId);
        }
Example #6
0
        public virtual void testAssertTrees()
        {
            // given
            var sourceProcessDefinition = testHelper.DeployAndGetDefinition(TransactionModels.ONE_TASK_TRANSACTION);
            var targetProcessDefinition = testHelper.DeployAndGetDefinition(TransactionModels.ONE_TASK_TRANSACTION);

            var migrationPlan =
                rule.RuntimeService.CreateMigrationPlan(sourceProcessDefinition.Id, targetProcessDefinition.Id)
                .MapActivities("transaction", "transaction")
                .MapActivities("userTask", "userTask")
                .Build();

            // when
            testHelper.CreateProcessInstanceAndMigrate(migrationPlan);

            // then
            testHelper.AssertExecutionTreeAfterMigration()
            .HasProcessDefinitionId(targetProcessDefinition.Id)
            .Matches(ExecutionAssert.DescribeExecutionTree(null)
                     .Scope()
                     .Id(testHelper.SnapshotBeforeMigration.ProcessInstanceId)
                     .Child("userTask")
                     .Scope()
                     .Id(testHelper.GetSingleExecutionIdForActivityBeforeMigration("userTask"))
                     .Up()
                     .Done());

            testHelper.AssertActivityTreeAfterMigration()
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(targetProcessDefinition.Id)
                          .BeginScope("transaction", testHelper.GetSingleActivityInstanceBeforeMigration("transaction")
                                      .Id)
                          .Activity("userTask", testHelper.GetSingleActivityInstanceBeforeMigration("userTask")
                                    .Id)
                          .Done());
        }
        public virtual void testMigrateCompensationSubscriptionAddRemoveSubProcessAssertActivityInstance()
        {
            // given
            var sourceProcessDefinition =
                testHelper.DeployAndGetDefinition(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL);
            var targetProcessDefinition =
                testHelper.DeployAndGetDefinition(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL);

            // subProcess is not mapped
            var migrationPlan =
                rule.RuntimeService.CreateMigrationPlan(sourceProcessDefinition.Id, targetProcessDefinition.Id)
                .MapActivities("userTask2", "userTask2")
                .MapActivities("compensationBoundary", "compensationBoundary")
                .Build();

            var processInstance = rule.RuntimeService.StartProcessInstanceById(sourceProcessDefinition.Id);

            testHelper.CompleteTask("userTask1");

            testHelper.MigrateProcessInstance(migrationPlan, processInstance);

            // when compensating
            testHelper.CompleteTask("userTask2");

            // then the activity instance tree is correct
            var activityInstance = rule.RuntimeService.GetActivityInstance(processInstance.Id);

            ActivityInstanceAssert.That(activityInstance)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(targetProcessDefinition.Id)
                          .Activity("compensationEvent")
                          .BeginScope("subProcess")
                          .Activity("compensationHandler")
                          .Done());
        }
        public virtual void testMigrateGatewayExecutionTree()
        {
            // given
            var sourceProcessDefinition =
                testHelper.DeployAndGetDefinition(EventBasedGatewayModels.TIMER_EVENT_BASED_GW_PROCESS);
            var targetProcessDefinition =
                testHelper.DeployAndGetDefinition(EventBasedGatewayModels.TIMER_EVENT_BASED_GW_PROCESS);

            var migrationPlan =
                rule.RuntimeService.CreateMigrationPlan(sourceProcessDefinition.Id, targetProcessDefinition.Id)
                .MapActivities("eventBasedGateway", "eventBasedGateway")
                .Build();

            // when
            testHelper.CreateProcessInstanceAndMigrate(migrationPlan);

            // then
            testHelper.AssertExecutionTreeAfterMigration()
            .HasProcessDefinitionId(targetProcessDefinition.Id)
            .Matches(ExecutionAssert.DescribeExecutionTree(null)
                     .Scope()
                     .Id(testHelper.SnapshotBeforeMigration.ProcessInstanceId)
                     .Child("eventBasedGateway")
                     .Scope()
                     .Id(testHelper.GetSingleExecutionIdForActivityBeforeMigration("eventBasedGateway"))
                     .Done());

            testHelper.AssertActivityTreeAfterMigration()
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(targetProcessDefinition.Id)
                          .Activity("eventBasedGateway",
                                    testHelper.GetSingleActivityInstanceBeforeMigration("eventBasedGateway")
                                    .Id)
                          .Done());
        }
        public virtual void testRemoveScopeAndMoveToConcurrentActivity()
        {
            // given
            var sourceProcessDefinition =
                testHelper.DeployAndGetDefinition(ProcessModels.ParallelGatewaySubprocessProcess);
            var targetProcessDefinition =
                testHelper.DeployAndGetDefinition(ProcessModels.ParallelTaskAndSubprocessProcess);

            var migrationPlan =
                rule.RuntimeService.CreateMigrationPlan(sourceProcessDefinition.Id, targetProcessDefinition.Id)
                .MapActivities("subProcess", "subProcess")
                .MapActivities("userTask1", "userTask1")
                .MapActivities("userTask2", "userTask2")
                .Build();

            // when
            testHelper.CreateProcessInstanceAndMigrate(migrationPlan);

            // then
            testHelper.AssertExecutionTreeAfterMigration()
            .HasProcessDefinitionId(targetProcessDefinition.Id)
            .Matches(ExecutionAssert.DescribeExecutionTree(null)
                     .Scope()
                     .Id(testHelper.SnapshotBeforeMigration.ProcessInstanceId)
                     .Child("userTask2")
                     .Concurrent()
                     .NoScope()
                     .Up()
                     .Child(null)
                     .Concurrent()
                     .NoScope()
                     .Child("userTask1")
                     .Scope()
                     .Done());

            testHelper.AssertActivityTreeAfterMigration()
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(targetProcessDefinition.Id)
                          .Activity("userTask2", testHelper.GetSingleActivityInstanceBeforeMigration("userTask2")
                                    .Id)
                          .BeginScope("subProcess", testHelper.GetSingleActivityInstanceBeforeMigration("subProcess")
                                      .Id)
                          .Activity("userTask1", testHelper.GetSingleActivityInstanceBeforeMigration("userTask1")
                                    .Id)
                          .Done());

            var migratedTasks = testHelper.SnapshotAfterMigration.Tasks;

            Assert.AreEqual(2, migratedTasks.Count);
            foreach (var migratedTask in migratedTasks)
            {
                Assert.AreEqual(targetProcessDefinition.Id, migratedTask.ProcessDefinitionId);
            }

            // and it is possible to successfully complete the migrated instance
            foreach (var migratedTask in migratedTasks)
            {
                rule.TaskService.Complete(migratedTask.Id);
            }
            testHelper.AssertProcessEnded(testHelper.SnapshotBeforeMigration.ProcessInstanceId);
        }
        public virtual void testTrees()
        {
            // given
            var sourceProcessDefinition = testHelper.DeployAndGetDefinition(ExternalTaskModels.ONE_EXTERNAL_TASK_PROCESS);
            var targetProcessDefinition = testHelper.DeployAndGetDefinition(ExternalTaskModels.ONE_EXTERNAL_TASK_PROCESS);

            var migrationPlan =
                rule.RuntimeService.CreateMigrationPlan(sourceProcessDefinition.Id, targetProcessDefinition.Id)
                .MapActivities("externalTask", "externalTask")
                .Build();

            var processInstance = rule.RuntimeService.StartProcessInstanceById(sourceProcessDefinition.Id);

            // when
            testHelper.MigrateProcessInstance(migrationPlan, processInstance);

            // then the execution and activity instance tree are exactly as before migration
            testHelper.AssertExecutionTreeAfterMigration()
            .HasProcessDefinitionId(targetProcessDefinition.Id)
            .Matches(ExecutionAssert.DescribeExecutionTree(null)
                     .Scope()
                     .Id(testHelper.SnapshotBeforeMigration.ProcessInstanceId)
                     .Child("externalTask")
                     .Scope()
                     .Id(testHelper.GetSingleExecutionIdForActivityBeforeMigration("externalTask"))
                     .Done());

            testHelper.AssertActivityTreeAfterMigration()
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(targetProcessDefinition.Id)
                          .Activity("externalTask", testHelper.GetSingleActivityInstanceBeforeMigration("externalTask")
                                    .Id)
                          .Done());
        }
Example #11
0
        public virtual void TestStartBeforeAndCancelAll()
        {
            var deployment = TestRule.Deploy(Instance);
            var definition = deployment.DeployedProcessDefinitions[0];

            var processInstanceIds = Helper.StartInstances("process1", 2);

            RuntimeService.CreateModification(definition.Id)
            .CancelAllForActivity("user1")
            .StartBeforeActivity("user2")
            .SetProcessInstanceIds(processInstanceIds)
            .Execute();

            foreach (var processInstanceId in processInstanceIds)
            {
                var updatedTree = RuntimeService.GetActivityInstance(processInstanceId);
                Assert.NotNull(updatedTree);
                Assert.AreEqual(processInstanceId, updatedTree.ProcessInstanceId);

                ActivityInstanceAssert.That(updatedTree)
                .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(definition.Id)
                              .Activity("user2")
                              .Done());
            }
        }
Example #12
0
        public virtual void testAddScopeDoesNotBecomeAsync()
        {
            // given
            var sourceProcessDefinition = testHelper.DeployAndGetDefinition(ProcessModels.OneTaskProcess);
            var targetProcessDefinition =
                testHelper.DeployAndGetDefinition(ModifiableBpmnModelInstance.Modify(ProcessModels.SubprocessProcess)
                                                  //.ActivityBuilder("subProcess")
                                                  //.CamundaAsyncBefore()
                                                  //.Done()
                                                  );

            var migrationPlan =
                rule.RuntimeService.CreateMigrationPlan(sourceProcessDefinition.Id, targetProcessDefinition.Id)
                .MapActivities("userTask", "userTask")
                .Build();

            // when
            testHelper.CreateProcessInstanceAndMigrate(migrationPlan);

            // then the async flag for the subprocess was not relevant for instantiation
            testHelper.AssertActivityTreeAfterMigration()
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(targetProcessDefinition.Id)
                          .BeginScope("subProcess")
                          .Activity("userTask", testHelper.GetSingleActivityInstanceBeforeMigration("userTask")
                                    .Id)
                          .Done());

            Assert.AreEqual(0, testHelper.SnapshotAfterMigration.Jobs.Count);
        }
        public virtual void testSingleActivityInstantiationById()
        {
            // given
            var processDefinitionId = repositoryService.CreateProcessDefinitionQuery()
                                      .First()
                                      .Id;

            // when
            var instance = runtimeService.CreateProcessInstanceById(processDefinitionId)
                           .StartBeforeActivity("task1")
                           .Execute();

            // then
            Assert.NotNull(instance);

            var updatedTree = runtimeService.GetActivityInstance(instance.Id);

            Assert.NotNull(updatedTree);

            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(instance.ProcessDefinitionId)
                          .Activity("task1")
                          .Done());

            // and it is possible to end the process
            completeTasksInOrder("task1");
            AssertProcessEnded(instance.Id);
        }
        public virtual void testCanOnlyTriggerCompensationInParentOfRemovedScope()
        {
            var sourceModel = ProcessModels.NewModel()
                              .StartEvent()
                              .SubProcess("outerSubProcess")
                              //.EmbeddedSubProcess()
                              //.StartEvent()
                              .UserTask("userTask1")
                              .BoundaryEvent("compensationBoundary")
                              //.CompensateEventDefinition()
                              //.CompensateEventDefinitionDone()
                              //.MoveToActivity("userTask1")
                              .SubProcess("innerSubProcess")
                              //.EmbeddedSubProcess()
                              //.StartEvent()
                              .UserTask("userTask2")
                              .EndEvent()
                              .SubProcessDone()
                              .EndEvent()
                              .SubProcessDone()
                              .Done();

            CompensationModels.addUserTaskCompensationHandler(sourceModel, "compensationBoundary", "compensationHandler");

            var sourceProcessDefinition = testHelper.DeployAndGetDefinition(sourceModel);
            var targetProcessDefinition =
                testHelper.DeployAndGetDefinition(
                    ModifiableBpmnModelInstance.Modify(CompensationModels.COMPENSATION_TWO_TASKS_SUBPROCESS_MODEL)
                    .EndEventBuilder("subProcessEnd")
                    //.CompensateEventDefinition()
                    //.WaitForCompletion(true)
                    //.CompensateEventDefinitionDone()
                    .Done());

            var migrationPlan =
                rule.RuntimeService.CreateMigrationPlan(sourceProcessDefinition.Id, targetProcessDefinition.Id)
                .MapActivities("innerSubProcess", "subProcess")
                .MapActivities("userTask2", "userTask2")
                .MapActivities("compensationBoundary", "compensationBoundary")
                .Build();

            var processInstance = rule.RuntimeService.StartProcessInstanceById(sourceProcessDefinition.Id);

            testHelper.CompleteTask("userTask1");
            testHelper.MigrateProcessInstance(migrationPlan, processInstance);

            // when
            testHelper.CompleteTask("userTask2");

            // then compensation is not triggered from inside the inner sub process
            // but only on process definition level
            var activityInstance = rule.RuntimeService.GetActivityInstance(processInstance.Id);

            ActivityInstanceAssert.That(activityInstance)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(targetProcessDefinition.Id)
                          .Activity("compensationEvent")
                          .BeginScope("subProcess")
                          .Activity("compensationHandler")
                          .Done());
        }
        public virtual void testNestedActivitiesInstantiation()
        {
            // when
            var instance = runtimeService.CreateProcessInstanceByKey("subprocess")
                           .StartBeforeActivity("innerTask")
                           .StartBeforeActivity("outerTask")
                           .StartBeforeActivity("innerTask")
                           .Execute();

            // then
            Assert.NotNull(instance);

            var updatedTree = runtimeService.GetActivityInstance(instance.Id);

            Assert.NotNull(updatedTree);

            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(instance.ProcessDefinitionId)
                          .Activity("outerTask")
                          .BeginScope("subProcess")
                          .Activity("innerTask")
                          .Activity("innerTask")
                          .Done());

            // and it is possible to end the process
            completeTasksInOrder("innerTask", "innerTask", "outerTask", "innerTask");
            AssertProcessEnded(instance.Id);
        }
        public virtual void testStartAsyncTask()
        {
            // when
            var instance = runtimeService.CreateProcessInstanceByKey("exclusiveGateway")
                           .StartBeforeActivity("task2")
                           .Execute();

            // then
            Assert.NotNull(instance);

            var updatedTree = runtimeService.GetActivityInstance(instance.Id);

            Assert.NotNull(updatedTree);

            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(instance.ProcessDefinitionId)
                          .Transition("task2")
                          .Done());

            // and it is possible to end the process
            var job = managementService.CreateJobQuery()
                      .First();

            Assert.NotNull(job);
            managementService.ExecuteJob(job.Id);

            completeTasksInOrder("task2");
            AssertProcessEnded(instance.Id);
        }
Example #17
0
        public virtual void testCallBpmnProcessParallelMultiInstance()
        {
            // given
            IBpmnModelInstance model =
                ModifiableBpmnModelInstance.Modify(CallActivityModels.oneBpmnCallActivityProcess("oneTaskProcess"))
                //.ActivityBuilder("callActivity")
                //.MultiInstance()
                //.Parallel()
                //.Cardinality("1")
                //.Done()
            ;

            var sourceProcessDefinition = testHelper.DeployAndGetDefinition(model);
            var targetProcessDefinition = testHelper.DeployAndGetDefinition(model);

            var migrationPlan =
                rule.RuntimeService.CreateMigrationPlan(sourceProcessDefinition.Id, targetProcessDefinition.Id)
                .MapActivities("callActivity#multiInstanceBody", "callActivity#multiInstanceBody")
                .MapActivities("callActivity", "callActivity")
                .Build();

            // when
            var processInstance = testHelper.CreateProcessInstanceAndMigrate(migrationPlan);

            // then
            testHelper.AssertExecutionTreeAfterMigration()
            .HasProcessDefinitionId(targetProcessDefinition.Id)
            .Matches(ExecutionAssert.DescribeExecutionTree(null)
                     .Scope()
                     .Id(testHelper.SnapshotBeforeMigration.ProcessInstanceId)
                     .Child(null)
                     .Scope()
                     .Id(testHelper.GetSingleExecutionIdForActivityBeforeMigration("callActivity#multiInstanceBody"))
                     .Child("callActivity")
                     .Concurrent()
                     .NoScope()
                     .Id(testHelper.GetSingleExecutionIdForActivityBeforeMigration("callActivity"))
                     .Done());

            testHelper.AssertActivityTreeAfterMigration()
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(targetProcessDefinition.Id)
                          .BeginMiBody("callActivity")
                          .Activity("callActivity", testHelper.GetSingleActivityInstanceBeforeMigration("callActivity")
                                    .Id)
                          .Done());

            // and the link between calling and called instance is maintained correctly

            testHelper.AssertSuperExecutionOfProcessInstance(rule.RuntimeService.CreateProcessInstanceQuery()
                                                             ////.SetProcessDefinitionKey("oneTaskProcess")
                                                             .First()
                                                             .Id, testHelper.GetSingleExecutionIdForActivityAfterMigration("callActivity"));

            // and it is possible to complete the called process instance
            testHelper.CompleteTask("userTask");
            // and the calling process instance
            testHelper.CompleteTask("userTask");

            testHelper.AssertProcessEnded(processInstance.Id);
        }
        public virtual void testMultipleActivitiesInstantiation()
        {
            // when
            var instance = runtimeService.CreateProcessInstanceByKey("exclusiveGateway")
                           .StartBeforeActivity("task1")
                           .StartBeforeActivity("task2")
                           .StartBeforeActivity("task1")
                           .Execute();

            // then
            Assert.NotNull(instance);

            var updatedTree = runtimeService.GetActivityInstance(instance.Id);

            Assert.NotNull(updatedTree);

            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(instance.ProcessDefinitionId)
                          .Activity("task1")
                          .Activity("task2")
                          .Activity("task1")
                          .Done());

            // and it is possible to end the process
            completeTasksInOrder("task1", "task2", "task1");
            AssertProcessEnded(instance.Id);
        }
        public virtual void shouldRestartProcessInstanceWithSubProcess()
        {
            // given
            var processDefinition = testRule.DeployAndGetDefinition(ProcessModels.SubprocessProcess);
            var processInstance   = runtimeService.StartProcessInstanceByKey("Process");

            runtimeService.DeleteProcessInstance(processInstance.Id, "test");

            // when
            runtimeService.RestartProcessInstances(processDefinition.Id)
            .StartBeforeActivity("subProcess")
            .SetProcessInstanceIds(processInstance.Id)
            .Execute();

            // then
            var restartedProcessInstance = runtimeService.CreateProcessInstanceQuery(c => c.SuspensionState == SuspensionStateFields.Active.StateCode)
                                           .First();
            var updatedTree = runtimeService.GetActivityInstance(restartedProcessInstance.Id);

            Assert.NotNull(updatedTree);
            Assert.AreEqual(restartedProcessInstance.Id, updatedTree.ProcessInstanceId);
            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processDefinition.Id)
                          .BeginScope("subProcess")
                          .Activity("userTask")
                          .Done());
        }
Example #20
0
        public virtual void TestTwoSubProcessInParallelWithinSubProcess()
        {
            IProcessInstance   pi        = runtimeService.StartProcessInstanceByKey("twoSubProcessInParallelWithinSubProcess");
            IQueryable <ITask> taskQuery = taskService.CreateTaskQuery(c => c.ProcessInstanceId == pi.Id);
            IList <ITask>      tasks     = taskQuery.ToList().OrderBy(m => m.Name).ToList();

            // After process start, both tasks in the subprocesses should be active
            ITask taskA = tasks[0];
            ITask taskB = tasks[1];

            Assert.AreEqual("Task in subprocess A", taskA.Name);
            Assert.AreEqual("Task in subprocess B", taskB.Name);

            // validate activity instance tree
            var rootActivityInstance = runtimeService.GetActivityInstance(pi.ProcessInstanceId);

            ActivityInstanceAssert.That(rootActivityInstance).HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(pi.ProcessDefinitionId).BeginScope("outerSubProcess").BeginScope("subProcessA").Activity("subProcessATask").EndScope().BeginScope("subProcessB").Activity("subProcessBTask").Done());
            ActivityInstanceAssert.That(rootActivityInstance)
            .Equals(ActivityInstanceAssert.DescribeActivityInstanceTree(pi.ProcessDefinitionId)
                    .BeginScope("outerSubProcess").BeginScope("subProcessA").Activity("subProcessATask").EndScope().
                    BeginScope("subProcessB").Activity("subProcessBTask").Done());

            // Completing both tasks should active the tasks outside the subprocesses
            taskService.Complete(taskA.Id);
            taskService.Complete(taskB.Id);

            ITask taskAfterSubProcess = taskQuery.First();

            Assert.AreEqual("Task after subprocess", taskAfterSubProcess.Name);

            // Completing this task should end the process
            taskService.Complete(taskAfterSubProcess.Id);
            AssertProcessEnded(pi.Id);
        }
Example #21
0
        public virtual void testRemoveParallelMultiInstanceBodyOneInstanceFinished()
        {
            // given
            var sourceProcessDefinition =
                testHelper.DeployAndGetDefinition(MultiInstanceProcessModels.PAR_MI_ONE_TASK_PROCESS);
            var targetProcessDefinition = testHelper.DeployAndGetDefinition(ProcessModels.OneTaskProcess);

            var migrationPlan =
                rule.RuntimeService.CreateMigrationPlan(sourceProcessDefinition.Id, targetProcessDefinition.Id)
                .MapActivities("userTask", "userTask")
                .Build();

            var processInstance = rule.RuntimeService.StartProcessInstanceById(migrationPlan.SourceProcessDefinitionId);

            var firstTask = rule.TaskService.CreateTaskQuery()
                            ///*.ListPage(0, 1)*/
                            .ToList()
                            [0];

            rule.TaskService.Complete(firstTask.Id);

            // when
            testHelper.MigrateProcessInstance(migrationPlan, processInstance);

            // then
            testHelper.AssertExecutionTreeAfterMigration()
            .HasProcessDefinitionId(targetProcessDefinition.Id)
            .Matches(ExecutionAssert.DescribeExecutionTree(null)
                     .Scope()
                     .Id(testHelper.SnapshotBeforeMigration.ProcessInstanceId)
                     .Child("userTask")
                     .Concurrent()
                     .NoScope()
                     .Up()
                     .Child("userTask")
                     .Concurrent()
                     .NoScope()
                     .Done());

            var userTaskInstances = testHelper.SnapshotBeforeMigration.ActivityTree.GetActivityInstances("userTask");

            testHelper.AssertActivityTreeAfterMigration()
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(targetProcessDefinition.Id)
                          .Activity("userTask", userTaskInstances[0].Id)
                          .Activity("userTask", userTaskInstances[1].Id)
                          .Done());

            var migratedTasks = testHelper.SnapshotAfterMigration.Tasks;

            Assert.AreEqual(2, migratedTasks.Count);

            // and it is possible to successfully complete the migrated instance
            foreach (var migratedTask in migratedTasks)
            {
                rule.TaskService.Complete(migratedTask.Id);
            }
            testHelper.AssertProcessEnded(testHelper.SnapshotBeforeMigration.ProcessInstanceId);
        }
        public virtual void executeModificationJobsForProcessInstancesWithDifferentStates()
        {
            var deployment        = testRule.Deploy(instance);
            var processDefinition = deployment.DeployedProcessDefinitions[0];

            var processInstanceIds = helper.StartInstances("process1", 1);
            var task = rule.TaskService.CreateTaskQuery()
                       .First();

            rule.TaskService.Complete(task.Id);

            var anotherProcessInstanceIds = helper.StartInstances("process1", 1);

            ((List <string>)processInstanceIds).AddRange(anotherProcessInstanceIds);

            var batch = runtimeService.CreateModification(processDefinition.Id)
                        .StartBeforeActivity("user2")
                        .SetProcessInstanceIds(processInstanceIds)
                        .ExecuteAsync();

            helper.ExecuteSeedJob(batch);
            var modificationJobs = helper.GetExecutionJobs(batch);

            // when
            foreach (var modificationJob in modificationJobs)
            {
                helper.ExecuteJob(modificationJob);
            }

            // then all process instances where modified
            IActivityInstance updatedTree = null;
            var ProcessInstanceId         = processInstanceIds[0];

            updatedTree = runtimeService.GetActivityInstance(ProcessInstanceId);
            Assert.NotNull(updatedTree);
            Assert.AreEqual(ProcessInstanceId, updatedTree.ProcessInstanceId);
            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processDefinition.Id)
                          .Activity("user2")
                          .Activity("user2")
                          .Done());

            ProcessInstanceId = processInstanceIds[1];
            updatedTree       = runtimeService.GetActivityInstance(ProcessInstanceId);
            Assert.NotNull(updatedTree);
            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processDefinition.Id)
                          .Activity("user1")
                          .Activity("user2")
                          .Done());

            // and the no modification jobs exist
            Assert.AreEqual(0, helper.GetExecutionJobs(batch)
                            .Count);

            // but a monitor job exists
            Assert.NotNull(helper.GetMonitorJob(batch));
        }
        public virtual void testStartBeforeMessageStartEvent()
        {
            runtimeService.CorrelateMessage("startMessage");
            var processInstance = runtimeService.CreateProcessInstanceQuery()
                                  .First();

            Assert.NotNull(processInstance);

            var startEventSubscription = runtimeService.CreateEventSubscriptionQuery()
                                         .First();

            Assert.NotNull(startEventSubscription);

            var ProcessInstanceId = processInstance.Id;

            // when I start before the message start event
            runtimeService.CreateProcessInstanceModification(ProcessInstanceId)
            .StartBeforeActivity("theStart")
            .Execute();

            // then there are two instances of "task"
            var updatedTree = runtimeService.GetActivityInstance(ProcessInstanceId);

            Assert.NotNull(updatedTree);
            Assert.AreEqual(ProcessInstanceId, updatedTree.ProcessInstanceId);

            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processInstance.ProcessDefinitionId)
                          .Activity("task")
                          .Activity("task")
                          .Done());

            var executionTree = ExecutionTree.ForExecution(ProcessInstanceId, ProcessEngine);

            ExecutionAssert.That(executionTree)
            .Matches(ExecutionAssert.DescribeExecutionTree(null)
                     .Scope()
                     .Child("task")
                     .Concurrent()
                     .NoScope()
                     .Up()
                     .Child("task")
                     .Concurrent()
                     .NoScope()
                     .Done());

            // and there is only the message start event subscription
            var subscription = runtimeService.CreateEventSubscriptionQuery()
                               .First();

            Assert.NotNull(subscription);
            Assert.AreEqual(startEventSubscription.Id, subscription.Id);

            completeTasksInOrder("task", "task");
            AssertProcessEnded(ProcessInstanceId);
        }
Example #24
0
        public virtual void testNonInterruptingEventInCombinationWithReceiveTaskInsideSubProcess()
        {
            // given
            IProcessInstance instance          = runtimeService.StartProcessInstanceByKey("process");
            string           ProcessInstanceId = instance.Id;

            // when (1)
            runtimeService.CorrelateMessage("firstMessage");

            // then (1)
            IActivityInstance activityInstance = runtimeService.GetActivityInstance(instance.Id);

            ActivityInstanceAssert.That(activityInstance).HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(instance.ProcessDefinitionId)
                                                                       .BeginScope("subProcess").Activity("task1").BeginScope("innerSubProcess").Activity("receiveTask").Done());

            Assert.AreEqual(1, taskService.CreateTaskQuery().Count());

            ITask task1 = taskService.CreateTaskQuery(c => c.TaskDefinitionKey == "task1").First();

            Assert.NotNull(task1);

            IExecution task1Execution = runtimeService.CreateExecutionQuery(c => c.ActivityId == "task1").First();

            Assert.IsFalse(ProcessInstanceId.Equals(((ExecutionEntity)task1Execution).ParentId));

            // when (2)
            runtimeService.CorrelateMessage("secondMessage");

            // then (2)
            Assert.AreEqual(2, taskService.CreateTaskQuery().Count());

            task1 = taskService.CreateTaskQuery(c => c.TaskDefinitionKey == "task1").First();
            Assert.NotNull(task1);

            task1Execution = runtimeService.CreateExecutionQuery(c => c.ActivityId == "task1").First();

            Assert.IsFalse(ProcessInstanceId.Equals(((ExecutionEntity)task1Execution).ParentId));

            ITask task2 = taskService.CreateTaskQuery(c => c.TaskDefinitionKey == "task2").First();

            Assert.NotNull(task2);

            IExecution task2Execution = runtimeService.CreateExecutionQuery(c => c.ActivityId == "task1").First();

            Assert.IsFalse(ProcessInstanceId.Equals(((ExecutionEntity)task2Execution).ParentId));

            Assert.True(((ExecutionEntity)task1Execution).ParentId.Equals(((ExecutionEntity)task2Execution).ParentId));

            Assert.AreEqual(0, runtimeService.CreateEventSubscriptionQuery().Count());

            taskService.Complete(task1.Id);
            taskService.Complete(task2.Id);

            AssertProcessEnded(ProcessInstanceId);
        }
Example #25
0
        public virtual void testInterruptingEscalationEventSubprocessInsideSubprocess()
        {
            IProcessInstance processInstance = runtimeService.StartProcessInstanceByKey("escalationProcess");
            // an escalation event is thrown from embedded subprocess and caught by interrupting event subprocess inside the subprocess

            IActivityInstance tree = runtimeService.GetActivityInstance(processInstance.Id);

            ActivityInstanceAssert.That(tree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processInstance.ProcessDefinitionId)
                          .BeginScope("subProcess").BeginScope("escalationEventSubprocess").Activity("taskAfterCatchedEscalation").Done());
        }
Example #26
0
        public virtual void testLoopingInclusiveGateways()
        {
            // given
            IProcessInstance processInstance = runtimeService.StartProcessInstanceByKey("process");

            // when
            IActivityInstance activityInstance = runtimeService.GetActivityInstance(processInstance.Id);

            // then
            ActivityInstanceAssert.That(activityInstance).HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processInstance.ProcessDefinitionId)
                                                                       .Activity("task1").Activity("task2").Activity("inclusiveGw3").Done());
        }
        public virtual void testStartBeforeTimerStartEvent()
        {
            var processInstance   = runtimeService.StartProcessInstanceByKey("process");
            var ProcessInstanceId = processInstance.Id;

            var startTimerJob = managementService.CreateJobQuery()
                                .First();

            Assert.NotNull(startTimerJob);

            // when I start before the timer start event
            runtimeService.CreateProcessInstanceModification(ProcessInstanceId)
            .StartBeforeActivity("theStart")
            .Execute();

            // then there are two instances of "task"
            var updatedTree = runtimeService.GetActivityInstance(ProcessInstanceId);

            Assert.NotNull(updatedTree);
            Assert.AreEqual(ProcessInstanceId, updatedTree.ProcessInstanceId);

            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processInstance.ProcessDefinitionId)
                          .Activity("task")
                          .Activity("task")
                          .Done());

            var executionTree = ExecutionTree.ForExecution(ProcessInstanceId, ProcessEngine);

            ExecutionAssert.That(executionTree)
            .Matches(ExecutionAssert.DescribeExecutionTree(null)
                     .Scope()
                     .Child("task")
                     .Concurrent()
                     .NoScope()
                     .Up()
                     .Child("task")
                     .Concurrent()
                     .NoScope()
                     .Done());

            // and there is only one timer job
            var job = managementService.CreateJobQuery()
                      .First();

            Assert.NotNull(job);
            Assert.AreEqual(startTimerJob.Id, job.Id);

            completeTasksInOrder("task", "task");
            AssertProcessEnded(ProcessInstanceId);
        }
Example #28
0
        public virtual void testStartBeforeStartEventInsideNonInterruptingEventSubProcessInsideSubProcessTask2ShouldStay
            ()
        {
            var processInstance   = runtimeService.StartProcessInstanceByKey("process");
            var ProcessInstanceId = processInstance.Id;

            var taskId = taskService.CreateTaskQuery()
                         .First()
                         .Id;

            taskService.Complete(taskId);

            runtimeService.CreateProcessInstanceModification(ProcessInstanceId)
            .StartBeforeActivity("eventProcessStart")
            .Execute();

            var updatedTree = runtimeService.GetActivityInstance(ProcessInstanceId);

            Assert.NotNull(updatedTree);
            Assert.AreEqual(ProcessInstanceId, updatedTree.ProcessInstanceId);

            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processInstance.ProcessDefinitionId)
                          .BeginScope("subProcess")
                          .Activity("task2")
                          .BeginScope("eventSubProcess")
                          .Activity("eventSubProcessTask")
                          .Done());

            var executionTree = ExecutionTree.ForExecution(ProcessInstanceId, ProcessEngine);

            ExecutionAssert.That(executionTree)
            .Matches(ExecutionAssert.DescribeExecutionTree(null)
                     .Scope()
                     .Child(null)
                     .Scope()
                     .Child("task2")
                     .Concurrent()
                     .NoScope()
                     .Up()
                     .Child(null)
                     .Concurrent()
                     .NoScope()
                     .Child("eventSubProcessTask")
                     .Scope()
                     .Done());

            completeTasksInOrder("task2", "eventSubProcessTask");
            AssertProcessEnded(ProcessInstanceId);
        }
        public virtual void testStartBeforNoneStartEvent()
        {
            var processInstance   = runtimeService.StartProcessInstanceByKey("oneTaskProcess");
            var ProcessInstanceId = processInstance.Id;

            // when I start before the none start event
            runtimeService.CreateProcessInstanceModification(ProcessInstanceId)
            .StartBeforeActivity("theStart")
            .Execute();

            // then there are two instances of "task"
            var updatedTree = runtimeService.GetActivityInstance(ProcessInstanceId);

            Assert.NotNull(updatedTree);
            Assert.AreEqual(ProcessInstanceId, updatedTree.ProcessInstanceId);

            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processInstance.ProcessDefinitionId)
                          .Activity("theTask")
                          .Activity("theTask")
                          .Done());

            var executionTree = ExecutionTree.ForExecution(ProcessInstanceId, ProcessEngine);

            ExecutionAssert.That(executionTree)
            .Matches(ExecutionAssert.DescribeExecutionTree(null)
                     .Scope()
                     .Child("theTask")
                     .Concurrent()
                     .NoScope()
                     .Up()
                     .Child("theTask")
                     .Concurrent()
                     .NoScope()
                     .Done());

            // and the process can be ended as usual
            var tasks = taskService.CreateTaskQuery()

                        .ToList();

            Assert.AreEqual(2, tasks.Count);

            foreach (var task in tasks)
            {
                taskService.Complete(task.Id);
            }

            AssertProcessEnded(ProcessInstanceId);
        }
        public virtual void testStartBeforeIntermediateCatchEvent()
        {
            var processInstance   = runtimeService.StartProcessInstanceByKey("process");
            var ProcessInstanceId = processInstance.Id;

            runtimeService.CreateProcessInstanceModification(ProcessInstanceId)
            .StartBeforeActivity("intermediateCatchEvent")
            .Execute();


            var updatedTree = runtimeService.GetActivityInstance(ProcessInstanceId);

            Assert.NotNull(updatedTree);
            Assert.AreEqual(ProcessInstanceId, updatedTree.ProcessInstanceId);

            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processInstance.ProcessDefinitionId)
                          .Activity("task")
                          .Activity("intermediateCatchEvent")
                          .Done());

            var executionTree = ExecutionTree.ForExecution(ProcessInstanceId, ProcessEngine);

            ExecutionAssert.That(executionTree)
            .Matches(ExecutionAssert.DescribeExecutionTree(null)
                     .Scope()
                     .Child("task")
                     .Concurrent()
                     .NoScope()
                     .Up()
                     .Child(null)
                     .Concurrent()
                     .NoScope()
                     .Child("intermediateCatchEvent")
                     .Scope()
                     .Done());

            var catchEventInstance = getChildInstanceForActivity(updatedTree, "intermediateCatchEvent");

            // and there is a timer job
            var job = managementService.CreateJobQuery()
                      .First();

            Assert.NotNull(job);
            Assert.AreEqual(catchEventInstance.ExecutionIds[0], job.ExecutionId);

            completeTasksInOrder("task");
            ExecuteAvailableJobs();
            AssertProcessEnded(ProcessInstanceId);
        }