public void UniqueValueConstructorRequiredNumberTest() { UniqueValueConstructor attributeConstructor = new UniqueValueConstructor(); attributeConstructor.ValueDeclaration = new UniqueValueDeclaration("mytestvalue%n%"); attributeConstructor.Attribute = ActiveConfig.DB.GetAttribute("personID"); attributeConstructor.UniqueAllocationAttributes.Add(attributeConstructor.Attribute); Guid newId = Guid.NewGuid(); try { MAObjectHologram sourceObject = ActiveConfig.DB.CreateMAObject(newId, "person"); attributeConstructor.Execute(sourceObject); AttributeValue value = sourceObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("personID")); if (value.IsNull) { Assert.Fail("The constructor did not generate any value"); } if (value.Value.ToString() != "mytestvalue1") { Assert.Fail("The constructor did not generate the expected value"); } } finally { ActiveConfig.DB.DeleteMAObjectPermanent(newId); } }
public void ValueConstructorSequentialIntegerAllocationTest() { SequentialIntegerAllocationConstructor attributeConstructor = new SequentialIntegerAllocationConstructor(); attributeConstructor.Attribute = ActiveConfig.DB.GetAttribute("unixUid"); attributeConstructor.Sequence = ActiveConfig.DB.GetSequence("unixUid"); Guid newId = Guid.NewGuid(); try { MAObjectHologram sourceObject = ActiveConfig.DB.CreateMAObject(newId, "person"); long nextInt = ActiveConfig.DB.GetNextSequenceValue("unixUid") + 1; attributeConstructor.Execute(sourceObject); AttributeValue value = sourceObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("unixUid")); if (value.IsNull) { Assert.Fail("The constructor did not generate any value"); } if (value.Value is long) { if (value.ValueLong != nextInt) { Assert.Fail("The constructor did not generate the expected value"); } } } finally { ActiveConfig.DB.DeleteMAObjectPermanent(newId); } }
public void AttributeDeleteConstructorSVTest() { AttributeValueDeleteConstructor attributeConstructor = new AttributeValueDeleteConstructor(); attributeConstructor.Attribute = ActiveConfig.DB.GetAttribute("mail"); attributeConstructor.RuleGroup = new RuleGroup(); attributeConstructor.RuleGroup.Items.Add(new ObjectChangeRule() { TriggerEvents = TriggerEvents.Add }); Guid newId = Guid.NewGuid(); try { MAObjectHologram sourceObject = ActiveConfig.DB.CreateMAObject(newId, "person"); sourceObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("mail"), "*****@*****.**"); sourceObject.CommitCSEntryChange(); sourceObject.DiscardPendingChanges(); sourceObject.SetObjectModificationType(ObjectModificationType.Update, false); attributeConstructor.Execute(sourceObject); AttributeValue value = sourceObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("mail")); if (!value.IsNull) { Assert.Fail("The constructor did not delete the attribute value"); } } finally { ActiveConfig.DB.DeleteMAObjectPermanent(newId); } }
public void PerformBulkUniqueAllocationTest() { UniqueValueConstructor constructor = new UniqueValueConstructor(); AcmaSchemaAttribute attribute = ActiveConfig.DB.GetAttribute("accountName"); constructor.UniqueAllocationAttributes = new System.Collections.Generic.List <AcmaSchemaAttribute>() { attribute }; constructor.ValueDeclaration = new UniqueValueDeclaration("{sn}%n%"); constructor.Attribute = attribute; List <Guid> preCreatedIDs = new List <Guid>(); List <Guid> testIDs = new List <Guid>(); int prestage = 100; int testcount = 200; try { for (int i = 1; i <= prestage; i++) { Guid newId = Guid.NewGuid(); MAObjectHologram sourceObject = ActiveConfig.DB.CreateMAObject(newId, "person"); preCreatedIDs.Add(newId); sourceObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("sn"), "yzhu"); sourceObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("accountName"), string.Format("yzhu{0}", i)); sourceObject.CommitCSEntryChange(); } for (int i = 1; i <= testcount; i++) { Guid newId = Guid.NewGuid(); MAObjectHologram sourceObject = ActiveConfig.DB.CreateMAObject(newId, "person"); testIDs.Add(newId); sourceObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("sn"), "yzhu"); constructor.Execute(sourceObject); sourceObject.CommitCSEntryChange(); AttributeValue value = sourceObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("accountName")); Assert.AreEqual(string.Format("yzhu{0}", i + prestage), value.ValueString); } } finally { foreach (Guid id in preCreatedIDs) { ActiveConfig.DB.DeleteMAObjectPermanent(id); } foreach (Guid id in testIDs) { ActiveConfig.DB.DeleteMAObjectPermanent(id); } } }
public void UniqueValueConstructorSelfUniqueDuplicateTest() { UniqueValueConstructor attributeConstructor = new UniqueValueConstructor(); attributeConstructor.ValueDeclaration = new UniqueValueDeclaration("mytestvalue"); attributeConstructor.Attribute = ActiveConfig.DB.GetAttribute("personID"); attributeConstructor.UniqueAllocationAttributes.Add(attributeConstructor.Attribute); Guid id1 = Guid.NewGuid(); Guid id2 = Guid.NewGuid(); try { MAObjectHologram sourceObject1 = ActiveConfig.DB.CreateMAObject(id1, "person"); MAObjectHologram sourceObject2 = ActiveConfig.DB.CreateMAObject(id2, "person"); attributeConstructor.Execute(sourceObject1); AttributeValue value = sourceObject1.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("personID")); if (value.IsNull) { Assert.Fail("The constructor did not generate any value"); } if (value.Value.ToString() != "mytestvalue") { Assert.Fail("The constructor did not generate the expected value"); } sourceObject1.CommitCSEntryChange(); try { attributeConstructor.Execute(sourceObject2); Assert.Fail("The constructor did not fail as expected"); } catch (MaximumAllocationAttemptsExceededException) { } } finally { ActiveConfig.DB.DeleteMAObjectPermanent(id1); ActiveConfig.DB.DeleteMAObjectPermanent(id2); } }
public void UniqueValueConstructorSelfUniqueRandomStringTest() { UniqueValueConstructor attributeConstructor = new UniqueValueConstructor(); attributeConstructor.ValueDeclaration = new UniqueValueDeclaration("%randstring:10%"); attributeConstructor.Attribute = ActiveConfig.DB.GetAttribute("personID"); attributeConstructor.UniqueAllocationAttributes.Add(attributeConstructor.Attribute); Guid id1 = Guid.NewGuid(); Guid id2 = Guid.NewGuid(); try { MAObjectHologram sourceObject1 = ActiveConfig.DB.CreateMAObject(id1, "person"); MAObjectHologram sourceObject2 = ActiveConfig.DB.CreateMAObject(id2, "person"); attributeConstructor.Execute(sourceObject1); AttributeValue value = sourceObject1.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("personID")); if (value.IsNull) { Assert.Fail("The constructor did not generate any value"); } sourceObject1.CommitCSEntryChange(); attributeConstructor.Execute(sourceObject2); value = sourceObject2.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("personID")); if (value.IsNull) { Assert.Fail("The constructor did not generate any value"); } } finally { ActiveConfig.DB.DeleteMAObjectPermanent(id1); ActiveConfig.DB.DeleteMAObjectPermanent(id2); } }
public void ExportCSEntryChangeAdd() { Guid id = Guid.NewGuid(); CSEntryChange csentry = CSEntryChange.Create(); csentry.DN = id.ToString(); csentry.ObjectModificationType = ObjectModificationType.Add; csentry.ObjectType = "person"; csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("mail", "*****@*****.**")); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("mailAlternateAddresses", new List <object> { "*****@*****.**", "*****@*****.**" })); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("unixUid", 44L)); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("expiryDates", new List <object>() { 55L, 66L, 77L })); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("directReports", new List <object>() { new Guid("{8FC92471-7835-4804-8BBB-0A5ED7078074}"), new Guid("{0EF7CC21-729E-4ED9-A3AF-8203796334C6}") })); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("supervisor", new Guid("{2807ED76-E262-4EB4-ABD9-9629F3830F12}"))); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("connectedToSap", true)); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("dateTimeMV", new List <object>() { DateTime.Parse("2010-01-01"), DateTime.Parse("2011-01-01") })); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("dateTimeSV", DateTime.Parse("2012-01-01"))); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("objectSids", new List <object>() { new byte[] { 0, 1, 2, 3, 4, 5 }, new byte[] { 2, 4, 6, 8, 0 } })); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("objectSid", new byte[] { 0, 1, 2, 3, 4 })); AcmaSchemaObjectClass objectClass = ActiveConfig.DB.GetObjectClass("person"); try { bool refretry; CSEntryExport.PutExportEntry(csentry, out refretry); MAObjectHologram sourceObject = ActiveConfig.DB.GetMAObject(id, objectClass); if (sourceObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("mail")).ValueString != "*****@*****.**") { Assert.Fail("One or more attribute changes were not committed"); } if (sourceObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("dateTimeSV")).ValueDateTime != DateTime.Parse("2012-01-01")) { Assert.Fail("One or more attribute changes were not committed"); } if (sourceObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("unixUid")).ValueLong != 44L) { Assert.Fail("One or more attribute changes were not committed"); } if (sourceObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("connectedToSap")).ValueBoolean != true) { Assert.Fail("One or more attribute changes were not committed"); } if (!sourceObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("objectSid")).ValueByte.SequenceEqual(new byte[] { 0, 1, 2, 3, 4 })) { Assert.Fail("One or more attribute changes were not committed"); } if (sourceObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("supervisor")).ValueGuid != new Guid("{2807ED76-E262-4EB4-ABD9-9629F3830F12}")) { Assert.Fail("One or more attribute changes were not committed"); } if (!sourceObject.GetMVAttributeValues(ActiveConfig.DB.GetAttribute("mailAlternateAddresses")).ContainsAllElements(new List <object> { "*****@*****.**", "*****@*****.**" })) { Assert.Fail("One or more attribute changes were not committed"); } if (!sourceObject.GetMVAttributeValues(ActiveConfig.DB.GetAttribute("expiryDates")).ContainsAllElements(new List <object>() { 55L, 66L, 77L })) { Assert.Fail("One or more attribute changes were not committed"); } if (!sourceObject.GetMVAttributeValues(ActiveConfig.DB.GetAttribute("dateTimeMV")).ContainsAllElements(new List <object>() { DateTime.Parse("2010-01-01"), DateTime.Parse("2011-01-01") })) { Assert.Fail("One or more attribute changes were not committed"); } if (!sourceObject.GetMVAttributeValues(ActiveConfig.DB.GetAttribute("directReports")).ContainsAllElements(new List <object>() { new Guid("{8FC92471-7835-4804-8BBB-0A5ED7078074}"), new Guid("{0EF7CC21-729E-4ED9-A3AF-8203796334C6}") })) { Assert.Fail("One or more attribute changes were not committed"); } if (!sourceObject.GetMVAttributeValues(ActiveConfig.DB.GetAttribute("objectSids")).ContainsAllElements(new List <object>() { new byte[] { 0, 1, 2, 3, 4, 5 }, new byte[] { 2, 4, 6, 8, 0 } })) { Assert.Fail("One or more attribute changes were not committed"); } } finally { ActiveConfig.DB.DeleteMAObjectPermanent(id); } }
public void ExportCSEntryChangeAddResurrect() { Guid originalId = Guid.NewGuid(); Guid replacementId = Guid.NewGuid(); if (!ActiveConfig.XmlConfig.ClassConstructors.Contains("person")) { ActiveConfig.XmlConfig.ClassConstructors.Add(new ClassConstructor() { ObjectClass = ActiveConfig.DB.GetObjectClass("person") }); } ActiveConfig.XmlConfig.ClassConstructors["person"].ResurrectionParameters = new DBQueryGroup(); ActiveConfig.XmlConfig.ClassConstructors["person"].ResurrectionParameters.Operator = GroupOperator.Any; DBQueryByValue query = new DBQueryByValue(ActiveConfig.DB.GetAttribute("sapPersonId"), ValueOperator.Equals, ActiveConfig.DB.GetAttribute("sapPersonId")); ActiveConfig.XmlConfig.ClassConstructors["person"].ResurrectionParameters.DBQueries.Add(query); CSEntryChange csentry = CSEntryChange.Create(); csentry.DN = originalId.ToString(); csentry.ObjectModificationType = ObjectModificationType.Add; csentry.ObjectType = "person"; csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("mail", "*****@*****.**")); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("mailAlternateAddresses", new List <object> { "*****@*****.**", "*****@*****.**" })); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("unixUid", 44L)); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("expiryDates", new List <object>() { 55L, 66L, 77L })); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("directReports", new List <object>() { new Guid("{8FC92471-7835-4804-8BBB-0A5ED7078074}"), new Guid("{0EF7CC21-729E-4ED9-A3AF-8203796334C6}") })); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("supervisor", new Guid("{2807ED76-E262-4EB4-ABD9-9629F3830F12}"))); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("connectedToSap", true)); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("objectSids", new List <object>() { new byte[] { 0, 1, 2, 3, 4, 5 }, new byte[] { 2, 4, 6, 8, 0 } })); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("objectSid", new byte[] { 0, 1, 2, 3, 4 })); try { bool refretry; CSEntryExport.PutExportEntry(csentry, out refretry); AcmaSchemaObjectClass objectClass = ActiveConfig.DB.GetObjectClass("person"); MAObjectHologram originalObject = ActiveConfig.DB.GetMAObject(originalId, objectClass); originalObject.SetObjectModificationType(ObjectModificationType.Update, false); originalObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("sapPersonId"), 7777L); originalObject.SetAttributeValue(ActiveConfig.DB.GetAttribute("accountName"), "jesus"); originalObject.DeletedTimestamp = DateTime.UtcNow.Ticks; originalObject.CommitCSEntryChange(); csentry = CSEntryChange.Create(); csentry.DN = replacementId.ToString(); csentry.ObjectModificationType = ObjectModificationType.Add; csentry.ObjectType = "person"; csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("mail", "*****@*****.**")); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("sapPersonId", 7777L)); CSEntryExport.PutExportEntry(csentry, out refretry); MAObjectHologram newObject = ActiveConfig.DB.GetMAObjectOrDefault(replacementId); if (newObject == null) { Assert.Fail("The object with the new ID was not found"); } if (newObject.GetSVAttributeValue(ActiveConfig.DB.GetAttribute("accountName")) != "jesus") { Assert.Fail("The object was not resurrected"); } if (newObject.DeletedTimestamp != 0) { Assert.Fail("The object was not undeleted"); } originalObject = ActiveConfig.DB.GetMAObjectOrDefault(originalId); if (originalObject != null) { Assert.Fail("The original object still exists"); } } finally { ActiveConfig.DB.DeleteMAObjectPermanent(originalId); ActiveConfig.DB.DeleteMAObjectPermanent(replacementId); } }
private static MAObjectHologram ExportShadowObject(CSEntryChange csentry) { if (!csentry.AttributeChanges.Contains("shadowLink")) { throw new ShadowObjectExportException("The shadowLink attribute was not present"); } if (!csentry.AttributeChanges.Contains("shadowParent")) { throw new ShadowObjectExportException("The shadowParent attribute was not present"); } ValueChange shadowParentValueChange = csentry.AttributeChanges["shadowParent"].ValueChanges.FirstOrDefault(t => t.ModificationType == ValueModificationType.Add); if (shadowParentValueChange == null) { throw new ShadowObjectExportException("The shadowParent attribute did not contain any value adds"); } if (shadowParentValueChange.Value == null) { throw new ShadowObjectExportException("The shadowParent attribute was null"); } Guid shadowParentID; if (shadowParentValueChange.Value is Guid) { shadowParentID = (Guid)shadowParentValueChange.Value; } else { shadowParentID = new Guid(shadowParentValueChange.Value.ToSmartString()); } MAObjectHologram parentHologram = ActiveConfig.DB.GetMAObjectOrDefault(shadowParentID); if (parentHologram == null) { throw new ShadowObjectExportException(string.Format("The shadow parent {0} for object {1} was not found", shadowParentID, csentry.DN)); } ValueChange shadowLinkValueChange = csentry.AttributeChanges["shadowLink"].ValueChanges.FirstOrDefault(t => t.ModificationType == ValueModificationType.Add); if (shadowLinkValueChange == null) { throw new ShadowObjectExportException("The shadowLink attribute did not contain any value adds"); } string shadowLinkID = shadowLinkValueChange.Value as string; AcmaSchemaShadowObjectLink link = ActiveConfig.DB.ShadowObjectLinks.FirstOrDefault(t => t.Name == shadowLinkID); if (link == null) { throw new ShadowObjectExportException(string.Format("The shadowLink '{0}' was not found in the database", shadowLinkID)); } AcmaSchemaObjectClass shadowObjectClass = ActiveConfig.DB.ObjectClasses.FirstOrDefault(t => t.Name == csentry.ObjectType); if (shadowObjectClass == null) { throw new NoSuchObjectTypeException(csentry.ObjectType); } if (shadowObjectClass != link.ShadowObjectClass) { throw new ShadowObjectExportException( string.Format("The object class exported ({0}) does not match the expected object class ({1}) specified by the link '{2}'", shadowObjectClass.Name, link.ShadowObjectClass, link.Name)); } if (link.ParentObjectClass != parentHologram.ObjectClass) { throw new ShadowObjectExportException(string.Format( "The specified parent object '{0}' was of the object type '{1}', however the link '{2}' defines '{3}' as the expected parent object type", parentHologram.ObjectID, parentHologram.ObjectClass.Name, link.Name, link.ParentObjectClass.Name)); } AttributeValue provisioningAttribute = parentHologram.GetSVAttributeValue(link.ProvisioningAttribute); if (provisioningAttribute.ValueBoolean == true) { throw new ShadowObjectExportException(string.Format("The shadow parent {0} already has a shadow object referenced by the link '{1}'", shadowParentID, shadowLinkID)); } return(parentHologram.ProvisionShadowObject(link, csentry)); }