public void TestNonInterruptingVariableConditionWithVariableEvent()
        {
            //given process with non interrupting boundary conditional event and defined variable event
            IBpmnModelInstance modelInstance = Specifier.GetProcessWithVarEvents(false, ConditionalVarEventUpdate);

            Engine.ManageDeployment(RepositoryService.CreateDeployment().AddModelInstance(ConditionalModel, modelInstance).Deploy());

            IProcessInstance   procInst  = RuntimeService.StartProcessInstanceByKey(ConditionalEventProcessKey);
            IQueryable <ITask> taskQuery = TaskService.CreateTaskQuery(c => c.ProcessInstanceId == procInst.Id);
            ITask task = taskQuery.First();

            Assert.IsNotNull(task);

            //when variable with name `variable` is set
            TaskService.SetVariable(task.Id, VariableName, 1); //create

            //then nothing happens
            task = taskQuery.First();
            Assert.IsNotNull(task);

            //when variable is updated twice
            TaskService.SetVariable(task.Id, VariableName, 1); //update
            TaskService.SetVariable(task.Id, VariableName, 1); //update

            //then execution is for two times at user task after conditional event
            Assert.Equals(2, taskQuery.Where(c => c.Name == TaskAfterCondition).Count());
            TasksAfterVariableIsSet = TaskService.CreateTaskQuery().ToList();
            Assert.Equals(3, TasksAfterVariableIsSet.Count);
            Assert.Equals(1, ConditionEventSubscriptionQuery.Count());
        }
Esempio n. 2
0
        public virtual void testVariableValue()
        {
            //given process with intermediate conditional event and variable with wrong value
            IDictionary <string, object> variables = ESS.FW.Bpm.Engine.Variable.Variables.CreateVariables();

            variables[VariableName] = 0;
            IProcessInstance procInst = RuntimeService.StartProcessInstanceByKey(ConditionalEventProcessKey, variables);

            //wait state is on conditional event, since condition is false
            IExecution execution = RuntimeService.CreateExecutionQuery(c => c.ProcessInstanceId == procInst.Id && c.ActivityId == ConditionalEvent).First();

            Assert.NotNull(execution);
            Assert.AreEqual(1, ConditionEventSubscriptionQuery.Count());

            //when variable is set to correct value
            RuntimeService.SetVariable(execution.Id, VariableName, 1);

            //then process instance is completed, since condition was true
            execution = RuntimeService.CreateExecutionQuery(c => c.ProcessInstanceId == procInst.Id && c.ActivityId == ConditionalEvent).First();
            Assert.IsNull(execution);

            procInst = RuntimeService.CreateProcessInstanceQuery(c => c.ProcessDefinitionId == ConditionalEventProcessKey).First();
            Assert.IsNull(procInst);
            Assert.AreEqual(0, ConditionEventSubscriptionQuery.Count());
        }
        public void TestVariableConditionWithVariableEvent()
        {
            //given process with boundary conditional event and defined variable event
            IBpmnModelInstance modelInstance = Specifier.GetProcessWithVarEvents(true, ConditionalVarEventUpdate);

            Engine.ManageDeployment(RepositoryService.CreateDeployment().AddModelInstance(ConditionalModel, modelInstance).Deploy());

            IDictionary <string, object> variables = ESS.FW.Bpm.Engine.Variable.Variables.CreateVariables();

            variables[VariableName + 1] = 0;
            IProcessInstance   procInst  = RuntimeService.StartProcessInstanceByKey(ConditionalEventProcessKey, variables);
            IQueryable <ITask> taskQuery = TaskService.CreateTaskQuery(c => c.ProcessInstanceId == procInst.Id);
            ITask task = taskQuery.First();

            Assert.IsNotNull(task);

            //when variable with name `variable` is set on execution
            RuntimeService.SetVariable(procInst.Id, VariableName, 1);

            //then nothing happens
            task = taskQuery.First();
            Assert.IsNotNull(task);
            Assert.Equals(TaskBeforeCondition, task.Name);
            Assert.Equals(1, ConditionEventSubscriptionQuery.Count());

            //when variable with name `variable1` is updated
            RuntimeService.SetVariable(procInst.Id, VariableName + 1, 1);

            //then execution is at user task after conditional intermediate event
            TasksAfterVariableIsSet = taskQuery.ToList();
            Assert.Equals(TaskAfterCondition, TasksAfterVariableIsSet.ElementAt(0).Name);
            Assert.Equals(0, ConditionEventSubscriptionQuery.Count());
        }
        public void TestVariableConditionWithVariableName()
        {
            //given process with boundary conditional event and defined variable name
            IBpmnModelInstance modelInstance = Specifier.GetProcessWithVarName(true, ConditionExpr);

            Engine.ManageDeployment(RepositoryService.CreateDeployment().AddModelInstance(ConditionalModel, modelInstance).Deploy());

            IProcessInstance   procInst  = RuntimeService.StartProcessInstanceByKey(ConditionalEventProcessKey);
            IQueryable <ITask> taskQuery = TaskService.CreateTaskQuery(c => c.ProcessInstanceId == procInst.Id);
            ITask task = taskQuery.First();

            Assert.IsNotNull(task);
            //AssertNotNull(task);

            //when variable with name `variable1` is set on execution
            TaskService.SetVariable(task.Id, VariableName + 1, 1);

            //then nothing happens
            task = taskQuery.First();
            Assert.IsNotNull(task);
            Assert.Equals(TaskBeforeCondition, task.Name);
            Assert.Equals(1, ConditionEventSubscriptionQuery.Count());


            //when variable with name `variable` is set on execution
            TaskService.SetVariable(task.Id, VariableName, 1);

            //then execution is at user task after conditional event
            TasksAfterVariableIsSet = taskQuery.ToList();
            Assert.Equals(TaskAfterCondition, TasksAfterVariableIsSet.ElementAt(0).Name);
            Assert.Equals(0, ConditionEventSubscriptionQuery.Count());
        }
