public void TestCreatePolicySetChannelsMasterCataloguePrepopulateRouting() { string testCatalogue = m_testPath + "TestCreatePolicySetChannelsMasterCatalogue.xml"; string languageFilename = m_testPath + "TestCreatePolicySetChannelsMasterCatalogueLanguage.xml"; string policySetFilename = m_testPath + "TestCreatePolicySetChannelsMasterCataloguePolicySet.xml"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.Reset(); Guid languageId = new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"); PolicyLanguageCache.Instance.ActiveLanguageId = languageId; IPolicyLanguage language = new PolicyLanguage(languageId, "en"); language.DefaultLanguage = true; languageStore.AddLanguage(language); PolicyLanguageCache policyLanguageCache = PolicyLanguageCache.Instance; policyLanguageCache.SetLanguageItemText(languageId, new Guid("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), "New catalogue"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{9465CA41-A0A1-40BD-BE26-E83E17D83148}"), "New policy set"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{08BC5764-4879-42ED-9AD8-15040C4ADEDE}"), "New policy"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{39C06E29-074C-46C8-BE3D-F1CD92BB8D66}"), "Test channel"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{03005F4E-04FC-4287-B2A6-25F877D9C31B}"), "Test sources"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{3BF2C1D6-0F40-4A32-A311-6F65A5D271BD}"), "Test destinations"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{A8CEBEDF-92EA-4DCC-8053-08E5245ED84D}"), "Test routing table"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{86D8056D-BA38-44FA-B9BD-100CFB7113F8}"), "Test condition group"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{040C4E16-EE88-4B91-833F-8F30A536DAC6}"), "Test action group"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{F03E6CD1-98C0-4590-B789-907ECF90BEBF}"), "Test data element"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{6197CDBE-9F42-4A61-9369-238355BAB404}"), "Test data element display"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{E5C29C65-9600-42D9-8CD6-6638F40F9341}"), "Test data item"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{463295F1-A5A2-4BB1-B029-7917AC75E9E6}"), "Test action"); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); IPolicyStore policyStore = new XmlStore(); IPolicySet policySet = new PolicySet(new Guid("{29EC30A5-1271-4306-89C8-5811172D901A}"), new TranslateableLanguageItem("{9465CA41-A0A1-40BD-BE26-E83E17D83148}"), policyStore, policyCatalogue, false); IPolicy newPolicy = new P5Policy(policySet, new Guid("{D257D4DC-4A12-438F-A32A-CF1CE4474441}"), new TranslateableLanguageItem("{08BC5764-4879-42ED-9AD8-15040C4ADEDE}"), PolicyStatus.Active); policySet.Policies.Add(newPolicy); // Create policy set channel PolicyChannel channel = new PolicyChannel(new Guid("{0FE26539-7AAD-46DC-8D5B-9651CC00B9E4}"), new TranslateableLanguageItem("{39C06E29-074C-46C8-BE3D-F1CD92BB8D66}"), ChannelType.SMTP); // Create routing table RoutingTable routingTable = new RoutingTable(new Guid("{CDF0252C-3D5D-4AFB-98C2-89CF00FE2175}"), new TranslateableLanguageItem("{A8CEBEDF-92EA-4DCC-8053-08E5245ED84D}"), ChannelType.SMTP); IRoutingItemCollection senders = new RoutingItemCollection(new Guid("{441FDCBF-B606-4325-8CD5-E829AD5303B9}"), "{03005F4E-04FC-4287-B2A6-25F877D9C31B}"); senders.Add(new RoutingItem(new Guid("{D41A47E2-CC13-46FF-BE83-829625792576}"), "James Brown", "*****@*****.**")); senders.Add(new RoutingItem(new Guid("{B031DFE9-54E7-482B-8955-18CFB8F06A40}"), "Nat King Cole", "*****@*****.**")); IRoutingItemCollection recipients = new RoutingItemCollection(new Guid("{29C44E5C-5405-409F-8513-A99AE246536F}"), "{3BF2C1D6-0F40-4A32-A311-6F65A5D271BD}"); recipients.Add(new RoutingItem(new Guid("{9E26C6A2-ABE2-427D-9D78-5B8547ADA8D2}"), "Jet Li", "*****@*****.**")); routingTable.Sources.Add(senders); routingTable.Destinations.Add(recipients); // Assign routing table to channel channel.Routing = routingTable; // Create action matrix ActionMatrix actionMatrix = new ObjectModel.ActionMatrix(false); // Create an action matrix cell ActionMatrixCell actionMatrixCell = new ObjectModel.ActionMatrixCell(senders, recipients); // Populate the action matrix cell ConditionGroup conditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new TranslateableLanguageItem("{86D8056D-BA38-44FA-B9BD-100CFB7113F8}"), ConditionLogic.AND, false); ActionGroup actionGroup = new ObjectModel.ActionGroup(new Guid("{32D97853-2680-4B02-A391-22CAEE87B017}"), new TranslateableLanguageItem("{040C4E16-EE88-4B91-833F-8F30A536DAC6}"), 1); IActionConditionGroup actionConditionGroup = new ObjectModel.ActionConditionGroup(conditionGroup, actionGroup, false); ObjectModel.Action action = new ObjectModel.Action(new Guid("{5153B00E-7D30-4D37-90F9-75E55AA1B32B}"), new TranslateableLanguageItem("{463295F1-A5A2-4BB1-B029-7917AC75E9E6}"), "TestAction.dll", "Test.Action", RunAt.Client, false, 1); //TODO JE DataItem dataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("{E5C29C65-9600-42D9-8CD6-6638F40F9341}"), DataType.String, "Not again, when will it ever end!"); DataElement dataElement = new DataElement(new Guid("{39500989-0B41-4C4E-85DF-CCB4FBD5BEB8}"), new TranslateableLanguageItem("{F03E6CD1-98C0-4590-B789-907ECF90BEBF}"), new TranslateableLanguageItem("{6197CDBE-9F42-4A61-9369-238355BAB404}"), DataType.String, dataItem); action.DataElements.Add(dataElement); actionConditionGroup.ActionGroup.Actions.Add(action); // Assign the action condition group to the matrix cell actionMatrixCell.ActionConditionGroups.Add(actionConditionGroup); // Assign the action matrix cell to the action matrix actionMatrix[senders, recipients] = actionMatrixCell; // Assign action matrix to channel channel.Actions = actionMatrix; // Assign channel to policy newPolicy.Channels.Add(channel); // Save everything IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, language.Identifier); catalogueWriter.WriteCatalogue(policyCatalogue); catalogueWriter.Close(); policySet.Save(); TestHelpers.CompareXml(policySetFilename, policyStore.XMLRepresentation); IRoutingMatrixCell routingMatrixCell = routingTable[senders, recipients]; string expectedCatalogueXml = System.IO.File.ReadAllText(testCatalogue); expectedCatalogueXml = expectedCatalogueXml.Replace("{0}", routingMatrixCell.Name.Identifier.ToString("B").ToUpper()); expectedCatalogueXml = expectedCatalogueXml.Replace("{1}", routingMatrixCell.Description.Identifier.ToString("B").ToUpper()); testCatalogue += ".tmp"; System.IO.File.WriteAllText(testCatalogue, expectedCatalogueXml); TestHelpers.CompareXml(testCatalogue, catalogueStore.GetStoreXML(policySet.MasterCatalogue.Identifier)); string expectedLanguageXml = System.IO.File.ReadAllText(languageFilename); expectedLanguageXml = expectedLanguageXml.Replace("{0}", routingMatrixCell.Name.Identifier.ToString("B").ToUpper()); expectedLanguageXml = expectedLanguageXml.Replace("{1}", routingMatrixCell.Description.Identifier.ToString("B").ToUpper()); languageFilename += ".tmp"; System.IO.File.WriteAllText(languageFilename, expectedLanguageXml); TestHelpers.CompareXml(languageFilename, languageStore.GetXMLRepresentation(language.Identifier, language.Name.Value)); }
public void TestReadPolicyAddActionAndSave() { string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml"; string languageFilename = m_testPath + "TestRealPolicyLanguage.xml"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.Reset(); string languageName; Guid languageId = languageStore.AddLanguage(System.IO.File.ReadAllText(languageFilename), out languageName); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); string policyFilename = m_testPath + "TestReadPolicyRulesReadAndSave.xml"; XmlStore policyStore = new XmlStore(System.IO.File.ReadAllText(policyFilename)); XmlPolicyReader xmlPolicyReader = policyStore.Reader as XmlPolicyReader; IPolicySet policySet = xmlPolicyReader.PolicySets[0]; IPolicy policy = policySet.Policies[0]; Assert.AreEqual(1, policy.Channels.Count, "Expected one channel"); IPolicyChannel channel = policy.Channels[0]; IActionMatrix actionMatrix = channel.Actions; IRoutingItemCollection senders = policyCatalogue.LocationsCollection[new Guid("{A81631A6-6AA3-45F7-AADD-4853447E5BD6}")]; Assert.IsNotNull(senders, "Expected a valid sources collection"); IRoutingItemCollection recipients = policyCatalogue.LocationsCollection[new Guid("{4E1B9EAB-E892-4E47-BBE6-9D70B2438333}")]; Assert.IsNotNull(recipients, "Expected a valid destinations collection"); PolicyLanguageCache policyLanguageCache = PolicyLanguageCache.Instance; policyLanguageCache.SetLanguageItemText(languageId, new Guid("{5B486305-A84C-4DF0-B29C-94FCB0053761}"), "This is a test action"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{4182414A-C775-4EFB-89FF-54FBAC334D71}"), "This is a test data element"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{25D5679E-B4B5-4C9E-8E85-5A922399B291}"), "This is a test data element description"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{6C94A67C-F43E-4761-89B4-EB0AD75CB29B}"), "This is a test data item"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{A614A4FF-714C-4AAD-8D5D-170EB92D0B3A}"), "This new action group"); // Create a new action matrix cell ActionMatrixCell actionMatrixCell = new ObjectModel.ActionMatrixCell(senders, recipients); ConditionGroup conditionGroup = policyCatalogue.ConditionGroups[0] as ConditionGroup; ActionGroup actionGroup = new ObjectModel.ActionGroup(new Guid("{A9E40C80-1FBC-405C-A6C9-241EC956D2AA}"), new TranslateableLanguageItem("{A614A4FF-714C-4AAD-8D5D-170EB92D0B3A}"), 2); IActionConditionGroup actionConditionGroup = new ObjectModel.ActionConditionGroup(conditionGroup, actionGroup, false); actionMatrixCell.ActionConditionGroups.Add(actionConditionGroup); // Add the action matrix cell to the channel actionMatrix[senders, recipients] = actionMatrixCell; ObjectModel.Action action = new ObjectModel.Action(new Guid("{707303BD-3EBB-48FD-93F3-CB72C6AAFF47}"), new TranslateableLanguageItem("{5B486305-A84C-4DF0-B29C-94FCB0053761}"), "TestAssembly.dll", "DoThis.Now", RunAt.Client, false, 1); //TODO JE IDataItem dataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("{6C94A67C-F43E-4761-89B4-EB0AD75CB29B}"), DataType.String, "This is a test item"); action.DataElements.Add(new DataElement(new Guid("{B10BEEC4-E851-4E25-A6AE-C6CEC3F767EB}"), new TranslateableLanguageItem("{4182414A-C775-4EFB-89FF-54FBAC334D71}"), new TranslateableLanguageItem("{25D5679E-B4B5-4C9E-8E85-5A922399B291}"), DataType.String, dataItem)); actionConditionGroup.ActionGroup.Actions.Add(action); // Save everthing IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId); catalogueWriter.WriteCatalogue(policyCatalogue); catalogueWriter.Close(); policySet.Save(); TestHelpers.CompareXml(m_testPath + "TestReadPolicyAddActionAndSave.Catalogue.xml", catalogueStore.GetStoreXML(policyCatalogue.Identifier)); TestHelpers.CompareXml(m_testPath + "TestReadPolicyAddActionAndSave.PolicySet.xml", policyStore.XMLRepresentation); TestHelpers.CompareXml(m_testPath + "TestReadPolicyAddActionAndSave.Language.xml", languageStore.GetXMLRepresentation(languageId, languageName)); }