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);
        }
Ejemplo n.º 2
0
        protected virtual void OnCreateAndListProcessDefinition(IProcessDefinitionPersisnenceService service)
        {
            var processDefinition = OnCreateProcessDefinition(service);
            IReadOnlyList <ProcessDefinitionDigest> flows = service.LisAlltWorkflows();

            Assert.IsNotNull(flows);
            Assert.AreEqual(1, flows.Count);
            Assert.AreEqual(processDefinition.Name, flows[0].Name);
            Assert.AreEqual(processDefinition.FlowId, flows[0].FlowId);
        }
Ejemplo n.º 3
0
        protected virtual void OnChangeProcessDefinitionStatus(IProcessDefinitionPersisnenceService service)
        {
            var processDefinition = BuildProcessdefinition();

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

            Assert.IsNotNull(flows);
            Assert.AreEqual(1, flows.Count);
            flows = service.ActivetWorkflows();
            Assert.IsNotNull(flows);
            Assert.AreEqual(1, flows.Count);
            Guid id = flows[0].Id;

            Assert.IsTrue(service.SetStatus(id, 1, ProcessDefStatusEnum.NotActive));
            flows = service.ActivetWorkflows();
            Assert.IsNotNull(flows);
            Assert.AreEqual(0, flows.Count);
            flows = service.LisAlltWorkflows();
            Assert.IsNotNull(flows);
            Assert.AreEqual(1, flows.Count);
        }
        public void TestRemoveRolesShouldRemoveSpecificRoles()
        {
            var collection = _database.GetCollection <ProcessDefinitionPersistence>(MongoProcessDefinitionPersistenceService.CollectionName);
            IProcessDefinitionPersisnenceService service = InstService();

            AccountData[] accounts = new[]
            {
                new AccountData
                {
                    AccountType  = 1,
                    Id           = Guid.NewGuid(),
                    Name         = "Underwriter",
                    SourceSystem = "ActiveDirectory"
                },
                new AccountData
                {
                    AccountType  = 1,
                    Id           = Guid.NewGuid(),
                    Name         = "Modeler",
                    SourceSystem = "ActiveDirectory"
                },
            };

            OnCreateFlowWithAssociatedSecutityAccounts(service, accounts);
            Assert.AreEqual(1, collection.Count(pd => true));
            IReadOnlyList <ProcessDefinitionDigest> flows = service.LisAlltWorkflows();

            Assert.IsNotNull(flows);
            Assert.AreEqual(1, flows.Count);
            ProcessDefinitionDigest flow = flows.ElementAt(0);

            service.RemoveRoles(flow.Id, flow.Version, accounts[0]);
            var idFilter
                = Builders <ProcessDefinitionPersistence> .Filter.Eq(r => r.Id, flow.Id);

            ProcessDefinitionPersistence persistence = collection.FindSync(idFilter).FirstOrDefault();

            Assert.IsNotNull(persistence);
            Assert.IsNotNull(persistence.Accounts);
            Assert.AreEqual(1, persistence.Accounts.Count);
            Assert.AreEqual(accounts[1].Name, persistence.Accounts[0].Name);
        }
Ejemplo n.º 5
0
        public void DeployWorkflow(Guid guid)
        {
            List <ProcessDefinition> defs = new List <ProcessDefinition>();

            _registries.ForEach(r =>
            {
                ProcessDefinition pd;
                if (r.TryGet(guid, out pd))
                {
                    defs.Add(pd);
                }
            });
            if (defs.Count == 0)
            {
                throw new ArgumentException($"No Process Definition with ID={guid} was found.");
            }
            if (defs.Count > 1)
            {
                throw new ArgumentException($"{defs.Count} Process Definitions with ID={guid} was found.");
            }
            Md5CalcVisitor visitor = new Md5CalcVisitor();

            defs[0].Accept(visitor);
            string md5 = visitor.CalculateMd5();
            IReadOnlyList <ProcessDefinitionDigest> processes = _persistence.LisAlltWorkflows();
            var processDefinitionDigests = processes.Where(p => p.Id == guid).ToArray();
            int nextVersion = processDefinitionDigests.Length > 0?processDefinitionDigests.Max(p => p.Version) + 1:1;

            foreach (ProcessDefinitionDigest p in processDefinitionDigests)
            {
                if (p.Md5 == md5)
                {
                    throw new ArgumentException($"Process ID={defs[0].Id} MD5={md5} already deployed. Cannot deploy the same process with the same MD5.");
                }
            }
            foreach (ProcessDefinitionDigest p in processes)
            {
                _persistence.SetStatus(p.Id, p.Version, ProcessDefStatusEnum.NotActive);
            }
            _persistence.Create(defs[0], ProcessDefStatusEnum.Active, nextVersion);
        }
        public void TestRetrieveProcessDefinitionListsForAccounts()
        {
            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"
                },
                new AccountData
                {
                    AccountType  = 1,
                    Id           = Guid.NewGuid(),
                    Name         = "Role1",
                    SourceSystem = "ActiveDirectory"
                },
                new AccountData
                {
                    AccountType  = 1,
                    Id           = Guid.NewGuid(),
                    Name         = "Role2",
                    SourceSystem = "ActiveDirectory"
                },
                new AccountData
                {
                    AccountType  = 1,
                    Id           = Guid.NewGuid(),
                    Name         = "None",
                    SourceSystem = "ActiveDirectory"
                }
            };
            var collection = _database.GetCollection <ProcessDefinitionPersistence>(MongoProcessDefinitionPersistenceService.CollectionName);
            IProcessDefinitionPersisnenceService service = InstService();
            ProcessDefinition pd1 = BuildProcessdefinition();
            ProcessDefinition pd2 = BuildProcessdefinition(id: "mongo.flow", name: "pd_1", description: "second flow");

            service.Create(pd1, ProcessDefStatusEnum.Active, 1, accounts[0], accounts[1]);
            service.Create(pd2, ProcessDefStatusEnum.NotActive, 1, accounts[2], accounts[3]);
            //List Underwriter should return one definition
            IReadOnlyList <ProcessDefinitionDigest> digest = service.LisAlltWorkflows(accounts[0].Name);

            Assert.IsNotNull(digest);
            Assert.AreEqual(1, digest.Count);
            Assert.AreEqual(pd1.Name, digest[0].Name);

            digest = service.LisAlltWorkflows(accounts[1].Name, accounts[3].Name);
            Assert.IsNotNull(digest);
            Assert.AreEqual(2, digest.Count);
            Assert.AreEqual(1, digest.Count(c => c.Name == pd1.Name));
            Assert.AreEqual(1, digest.Count(c => c.Name == pd2.Name));

            digest = service.LisAlltWorkflows(accounts[4].Name);
            Assert.IsNotNull(digest);
            Assert.AreEqual(0, digest.Count);
        }