Esempio n. 5
0
        public virtual void testCleanUpConditionalEventSubscriptions()
        {
            //given process with intermediate conditional event and variable with wrong value
            IDictionary <string, object> variables = ESS.FW.Bpm.Engine.Variable.Variables.CreateVariables();

            variables[VariableName] = 0;
            IProcessInstance procInst = RuntimeService.StartProcessInstanceByKey(ConditionalEventProcessKey, variables);

            //wait state is on conditional event, since condition is false
            IExecution execution = RuntimeService.CreateExecutionQuery(c => c.ProcessInstanceId == procInst.Id && c.ActivityId == ConditionalEvent).First();

            Assert.NotNull(execution);

            //condition subscription is created
            Assert.AreEqual(1, ConditionEventSubscriptionQuery.Count());

            //when variable is set to correct value
            RuntimeService.SetVariable(execution.Id, VariableName, 1);

            //then execution is on next IUser task and the subscription is deleted
            ITask task = TaskService.CreateTaskQuery(c => c.ProcessInstanceId == procInst.Id).First();

            Assert.NotNull(task);
            Assert.AreEqual(TaskAfterCondition, task.Name);
            Assert.AreEqual(0, ConditionEventSubscriptionQuery.Count());

            //and task can be completed which ends process instance
            TaskService.Complete(task.Id);
            Assert.IsNull(TaskService.CreateTaskQuery().First());
            Assert.IsNull(RuntimeService.CreateProcessInstanceQuery().First());
        }
Esempio n. 6
0
        public virtual void testParallelVariableSetValueOnParent()
        {
            //given process with intermediate conditional event and variable with wrong value
            IDictionary <string, object> variables = ESS.FW.Bpm.Engine.Variable.Variables.CreateVariables();

            variables[VariableName] = 0;
            IProcessInstance procInst = RuntimeService.StartProcessInstanceByKey(ConditionalEventProcessKey, variables);

            //when variable is set to correct value
            RuntimeService.SetVariable(procInst.Id, VariableName, 1);

            //then execution of conditional event is completed
            IExecution execution = RuntimeService.CreateExecutionQuery(c => c.ProcessInstanceId == procInst.Id && c.ActivityId == ConditionalEvent + 1).First();

            Assert.IsNull(execution);

            //when second variable is set to correct value
            RuntimeService.SetVariable(procInst.Id, VariableName, 2);

            //then execution and process instance is ended, since both conditions was true
            execution = RuntimeService.CreateExecutionQuery(c => c.ProcessInstanceId == procInst.Id && c.ActivityId == ConditionalEvent + 2).First();
            Assert.IsNull(execution);
            procInst = RuntimeService.CreateProcessInstanceQuery(c => c.ProcessDefinitionId == ConditionalEventProcessKey).First();
            Assert.IsNull(procInst);
        }
Esempio n. 7
0
        public virtual void TestMessageJobHasNoDueDateSet()
        {
            RuntimeService.StartProcessInstanceByKey("simpleAsyncProcess");

            var job = ManagementService.CreateJobQuery().First();

            Assert.IsNull(job.Duedate);
        }
