Ejemplo n.º 1
0
        protected virtual ProcessDefinition BuildProcessWithTasks()
        {
            var factory = new ProcessBuilderFactory();
            var builder = factory.CreateProcess(id: "com.klaudwerk.workflow.renewal",
                                                name: "Renewal", description: "Policy Renewal");
            IReadOnlyList <ProcessValidationResult> result;
            bool isValid =
                builder.Variables().Name("PolicyNumber").Type(VariableTypeEnum.String).Done()
                .Variables().Name("Count").Type(VariableTypeEnum.Int).Done()
                .Start("s_1").SetName("Start")
                .Vars().Name("PolicyNumber").OnExit().Done()
                .Vars().Name("Count").OnExit().Done()
                .OnEntry()
                .Language(ScriptLanguage.CSharpScript)
                .Body("" +
                      " PropertySet.Set(\"PolicyNumber\",\"P12345\");" +
                      " PropertySet.Set(\"Count\",(int?)1);" +
                      " return 1;").Done().Done()
                .Step("task_1").Handler().HumanTask().Done().Done()
                .End("e_1").SetName("End Process").Done()
                .Link().From("s_1").To("task_1").Name("task").Done()
                .Link().From("task_1").To("e_1").Name("end").Done()
                .TryValidate(out result);

            Assert.IsTrue(isValid);
            return(builder.Build());
        }
        public void TestContinueAfterSuspending()
        {
            var factory = new ProcessBuilderFactory();
            var builder = factory.CreateProcess(id: "com.klaudwerk.workflow.renewal",
                                                name: "Renewal", description: "Policy Renewal");
            IReadOnlyList <ProcessValidationResult> result;

            builder.Start("s_1").Handler().HumanTask().Done().SetName("Start").Done()
            .Step("s_2").Handler().HumanTask().Done().Done()
            .Step("s_3").Handler().HumanTask().Done().Done()
            .End("e_1").SetName("End Process").Done()
            .Link().From("s_1").To("s_2").Name("s_1_s_2").Done()
            .Link().From("s_2").To("s_3").Name("s_2_s_3").Done()
            .Link().From("s_3").To("e_1").Name("end").Done()
            .TryValidate(out result);

            ProcessDefinition processDefinition          = builder.Build();
            IProcessDefinitionPersisnenceService service = GetProcessDefinitionPersistenceService();

            service.Create(processDefinition, ProcessDefStatusEnum.Active, 1);

            IProcessRuntimeService            pservice   = GetProcessRuntime();
            PropertySetCollection             collection = new PropertySetCollection(new PropertySchemaSet(new PropertySchemaFactory()));
            Mock <IProcessRuntimeEnvironment> mEnv       = new Mock <IProcessRuntimeEnvironment>();

            mEnv.SetupGet(m => m.PropertySet).Returns(collection).Verifiable();
            mEnv.Setup(m => m.TaskServiceAsync())
            .Returns(() =>
                     Task.FromResult(new ExecutionResult(StepExecutionStatusEnum.Suspend)))
            .Verifiable();

            IProcessRuntime runtime = pservice.Create(processDefinition, collection);

            string[] errors;
            runtime.TryCompile(out errors);

            IProcessRuntime        ufRuntime;
            StepRuntime            ufStep;
            IPropertySetCollection ufCollection;
            Tuple <ExecutionResult, StepRuntime> execute = runtime.Execute(runtime.StartSteps[0], mEnv.Object);

            Assert.IsNotNull(execute);
            Assert.AreEqual(StepExecutionStatusEnum.Suspend, execute.Item1.Status, "The Workflow should be in Suspended state");
            Assert.AreEqual(execute.Item2.StepId, "s_1");
            execute = runtime.Continue(mEnv.Object);
            Assert.IsNotNull(execute);
            Assert.AreEqual(StepExecutionStatusEnum.Ready, execute.Item1.Status, "The Workflow should be in Suspended state");
            Assert.AreEqual(execute.Item2.StepId, "s_2");

            pservice.TryUnfreeze(runtime.Id, out ufRuntime, out ufStep, out ufCollection);
            Assert.IsNotNull(ufRuntime);
            Assert.IsNotNull(ufStep);
            Assert.AreEqual("s_2", ufStep.StepId);
        }
Ejemplo n.º 3
0
        protected virtual ProcessDefinition BuildProcessdefinition()
        {
            var factory = new ProcessBuilderFactory();
            var builder = factory.CreateProcess(id: "com.klaudwerk.workflow.renewal",
                                                name: "Renewal", description: "Policy Renewal");
            IReadOnlyList <ProcessValidationResult> result;
            bool isValid = builder.Variables().Name("PolicyNumber").Type(VariableTypeEnum.String).Done()
                           .Start("s_1").SetName("Start").Vars().Name("PolicyNumber").OnExit().Done().Done()
                           .End("e_1").SetName("End Process").Done()
                           .Link().From("s_1").To("e_1").Name("finish").Done()
                           .TryValidate(out result);

            Assert.IsTrue(isValid);
            return(builder.Build());
        }
