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());
        }
Example #2
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());
            }
        }
        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 #4
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 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 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);
        }
        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 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());
        }
Example #10
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);
        }
        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 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());
        }
        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 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 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 #17
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 #18
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 #19
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);
        }
        public virtual void testBatchExecutionFailureWithMissingProcessInstance()
        {
            var deployment        = testRule.Deploy(instance);
            var processDefinition = deployment.DeployedProcessDefinitions[0];
            var batch             = helper.StartAfterAsync("process1", 2, "user1", processDefinition.Id);

            helper.ExecuteSeedJob(batch);

            var processInstances = runtimeService.CreateProcessInstanceQuery()

                                   .ToList();
            var deletedProcessInstanceId = processInstances[0].Id;

            // when
            runtimeService.DeleteProcessInstance(deletedProcessInstanceId, "test");
            helper.ExecuteJobs(batch);

            // then the remaining process instance was modified
            foreach (var ProcessInstanceId in helper.CurrentProcessInstances)
            {
                if (ProcessInstanceId.Equals(helper.CurrentProcessInstances[0]))
                {
                    var u = runtimeService.GetActivityInstance(ProcessInstanceId);
                    Assert.IsNull(u);
                    continue;
                }

                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());
            }

            // and one batch job failed and has 2 retries left
            var modificationJobs = helper.GetExecutionJobs(batch);

            Assert.AreEqual(1, modificationJobs.Count);

            var failedJob = modificationJobs[0];

            Assert.AreEqual(2, failedJob.Retries);
            Assert.That(failedJob.ExceptionMessage, Does.Contain("ENGINE-13036"));
            Assert.That(failedJob.ExceptionMessage,
                        Does.Contain("Process instance '" + deletedProcessInstanceId + "' cannot be modified"));
        }
        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);
        }
        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);
        }
Example #24
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 testNonInterruptingActivityInstanceTree()
        {
            // given
            IProcessInstance instance          = runtimeService.StartProcessInstanceByKey("process");
            string           ProcessInstanceId = instance.Id;

            // when
            runtimeService.CorrelateMessage("newMessage");

            // then
            IActivityInstance tree = runtimeService.GetActivityInstance(ProcessInstanceId);

            ActivityInstanceAssert.That(tree).HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(instance.ProcessDefinitionId)
                                                           .BeginScope("subProcess").Activity("innerTask").BeginScope("eventSubProcess").Activity("eventSubProcessTask").EndScope().EndScope().Done());
        }
Example #26
0
        public virtual void testStartBeforeNonInterruptingBoundaryEvent()
        {
            var processInstance   = runtimeService.StartProcessInstanceByKey("process");
            var ProcessInstanceId = processInstance.Id;

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

            var updatedTree = runtimeService.GetActivityInstance(ProcessInstanceId);

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

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

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

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

            completeTasksInOrder("task1", "task2", "taskAfterBoundaryEvent");
            AssertProcessEnded(ProcessInstanceId);
        }
Example #27
0
        public virtual void testTriggerGatewayWithEnoughArrivedTokens()
        {
            Deployment(ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess("process").StartEvent().UserTask("beforeTask").InclusiveGateway("gw").UserTask("afterTask").EndEvent().Done());

            // given
            IProcessInstance processInstance = runtimeService.CreateProcessInstanceByKey("process").StartBeforeActivity("beforeTask").StartBeforeActivity("beforeTask").Execute();

            ITask task = taskService.CreateTaskQuery().First();

            // when
            taskService.Complete(task.Id);

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

            ActivityInstanceAssert.That(activityInstance).HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processInstance.ProcessDefinitionId)
                                                                       .Activity("beforeTask").Activity("afterTask").Done());
        }
        public virtual void testNonInterruptingWithTerminatingEndEvent()
        {
            IProcessInstance processInstance = runtimeService.StartProcessInstanceByKey("process");
            ITask            task            = taskService.CreateTaskQuery().First();

            Assert.That(task.Name, Is.EqualTo("Inner IUser Task"));
            runtimeService.CorrelateMessage("message");

            ITask eventSubprocessTask = taskService.CreateTaskQuery(c => c.Name == "Event IUser Task").First();

            Assert.That(eventSubprocessTask, Is.Not.Null);
            taskService.Complete(eventSubprocessTask.Id);

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

            ActivityInstanceAssert.That(tree).HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(processInstance.ProcessDefinitionId)
                                                           .BeginScope("SubProcess_1").Activity("UserTask_1").EndScope().EndScope().Done());
        }
Example #29
0
        public virtual void TestDifferentStates()
        {
            var deployment = TestRule.Deploy(Instance);
            var definition = 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);

            RuntimeService.CreateModification(definition.Id)
            .StartBeforeActivity("user3")
            .SetProcessInstanceIds(processInstanceIds)
            .Execute();

            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(definition.Id)
                          .Activity("user2")
                          .Activity("user3")
                          .Done());

            processInstanceId = processInstanceIds[1];
            updatedTree       = RuntimeService.GetActivityInstance(processInstanceId);
            Assert.NotNull(updatedTree);
            Assert.AreEqual(processInstanceId, updatedTree.ProcessInstanceId);
            ActivityInstanceAssert.That(updatedTree)
            .HasStructure(ActivityInstanceAssert.DescribeActivityInstanceTree(definition.Id)
                          .Activity("user1")
                          .Activity("user3")
                          .Done());
        }
        public virtual void executeModificationJobsForStartAfterAndCancelAll()
        {
            var deployment        = testRule.Deploy(instance);
            var processDefinition = deployment.DeployedProcessDefinitions[0];
            var instances         = helper.StartInstances("process1", 10);

            var batch = runtimeService.CreateModification(processDefinition.Id)
                        .StartAfterActivity("user1")
                        .CancelAllForActivity("user1")
                        .SetProcessInstanceIds(instances)
                        .ExecuteAsync();

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

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

            // 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("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));
        }