Esempio n. 8
0
        public virtual void TestMessageJobHasDueDateSet()
        {
            RuntimeService.StartProcessInstanceByKey("simpleAsyncProcess");

            var job = ManagementService.CreateJobQuery().First();

            Assert.NotNull(job.Duedate);
            Assert.AreEqual(ClockUtil.CurrentTime.ToString("yyyy-MM-dd HH:mm:ss"), job.Duedate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
        }
        public virtual void TestSimpleProcess()
        {
            RuntimeService.StartProcessInstanceByKey("simpleProcess");

            var task = TaskService.CreateTaskQuery().First();

            Assert.AreEqual("My Task", task.Name);

            TaskService.Complete(task.Id);
            Assert.AreEqual(0, RuntimeService.CreateProcessInstanceQuery().Count());
        }
        public virtual void TestMessageJobHasDueDateSet()
        {
            RuntimeService.StartProcessInstanceByKey("simpleAsyncProcess");

            var job = ManagementService.CreateJobQuery().SingleOrDefault();

            Assert.NotNull(job.Duedate);

            // Todo: C# DateTime -> Oracle timestamp(6)小数秒丢失
            Assert.AreEqual(ClockUtil.CurrentTime.ToString("yyyy-MM-dd HH:mm:ss"), job.Duedate?.ToString("yyyy-MM-dd HH:mm:ss"));
        }
Esempio n. 11
0
        public virtual void testSubProcessVariableSetValueOnParent()
        {
            //given process with intermediate conditional event and variable with wrong value
            IDictionary <string, object> variables = ESS.FW.Bpm.Engine.Variable.Variables.CreateVariables();

            variables[VariableName] = 0;
            IProcessInstance procInst = RuntimeService.StartProcessInstanceByKey(ConditionalEventProcessKey, variables);

            //when variable is set to correct value
            RuntimeService.SetVariable(procInst.Id, VariableName, 1);

            //then process instance is ended, since condition was true
            procInst = RuntimeService.CreateProcessInstanceQuery(c => c.ProcessDefinitionId == ConditionalEventProcessKey).First();
            Assert.IsNull(procInst);
        }
Esempio n. 12
0
        public virtual void testFalseCondition()
        {
            //given process with intermediate conditional event
            IProcessInstance procInst = RuntimeService.StartProcessInstanceByKey(ConditionalEventProcessKey);

            IQueryable <ITask> taskQuery = TaskService.CreateTaskQuery();
            ITask task = taskQuery.Where(c => c.ProcessInstanceId == procInst.Id).First();

            Assert.NotNull(task);
            Assert.AreEqual(TaskBeforeCondition, task.Name);

            //when task before condition is completed
            TaskService.Complete(task.Id);

            //then next wait state is on conditional event, since condition is false
            //and a condition event subscription is create
            IExecution execution = RuntimeService.CreateExecutionQuery(c => c.ProcessInstanceId == procInst.Id && c.ActivityId == ConditionalEvent).First();

            Assert.NotNull(execution);
            Assert.AreEqual(1, ConditionEventSubscriptionQuery.Count());
        }
Esempio n. 13
0
        public virtual void TestTimerAndOldJobsArePreferred()
        {
            // first start process with timer job
            var timerProcess1 = RuntimeService.StartProcessInstanceByKey("testProcess");

            // then start process with async task
            ClockTestUtil.IncrementClock(1);
            var asyncProcess1 = RuntimeService.StartProcessInstanceByKey("simpleAsyncProcess");

            // then start process with timer job
            ClockTestUtil.IncrementClock(1);
            var timerProcess2 = RuntimeService.StartProcessInstanceByKey("testProcess");

            // and another process with async task after the timers are acquirable
            ClockTestUtil.IncrementClock(61);
            var asyncProcess2 = RuntimeService.StartProcessInstanceByKey("simpleAsyncProcess");

            var timerJob1   = ManagementService.CreateJobQuery(c => c.ProcessInstanceId == timerProcess1.Id).First();
            var timerJob2   = ManagementService.CreateJobQuery(c => c.ProcessInstanceId == timerProcess2.Id).First();
            var messageJob1 = ManagementService.CreateJobQuery(c => c.ProcessInstanceId == asyncProcess1.Id).First();
            var messageJob2 = ManagementService.CreateJobQuery(c => c.ProcessInstanceId == asyncProcess2.Id).First();

            Assert.NotNull(timerJob1.Duedate);
            Assert.NotNull(timerJob2.Duedate);
            Assert.NotNull(messageJob1.Duedate);
            Assert.NotNull(messageJob2.Duedate);

            Assert.True(messageJob1.Duedate < timerJob1.Duedate);
            Assert.True(timerJob1.Duedate < timerJob2.Duedate);
            Assert.True(timerJob2.Duedate < messageJob2.Duedate);

            var acquirableJobs = FindAcquirableJobs();

            Assert.AreEqual(4, acquirableJobs.Count);
            Assert.AreEqual(timerJob1.Id, acquirableJobs[0].Id);
            Assert.AreEqual(timerJob2.Id, acquirableJobs[1].Id);
            Assert.AreEqual(messageJob1.Id, acquirableJobs[2].Id);
            Assert.AreEqual(messageJob2.Id, acquirableJobs[3].Id);
        }
Esempio n. 14
0
        public virtual void TestTimerJobsArePreferred()
        {
            // first start process with timer job
            RuntimeService.StartProcessInstanceByKey("testProcess");
            // then start process with async task
            RuntimeService.StartProcessInstanceByKey("simpleAsyncProcess");
            // then start process with timer job
            RuntimeService.StartProcessInstanceByKey("testProcess");
            // and another process with async task
            RuntimeService.StartProcessInstanceByKey("simpleAsyncProcess");

            // increment clock so that timer events are acquirable
            ClockTestUtil.IncrementClock(70);

            var acquirableJobs = FindAcquirableJobs();

            Assert.AreEqual(4, acquirableJobs.Count);
            Assert.True(acquirableJobs[0] is TimerEntity);
            Assert.True(acquirableJobs[1] is TimerEntity);
            Assert.True(acquirableJobs[2] is MessageEntity);
            Assert.True(acquirableJobs[3] is MessageEntity);
        }
Esempio n. 15
0
        public virtual void testTrueCondition()
        {
            //given process with intermediate conditional event
            IProcessInstance procInst = RuntimeService.StartProcessInstanceByKey(ConditionalEventProcessKey);

            IQueryable <ITask> taskQuery = TaskService.CreateTaskQuery(c => c.ProcessInstanceId == procInst.Id);
            ITask task = taskQuery.First();

            Assert.NotNull(task);
            Assert.AreEqual(TaskBeforeCondition, task.Name);

            //when task before condition is completed
            TaskService.Complete(task.Id);

            //then next wait state is on IUser task after conditional event, since condition was true
            IExecution execution = RuntimeService.CreateExecutionQuery(c => c.ProcessInstanceId == procInst.Id && c.ActivityId == ConditionalEvent).First();

            Assert.IsNull(execution);

            task = taskQuery.First();
            Assert.NotNull(task);
            Assert.AreEqual(TaskAfterCondition, task.Name);
        }
        public void TestNonInterruptingVariableConditionWithVariableName()
        {
            //given process with non interrupting boundary conditional event and defined variable name and true condition
            IBpmnModelInstance modelInstance = Specifier.GetProcessWithVarName(false, TrueCondition);

            Engine.ManageDeployment(RepositoryService.CreateDeployment().AddModelInstance(ConditionalModel, modelInstance).Deploy());

            //when process is started
            IProcessInstance   procInst  = RuntimeService.StartProcessInstanceByKey(ConditionalEventProcessKey);
            IQueryable <ITask> taskQuery = TaskService.CreateTaskQuery(c => c.ProcessInstanceId == procInst.Id);

            //then first event is triggered since condition is true
            IList <ITask> tasks = taskQuery.ToList();

            Assert.Equals(2, tasks.Count);

            //when variable with name `variable1` is set on execution
            RuntimeService.SetVariable(procInst.Id, VariableName + 1, 1);

            //then nothing happens
            tasks = taskQuery.ToList();
            Assert.Equals(2, tasks.Count);
            Assert.Equals(1, ConditionEventSubscriptionQuery.Count());

            //when variable with name `variable` is set, updated and deleted
            RuntimeService.SetVariable(procInst.Id, VariableName, 1); //create
            RuntimeService.SetVariable(procInst.Id, VariableName, 1); //update
            RuntimeService.RemoveVariable(procInst.Id, VariableName); //delete

            //then execution is for four times at user task after conditional event
            //one from default behavior and three times from the variable events
            Assert.Equals(4, TaskService.CreateTaskQuery(c => c.Name == TaskAfterCondition).Count());
            TasksAfterVariableIsSet = taskQuery.ToList();
            Assert.Equals(5, TasksAfterVariableIsSet.Count);
            Assert.Equals(1, ConditionEventSubscriptionQuery.Count());
        }