public void TestConnectionPooling()
        {
            ConnectorPoolManager.Dispose();
            ConnectorInfoManager manager =
                GetConnectorInfoManager();
            ConnectorInfo info1 =
                FindConnectorInfo(manager,
                                  "1.0.0.0",
                                  "org.identityconnectors.testconnector.TstConnector");

            Assert.IsNotNull(info1);
            //reset connection count
            {
                //trigger TstConnection.init to be called
                APIConfiguration config2 =
                    info1.CreateDefaultAPIConfiguration();
                config2.ConfigurationProperties.GetProperty("resetConnectionCount").Value = (true);
                ConnectorFacade facade2 =
                    ConnectorFacadeFactory.GetInstance().NewInstance(config2);
                facade2.Schema(); //force instantiation
            }

            APIConfiguration config =
                info1.CreateDefaultAPIConfiguration();

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

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

            OperationOptionsBuilder builder = new OperationOptionsBuilder();

            builder.SetOption("testPooling", "true");
            OperationOptions options = builder.Build();
            ICollection <ConnectorAttribute> attrs = CollectionUtil.NewReadOnlySet <ConnectorAttribute>();

            Assert.AreEqual("1", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            Assert.AreEqual("2", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            Assert.AreEqual("3", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            Assert.AreEqual("4", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            config =
                info1.CreateDefaultAPIConfiguration();
            config.ConnectorPoolConfiguration.MinIdle = (1);
            config.ConnectorPoolConfiguration.MaxIdle = (2);
            facade1 =
                ConnectorFacadeFactory.GetInstance().NewInstance(config);
            Assert.AreEqual("5", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            Assert.AreEqual("5", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            Assert.AreEqual("5", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            Assert.AreEqual("5", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
        }
        public void TestConnectorContext()
        {
            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 facade1 = ConnectorFacadeFactory.GetInstance().NewInstance(config);

            ICollection <ConnectorAttribute> attrs = CollectionUtil.NewReadOnlySet <ConnectorAttribute>();
            string uid = facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue();

            Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid);
            Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid);
            Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid);
            Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid);
            Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid);
            Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid);

            config = info1.CreateDefaultAPIConfiguration();
            config.ConnectorPoolConfiguration.MinIdle = 1;
            config.ConnectorPoolConfiguration.MaxIdle = 2;
            facade1 = ConnectorFacadeFactory.GetInstance().NewInstance(config);
            uid     = facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue();
            Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid);
            Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid);
            Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid);
            Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid);
            Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), uid);
            Assert.AreEqual(facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue(), 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);
        }
        public void TestPagedSearch()
        {
            ConnectorPoolManager.Dispose();
            ConnectorInfoManager manager = GetConnectorInfoManager();
            ConnectorInfo        info1   = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstStatefulPoolableConnector");

            Assert.IsNotNull(info1);

            APIConfiguration config = info1.CreateDefaultAPIConfiguration();

            config.ProducerBufferSize = 0;

            config.ConnectorPoolConfiguration.MinIdle = 1;
            config.ConnectorPoolConfiguration.MaxIdle = 2;
            config.ResultsHandlerConfiguration.FilteredResultsHandlerInValidationMode = true;           // for paged searches, the filtered results handler should be either disabled or put into validation mode

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

            OperationOptionsBuilder builder = new OperationOptionsBuilder();

            builder.PageSize = 10;
            builder.SetSortKeys(new ICF.SortKey(Name.NAME, true));

            SearchResult searchResult = null;
            ISet <Uid>   UIDs         = new HashSet <Uid>();

            int iteration = 0;

            do
            {
                if (null != searchResult)
                {
                    builder.PagedResultsCookie = searchResult.PagedResultsCookie;
                }

                int size = 0;
                searchResult = facade1.Search(ObjectClass.ACCOUNT, null, new ResultsHandler()
                {
                    Handle = obj =>
                    {
                        if (size >= 10)
                        {
                            Assert.Fail("More then 10 objects was handled!");
                        }
                        size++;
                        if (UIDs.Contains(obj.Uid))
                        {
                            Assert.Fail("Duplicate Entry in results");
                        }
                        return(UIDs.Add(obj.Uid));
                    }
                }, builder.Build());
                iteration++;
                Assert.IsNotNull(searchResult);
                Assert.AreEqual(searchResult.RemainingPagedResults, 100 - (iteration * 10));
            } while (searchResult.PagedResultsCookie != null);

            // Search with paged results offset

            builder                    = new OperationOptionsBuilder();
            builder.PageSize           = 10;
            builder.PagedResultsOffset = 5;
            builder.SetSortKeys(new ICF.SortKey(Name.NAME, true));

            searchResult = null;

            UIDs.Clear();
            Filter filter = FilterBuilder.EqualTo(ConnectorAttributeBuilder.BuildEnabled(true));

            iteration = 0;
            do
            {
                if (null != searchResult)
                {
                    builder.PagedResultsCookie = searchResult.PagedResultsCookie;
                }

                int size = 0;
                searchResult = facade1.Search(ObjectClass.ACCOUNT, filter, new ResultsHandler()
                {
                    Handle = obj =>
                    {
                        if (size >= 10)
                        {
                            Assert.Fail("More then 10 objects was handled!");
                        }
                        size++;
                        if (UIDs.Contains(obj.Uid))
                        {
                            Assert.Fail("Duplicate Entry in results");
                        }
                        return(UIDs.Add(obj.Uid));
                    }
                }, builder.Build());
                iteration++;
                Assert.IsNotNull(searchResult);
                Assert.AreEqual(searchResult.RemainingPagedResults, Math.Max(50 - (iteration * 15), 0));
            } while (searchResult.PagedResultsCookie != null);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Dispose of all object pools and other resources associated with this
 /// class.
 /// </summary>
 public override void Dispose()
 {
     ConnectorPoolManager.Dispose();
 }