protected virtual Uid CreateTestUser(string username)
        {
            ICollection <ConnectorAttribute> createAttributes = GetTestCreateConnectorObject(username);
            ConnectorFacade facade = GetFacade();
            Uid             uid    = facade.Create(ObjectClass.ACCOUNT, createAttributes, null);

            Assert.IsNotNull(uid);
            ConnectorObject co = facade.GetObject(ObjectClass.ACCOUNT, uid, null);

            Assert.AreEqual(co.Uid, uid);
            return(uid);
        }
        public void TestAttributeTypeMap()
        {
            ConnectorPoolManager.Dispose();
            ConnectorInfoManager manager = GetConnectorInfoManager();
            ConnectorInfo        info1   = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstStatefulConnector");

            Assert.IsNotNull(info1);

            APIConfiguration config = info1.CreateDefaultAPIConfiguration();

            config.ConnectorPoolConfiguration.MinIdle = 0;
            config.ConnectorPoolConfiguration.MaxIdle = 0;

            ConnectorFacade facade = ConnectorFacadeFactory.GetInstance().NewInstance(config);

            HashSet <ConnectorAttribute> createAttributes = new HashSet <ConnectorAttribute>();
            IDictionary <string, object> mapAttribute     = new Dictionary <string, object>();

            mapAttribute["email"]   = "*****@*****.**";
            mapAttribute["primary"] = true;
            mapAttribute["usage"]   = new List <String>()
            {
                "home", "work"
            };
            createAttributes.Add(ConnectorAttributeBuilder.Build("emails", mapAttribute));

            Uid uid = facade.Create(ObjectClass.ACCOUNT, createAttributes, null);

            Assert.AreEqual(uid.GetUidValue(), "*****@*****.**");

            ConnectorObject co    = facade.GetObject(ObjectClass.ACCOUNT, new Uid("0"), null);
            object          value = ConnectorAttributeUtil.GetSingleValue(co.GetAttributeByName("emails"));

            Assert.IsTrue(value is IDictionary);
            Assert.IsTrue(((IDictionary)value)["usage"] is IList);
        }
Beispiel #3
0
        public void UpdateMergeTests()
        {
            ConnectorAttribute     expected, actual;
            Configuration          config  = new MockConfiguration(false);
            ConnectorFacadeFactory factory = ConnectorFacadeFactory.GetInstance();
            SafeType <Connector>   clazz   = SafeType <Connector> .Get <MockUpdateConnector>();

            // **test only**
            APIConfiguration impl = TestHelpers.CreateTestConfiguration(clazz, config);

            impl.SetTimeout(SafeType <APIOperation> .Get <GetApiOp>(), APIConstants.NO_TIMEOUT);
            impl.SetTimeout(SafeType <APIOperation> .Get <UpdateApiOp>(), APIConstants.NO_TIMEOUT);
            impl.SetTimeout(SafeType <APIOperation> .Get <SearchApiOp>(), APIConstants.NO_TIMEOUT);
            ConnectorFacade facade = factory.NewInstance(impl);
            // sniff test to make sure we can get an object..
            ConnectorObject obj = facade.GetObject(ObjectClass.ACCOUNT, NewUid(1), null);

            Assert.AreEqual(NewUid(1), obj.Uid);
            // ok lets add an attribute that doesn't exist..
            String ADDED     = "somthing to add to the object";
            String ATTR_NAME = "added";
            ICollection <ConnectorAttribute> addAttrSet;

            addAttrSet = CollectionUtil.NewSet((IEnumerable <ConnectorAttribute>)obj.GetAttributes());
            addAttrSet.Add(ConnectorAttributeBuilder.Build(ATTR_NAME, ADDED));
            Name name = obj.Name;

            addAttrSet.Remove(name);
            Uid uid = facade.AddAttributeValues(ObjectClass.ACCOUNT, obj.Uid, ConnectorAttributeUtil.FilterUid(addAttrSet), null);

            // get back the object and see if there are the same..
            addAttrSet.Add(name);
            ConnectorObject addO = new ConnectorObject(ObjectClass.ACCOUNT, addAttrSet);

            obj = facade.GetObject(ObjectClass.ACCOUNT, NewUid(1), null);
            Assert.AreEqual(addO, obj);
            // attempt to add on to an existing attribute..
            addAttrSet.Remove(name);
            uid = facade.AddAttributeValues(ObjectClass.ACCOUNT, obj.Uid, ConnectorAttributeUtil.FilterUid(addAttrSet), null);
            // get the object back out and check on it..
            obj      = facade.GetObject(ObjectClass.ACCOUNT, uid, null);
            expected = ConnectorAttributeBuilder.Build(ATTR_NAME, ADDED, ADDED);
            actual   = obj.GetAttributeByName(ATTR_NAME);
            Assert.AreEqual(expected, actual);
            // attempt to delete a value from an attribute..
            ICollection <ConnectorAttribute> deleteAttrs = CollectionUtil.NewSet((IEnumerable <ConnectorAttribute>)addO.GetAttributes());

            deleteAttrs.Remove(name);
            uid      = facade.RemoveAttributeValues(ObjectClass.ACCOUNT, addO.Uid, ConnectorAttributeUtil.FilterUid(deleteAttrs), null);
            obj      = facade.GetObject(ObjectClass.ACCOUNT, uid, null);
            expected = ConnectorAttributeBuilder.Build(ATTR_NAME, ADDED);
            actual   = obj.GetAttributeByName(ATTR_NAME);
            Assert.AreEqual(expected, actual);
            // attempt to delete an attribute that doesn't exist..
            ICollection <ConnectorAttribute> nonExist = new HashSet <ConnectorAttribute>();

            nonExist.Add(NewUid(1));
            nonExist.Add(ConnectorAttributeBuilder.Build("does not exist", "asdfe"));
            uid = facade.RemoveAttributeValues(ObjectClass.ACCOUNT, addO.Uid, ConnectorAttributeUtil.FilterUid(nonExist), null);
            obj = facade.GetObject(ObjectClass.ACCOUNT, NewUid(1), null);
            Assert.IsTrue(obj.GetAttributeByName("does not exist") == null);
        }