public void TestCreateProcessDefinitionWithScriptAndRetrieve()
        {
            ProcessDefinition pd      = BuildProcessdefinition("id.123", "test_definition", "description");
            Md5CalcVisitor    visitor = new Md5CalcVisitor();

            pd.Accept(visitor);
            string md5 = visitor.CalculateMd5();
            IProcessDefinitionPersisnenceService service = InstService();

            service.Create(pd, ProcessDefStatusEnum.Active, 1);
            IReadOnlyList <ProcessDefinitionDigest> flows = service.LisAlltWorkflows();

            Assert.IsNotNull(flows);
            Assert.AreEqual(1, flows.Count);
            ProcessDefStatusEnum stat;
            ProcessDefinition    savedPd;

            AccountData[] accounts;
            Assert.IsTrue(service.TryFind(flows[0].Id, flows[0].Version, out savedPd, out stat, out accounts));

            Assert.IsNotNull(savedPd);
            visitor.Reset();
            savedPd.Accept(visitor);
            string savedMd5 = visitor.CalculateMd5();

            Assert.AreEqual(md5, savedMd5);
        }
Example #2
0
        protected virtual void OnCreateProcessUsingExistingAccounts(IProcessDefinitionPersisnenceService service)
        {
            var processDefinition = BuildProcessdefinition();

            Assert.IsNotNull(processDefinition);
            AccountData[] accounts = new[]
            {
                new AccountData
                {
                    AccountType  = 1,
                    Id           = Guid.NewGuid(),
                    Name         = "Underwriters",
                    SourceSystem = "ActiveDirectory"
                },
                new AccountData
                {
                    AccountType  = 1,
                    Id           = Guid.NewGuid(),
                    Name         = "Modeler",
                    SourceSystem = "ActiveDirectory"
                },
            };
            service.CreateAccounts(accounts);
            service.Create(processDefinition, ProcessDefStatusEnum.Active, 1, accounts);
            ProcessDefStatusEnum status;

            AccountData[] pdAccounts;
            Assert.IsTrue(service.TryFind(processDefinition.Id, 1, out processDefinition, out status, out pdAccounts));
            Assert.IsNotNull(pdAccounts);
            Assert.AreEqual(2, pdAccounts.Length);
            Assert.IsNotNull(pdAccounts.FirstOrDefault(d => d.Id == accounts[0].Id));
            Assert.IsNotNull(pdAccounts.FirstOrDefault(d => d.Id == accounts[1].Id));
        }
Example #3
0
        protected virtual void OnFindNonExistingFlowShouldReturnFalse(IProcessDefinitionPersisnenceService service)
        {
            ProcessDefStatusEnum status;
            ProcessDefinition    def;

            AccountData[] pdAccounts;
            Assert.IsFalse(service.TryFind(Guid.NewGuid(), 1, out def, out status, out pdAccounts));
            Assert.IsNull(def);
            Assert.AreEqual(ProcessDefStatusEnum.NotActive, status);
        }
Example #4
0
        public void PrintDefinition(Guid guid, int aVersion)
        {
            ProcessDefinition    pd;
            ProcessDefStatusEnum stat;

            AccountData[] accounts;
            if (!_persistence.TryFind(guid, aVersion, out pd, out stat, out accounts))
            {
                Console.WriteLine($"Cannot find workflow Id={guid} version={aVersion}");
                return;
            }
            Console.WriteLine(JsonConvert.SerializeObject(pd, Formatting.Indented));
        }
Example #5
0
        protected virtual void OnCreateFlowWithAssociatedSecutityAccounts(IProcessDefinitionPersisnenceService service, AccountData[] accounts)
        {
            var processDefinition = BuildProcessdefinition();

            Assert.IsNotNull(processDefinition);
            service.Create(processDefinition, ProcessDefStatusEnum.Active, 1, accounts);
            ProcessDefStatusEnum status;

            AccountData[] pdAccounts;
            Assert.IsTrue(service.TryFind(processDefinition.Id, 1, out processDefinition, out status, out pdAccounts));
            Assert.IsNotNull(pdAccounts);
            Assert.AreEqual(2, pdAccounts.Length);
            Assert.IsNotNull(pdAccounts.FirstOrDefault(d => d.Id == accounts[0].Id));
            Assert.IsNotNull(pdAccounts.FirstOrDefault(d => d.Id == accounts[1].Id));
        }
Example #6
0
        protected virtual void OnPossibleToUpdateNameAndDescription(IProcessDefinitionPersisnenceService service)
        {
            var processDefinition = BuildProcessdefinition();

            service.Create(processDefinition, ProcessDefStatusEnum.Active, 1);
            ProcessDefinition    definition;
            ProcessDefStatusEnum stat;

            AccountData[] pdAccounts;
            Assert.IsTrue(service.TryFind(processDefinition.Id, 1, out definition, out stat, out pdAccounts));
            service.Update(processDefinition.Id, 1, pd => { pd.Name = "New Name"; });
            var flows = service.ActivetWorkflows();

            Assert.IsNotNull(flows);
            Assert.AreEqual("New Name", flows[0].Name);
        }
Example #7
0
        protected virtual void OnTryFindFlow(IProcessDefinitionPersisnenceService service)
        {
            var processDefinition = BuildProcessdefinition();

            Assert.IsNotNull(processDefinition);
            service.Create(processDefinition, ProcessDefStatusEnum.Active, 1);
            ProcessDefinition    definition;
            ProcessDefStatusEnum stat;

            AccountData[] pdAccounts;
            Assert.IsTrue(service.TryFind(processDefinition.Id, 1, out definition, out stat, out pdAccounts));
            Assert.IsNotNull(definition);
            Md5CalcVisitor visitor = new Md5CalcVisitor();

            processDefinition.Accept(visitor);
            string md5 = visitor.CalculateMd5();

            visitor.Reset();
            definition.Accept(visitor);
            string restoredMd5 = visitor.CalculateMd5();

            Assert.AreEqual(md5, restoredMd5);
        }
        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);
        }