Ejemplo n.º 4
0
        protected ProcessDefinition BuildProcessdefinition(string id, string name, string description)
        {
            var factory = new ProcessBuilderFactory();
            var builder = factory.CreateProcess(id: id,
                                                name: name, description: description);
            IReadOnlyList <ProcessValidationResult> result;
            bool isValid = builder.Variables().Name("PolicyNumber").Type(VariableTypeEnum.String).Done()
                           .Start("s_1").SetName("Start")
                           .Handler().Script().Language(ScriptLanguage.CSharpScript).Body("return 1").Done().Done()
                           .Vars().Name("PolicyNumber").OnExit().Done().Done()
                           .End("e_1").SetName("End Process").Done()
                           .Link().From("s_1").To("e_1").Name("finish").Done()
                           .TryValidate(out result);

            Assert.IsTrue(isValid);
            return(builder.Build());
        }
Ejemplo n.º 5
0
        protected virtual void OnTestExecuteMultipleStepsSaveStateBetweenSteps()
        {
            var factory = new ProcessBuilderFactory();
            var builder = factory.CreateProcess(id: "com.klaudwerk.workflow.renewal",
                                                name: "Renewal", description: "Policy Renewal");
            IReadOnlyList <ProcessValidationResult> result;

            builder.Variables()
            .Name("Count")
            .Type(VariableTypeEnum.Int)
            .Done()
            .Start("s_1")
            .SetName("Start")
            .OnEntry()
            .Language(ScriptLanguage.CSharpScript)
            .Body("" +
                  " PropertySet.Set(\"Count\",(int?)1);" +
                  " return 1;")
            .Done()
            .Done()
            .Step("s_2")
            .OnEntry()
            .Language(ScriptLanguage.CSharpScript)
            .Body("" +
                  " PropertySet.Set(\"Count\",(int?)2);" +
                  " return 1;")
            .Done()
            .Done()
            .Step("s_3")
            .OnEntry()
            .Language(ScriptLanguage.CSharpScript)
            .Body("" +
                  " PropertySet.Set(\"Count\",(int?)3);" +
                  " return 1;")
            .Done()
            .Done()
            .End("e_1")
            .SetName("End Process")
            .Done()
            .Link()
            .From("s_1")
            .To("s_2")
            .Name("s_1_s_2")
            .Done()
            .Link()
            .From("s_2")
            .To("s_3")
            .Name("s_2_s_3")
            .Done()
            .Link()
            .From("s_3")
            .To("e_1")
            .Name("end")
            .Done()
            .TryValidate(out result);
            ProcessDefinition processDefinition          = builder.Build();
            IProcessDefinitionPersisnenceService service = GetProcessDefinitionPersistenceService();

            service.Create(processDefinition, ProcessDefStatusEnum.Active, 1);

            IProcessRuntimeService            pservice   = GetProcessRuntime();
            PropertySetCollection             collection = new PropertySetCollection(new PropertySchemaSet(new PropertySchemaFactory()));
            Mock <IProcessRuntimeEnvironment> mEnv       = new Mock <IProcessRuntimeEnvironment>();

            mEnv.SetupGet(m => m.PropertySet).Returns(collection).Verifiable();
            mEnv.Setup(m => m.TaskServiceAsync())
            .Returns(() =>
                     Task.FromResult(new ExecutionResult(StepExecutionStatusEnum.Suspend)))
            .Verifiable();
            IProcessRuntime runtime = pservice.Create(processDefinition, collection);

            string[] errors;
            runtime.TryCompile(out errors);
            IProcessRuntime        ufRuntime;
            StepRuntime            ufStep;
            IPropertySetCollection ufCollection;

            pservice.TryUnfreeze(runtime.Id, out ufRuntime, out ufStep, out ufCollection);
            Assert.IsNotNull(ufRuntime);
            Assert.IsNotNull(ufCollection);
            Assert.IsNull(ufStep);
            Assert.IsNull(ufCollection.Get <int?>("Count"));
            Assert.AreEqual(ProcessStateEnum.NotStarted, ufRuntime.State);

            Tuple <ExecutionResult, StepRuntime> exResult = runtime.Execute(runtime.StartSteps[0], mEnv.Object);

            Assert.IsNotNull(exResult);
            pservice.TryUnfreeze(runtime.Id, out ufRuntime, out ufStep, out ufCollection);
            Assert.AreEqual(1, ufCollection.Get <int?>("Count"));
            Assert.AreEqual(ProcessStateEnum.Ready, ufRuntime.State);
            Assert.IsNotNull(ufStep);
            Assert.AreEqual("s_2", ufStep.StepId);

            exResult = runtime.Execute(exResult.Item2, mEnv.Object);
            Assert.IsNotNull(exResult);
            pservice.TryUnfreeze(runtime.Id, out ufRuntime, out ufStep, out ufCollection);
            Assert.AreEqual(2, ufCollection.Get <int?>("Count"));
            Assert.AreEqual(ProcessStateEnum.Ready, ufRuntime.State);
            Assert.IsNotNull(ufStep);
            Assert.AreEqual("s_3", ufStep.StepId);

            exResult = runtime.Execute(exResult.Item2, mEnv.Object);
            Assert.IsNotNull(exResult);
            pservice.TryUnfreeze(runtime.Id, out ufRuntime, out ufStep, out ufCollection);
            Assert.AreEqual(3, ufCollection.Get <int?>("Count"));
            Assert.AreEqual(ProcessStateEnum.Ready, ufRuntime.State);
            Assert.IsNotNull(ufStep);
            Assert.AreEqual("e_1", ufStep.StepId);

            exResult = runtime.Execute(exResult.Item2, mEnv.Object);
            Assert.IsNotNull(exResult);
            pservice.TryUnfreeze(runtime.Id, out ufRuntime, out ufStep, out ufCollection);
            Assert.AreEqual(3, ufCollection.Get <int?>("Count"));
            Assert.AreEqual(ProcessStateEnum.Completed, ufRuntime.State);
            Assert.IsNull(ufStep);
        }
        public void TestContinueTaskWithLinkAnVariables()
        {
            var factory = new ProcessBuilderFactory();
            var builder = factory.CreateProcess(id: "com.klaudwerk.workflow.renewal",
                                                name: "Renewal", description: "Policy Renewal");
            IReadOnlyList <ProcessValidationResult> result;

            builder
            .Variables().Name("v_1").Type(VariableTypeEnum.String).Done()
            .Variables().Name("v_2").Type(VariableTypeEnum.String).Done()
            .Start("s_1").Handler().HumanTask().Done().SetName("Start")
            .Vars().Name("v_1").Done()
            .Vars().Name("v_2").Done()
            .Done()
            .Step("s_2").Handler().HumanTask().Done()
            .Done()
            .Step("s_3").Handler().HumanTask().Done()
            .Vars().Name("v_1").OnExit().Done()
            .Vars().Name("v_2").OnExit().Done()
            .Done()
            .End("e_1").SetName("End Process").Done()
            .Link().From("s_1").To("s_2").Name("s_1_s_2").Done()
            .Link().From("s_1").To("s_3").Name("s_1_s_3").Done()
            .Link().From("s_2").To("e_1").Name("s2_end").Done()
            .Link().From("s_3").To("e_1").Name("s3_end").Done()
            .TryValidate(out result);

            ProcessDefinition processDefinition          = builder.Build();
            IProcessDefinitionPersisnenceService service = GetProcessDefinitionPersistenceService();

            service.Create(processDefinition, ProcessDefStatusEnum.Active, 1);
            // retrieve process definition
            var flows = service.ActivetWorkflows();

            Assert.IsNotNull(flows);
            Assert.AreEqual(1, flows.Count);
            ProcessDefinition    loadedPd;
            ProcessDefStatusEnum status;

            Assert.IsTrue(service.TryFind(flows[0].Id, flows[0].Version, out loadedPd, out status, out accounts));

            IProcessRuntimeService            pservice   = GetProcessRuntime();
            PropertySetCollection             collection = new PropertySetCollection(new PropertySchemaSet(new PropertySchemaFactory()));
            Mock <IProcessRuntimeEnvironment> mEnv       = new Mock <IProcessRuntimeEnvironment>();

            mEnv.SetupGet(m => m.PropertySet).Returns(collection).Verifiable();
            mEnv.Setup(m => m.TaskServiceAsync())
            .Returns(() =>
                     Task.FromResult(new ExecutionResult(StepExecutionStatusEnum.Suspend)))
            .Verifiable();
            mEnv.SetupGet(m => m.Transition).Returns("s_1_s_3");
            IProcessRuntime runtime = pservice.Create(loadedPd, collection);

            string[] errors;
            runtime.TryCompile(out errors);
            Tuple <ExecutionResult, StepRuntime> execute = runtime.Execute(runtime.StartSteps[0], mEnv.Object);

            Assert.IsNotNull(execute);
            Assert.AreEqual(StepExecutionStatusEnum.Suspend, execute.Item1.Status, "The Workflow should be in Suspended state");
            Assert.AreEqual(execute.Item2.StepId, "s_1");
            collection.Set("v_1", "v_1");
            collection.Set("v_2", "v_2");
            execute = runtime.Continue(mEnv.Object);
            Assert.IsNotNull(execute);
            Assert.AreEqual(StepExecutionStatusEnum.Ready, execute.Item1.Status, "The Workflow should be in Suspended state");
            Assert.AreEqual(execute.Item2.StepId, "s_3");
            Assert.IsNotNull(execute.Item2.StepDefinition.VariablesMap);
            Assert.AreEqual(2, execute.Item2.StepDefinition.VariablesMap.Length);
            Assert.AreEqual(VarRequiredEnum.OnExit, execute.Item2.StepDefinition.VariablesMap[0].Required);
            Assert.AreEqual(VarRequiredEnum.OnExit, execute.Item2.StepDefinition.VariablesMap[1].Required);
        }