public ConnectorFacade CreateConnectorFacade(SafeType <Connector> clazz) { if (null == _facade) { PropertyBag propertyBag = TestHelpers.GetProperties(clazz.RawType); string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string testModulePath = Path.GetFullPath(Path.Combine(assemblyFolder, "..\\..\\..\\Samples\\Tests\\TestModule.psm1")); string objectChacheModulePath = typeof(ObjectCacheLibrary).Assembly.Location; var importModules = new string[] { testModulePath, objectChacheModulePath }; APIConfiguration impl = TestHelpers.CreateTestConfiguration(clazz, propertyBag, "configuration"); impl.ConfigurationProperties.SetPropertyValue("PsModulesToImport", importModules); // impl.ProducerBufferSize = 0; impl.ResultsHandlerConfiguration.EnableAttributesToGetSearchResultsHandler = false; impl.ResultsHandlerConfiguration.EnableCaseInsensitiveFilter = false; impl.ResultsHandlerConfiguration.EnableFilteredResultsHandler = false; impl.ResultsHandlerConfiguration.EnableNormalizingResultsHandler = false; //We timeout after 10s impl.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(CreateApiOp)), 10000); impl.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(UpdateApiOp)), 10000); impl.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(DeleteApiOp)), 10000); _facade = ConnectorFacadeFactory.GetInstance().NewInstance(impl); } return(_facade); }
public void TestClassLoading() { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info1 = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector"); Assert.IsNotNull(info1); ConnectorInfo info2 = FindConnectorInfo(manager, "2.0.0.0", "org.identityconnectors.testconnector.TstConnector"); Assert.IsNotNull(info2); ConnectorFacade facade1 = ConnectorFacadeFactory.GetInstance().NewInstance(info1.CreateDefaultAPIConfiguration()); ConnectorFacade facade2 = ConnectorFacadeFactory.GetInstance().NewInstance(info2.CreateDefaultAPIConfiguration()); ICollection <ConnectorAttribute> attrs = new HashSet <ConnectorAttribute>(); Assert.AreEqual("1.0", facade1.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue()); Assert.AreEqual("2.0", facade2.Create(ObjectClass.ACCOUNT, attrs, null).GetUidValue()); }
public void Cleanup() { if (null != _facade) { ((LocalConnectorFacadeImpl)_facade).Dispose(); _facade = null; } }
public void TestTimeout() { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info1 = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector"); Assert.IsNotNull(info1); APIConfiguration config = info1.CreateDefaultAPIConfiguration(); config.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(CreateApiOp)), 5000); config.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(SearchApiOp)), 5000); ConfigurationProperties props = config.ConfigurationProperties; ConfigurationProperty property = props.GetProperty("numResults"); // 1000 is several times the remote size between pauses property.Value = 2; OperationOptionsBuilder opBuilder = new OperationOptionsBuilder(); opBuilder.SetOption("delay", 10000); ConnectorFacade facade1 = ConnectorFacadeFactory.GetInstance().NewInstance(config); ICollection <ConnectorAttribute> attrs = CollectionUtil.NewReadOnlySet <ConnectorAttribute>(); try { facade1.Create(ObjectClass.ACCOUNT, attrs, opBuilder.Build()).GetUidValue(); Assert.Fail("expected timeout"); } catch (OperationTimeoutException) { // expected } //catch (RemoteWrappedException e) //{ // Assert.IsTrue(e.Is(typeof(OperationTimeoutException))); //} try { facade1.Search(ObjectClass.ACCOUNT, null, new ResultsHandler() { Handle = obj => { return(true); } }, opBuilder.Build()); Assert.Fail("expected timeout"); } catch (OperationTimeoutException) { // expected } //catch (RemoteWrappedException e) //{ // Assert.IsTrue(e.Is(typeof(OperationTimeoutException))); //} }
public virtual void TestFacadeEviction() { ConnectorServer server = ConnectorServer.NewInstance(); try { GuardedString str = new GuardedString(); str.AppendChar('c'); str.AppendChar('h'); str.AppendChar('a'); str.AppendChar('n'); str.AppendChar('g'); str.AppendChar('e'); str.AppendChar('i'); str.AppendChar('t'); #if DEBUG const int PORT = 58760; #else const int PORT = 58761; #endif server.MaxFacadeLifeTime = 1; server.Port = PORT; server.IfAddress = (IOUtil.GetIPAddress("127.0.0.1")); server.KeyHash = str.GetBase64SHA1Hash(); server.Start(); RemoteFrameworkConnectionInfo connInfo = new RemoteFrameworkConnectionInfo("127.0.0.1", PORT, str, false, null, 0); ConnectorInfoManager remoteManager = ConnectorInfoManagerFactory.GetInstance().GetRemoteManager(connInfo); ConnectorInfo remoteInfo = FindConnectorInfo(remoteManager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector"); ConnectorFacade remoteFacade = ConnectorFacadeFactory.GetInstance(). NewInstance(remoteInfo.CreateDefaultAPIConfiguration()); ManagedConnectorFacadeFactoryImpl managedFactory = (ManagedConnectorFacadeFactoryImpl)ConnectorFacadeFactory.GetManagedInstance(); // Assert it's empty Assert.IsNull(managedFactory.Find(remoteFacade.ConnectorFacadeKey)); remoteFacade.Schema(); // Assert it has one item Assert.IsNotNull(managedFactory.Find(remoteFacade.ConnectorFacadeKey)); Thread.Sleep(new TimeSpan(0, 2, 0)); // Assert it's empty Assert.IsNull(managedFactory.Find(remoteFacade.ConnectorFacadeKey)); } finally { server.Stop(); } }
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 TestAPIConfiguration() { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector"); Assert.IsNotNull(info); APIConfiguration api = info.CreateDefaultAPIConfiguration(); ConfigurationProperties props = api.ConfigurationProperties; ConfigurationProperty property = props.GetProperty("tstField"); Assert.IsNotNull(property); ICollection <SafeType <APIOperation> > operations = property.Operations; Assert.AreEqual(1, operations.Count); Assert.IsTrue(operations.Contains(SafeType <APIOperation> .Get <SyncApiOp>())); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en"); Assert.AreEqual("Help for test field.", property.GetHelpMessage(null)); Assert.AreEqual("Display for test field.", property.GetDisplayName(null)); Assert.AreEqual("Group for test field.", property.GetGroup(null)); Assert.AreEqual("Test Framework Value", info.Messages.Format("TEST_FRAMEWORK_KEY", "empty")); CultureInfo eslocale = new CultureInfo("es"); Thread.CurrentThread.CurrentUICulture = eslocale; Assert.AreEqual("tstField.help_es", property.GetHelpMessage(null)); Assert.AreEqual("tstField.display_es", property.GetDisplayName(null)); CultureInfo esESlocale = new CultureInfo("es-ES"); Thread.CurrentThread.CurrentUICulture = esESlocale; Assert.AreEqual("tstField.help_es-ES", property.GetHelpMessage(null)); Assert.AreEqual("tstField.display_es-ES", property.GetDisplayName(null)); CultureInfo esARlocale = new CultureInfo("es-AR"); Thread.CurrentThread.CurrentUICulture = esARlocale; Assert.AreEqual("tstField.help_es", property.GetHelpMessage(null)); Assert.AreEqual("tstField.display_es", property.GetDisplayName(null)); ConnectorFacadeFactory facf = ConnectorFacadeFactory.GetInstance(); ConnectorFacade facade = facf.NewInstance(api); // call the various create/update/delete commands.. facade.Schema(); }
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 TestStackTraceOfExceptionThrownByConnectorFacade() { ConnectorFacadeFactory factory = ConnectorFacadeFactory.GetInstance(); Configuration config = new MockConfiguration(); ConnectorFacade facade = factory.NewInstance( TestHelpers.CreateTestConfiguration(SafeType <Connector> .Get <SpyConnector>(), config)); try { facade.Test(); Assert.Fail("Exception was not thrown"); } catch (EUTestException eutex) { ExceptionUtilTestHelpers.AssertStackTrace(eutex, SpyConnector.StackTrace); } }
public virtual void TestSearch2() { ConnectorFacade search = GetFacade(); for (int i = 0; i < 100; i++) { ICollection <ConnectorAttribute> co = GetTestCreateConnectorObject(string.Format("TEST{0:D5}", i)); co.Add(ConnectorAttributeBuilder.Build("sortKey", i)); search.Create(ObjectClass.ACCOUNT, co, null); } OperationOptionsBuilder builder = new OperationOptionsBuilder { PageSize = 10, SortKeys = new[] { new SortKey("sortKey", false) } }; SearchResult result = null; ICollection <ConnectorObject> resultSet = new HashSet <ConnectorObject>(); int pageIndex = 0; int index = 101; while ((result = search.Search(ObjectClass.ACCOUNT, FilterBuilder.StartsWith(ConnectorAttributeBuilder.Build(Name.NAME, "TEST")), new ResultsHandler() { Handle = connectorObject => { int?idx = ConnectorAttributeUtil.GetIntegerValue(connectorObject.GetAttributeByName("sortKey")); Assert.IsTrue(idx < index); if (idx != null) { index = (int)idx; } resultSet.Add(connectorObject); return(true); } }, builder.Build())).PagedResultsCookie != null) { builder = new OperationOptionsBuilder(builder.Build()) { PagedResultsCookie = result.PagedResultsCookie }; Assert.AreEqual(10 * ++pageIndex, resultSet.Count); } Assert.AreEqual(9, pageIndex); Assert.AreEqual(100, resultSet.Count); }
public void TestValidate() { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector"); Assert.IsNotNull(info); APIConfiguration api = info.CreateDefaultAPIConfiguration(); ConfigurationProperties props = api.ConfigurationProperties; ConfigurationProperty property = props.GetProperty("failValidation"); property.Value = false; ConnectorFacadeFactory facf = ConnectorFacadeFactory.GetInstance(); ConnectorFacade facade = facf.NewInstance(api); facade.Validate(); property.Value = true; facade = facf.NewInstance(api); try { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en"); facade.Validate(); Assert.Fail("exception expected"); } catch (ConnectorException e) { Assert.AreEqual("validation failed en", e.Message); } try { Thread.CurrentThread.CurrentUICulture = new CultureInfo("es"); facade.Validate(); Assert.Fail("exception expected"); } catch (ConnectorException e) { Assert.AreEqual("validation failed es", e.Message); } }
private APIOperation GetAPIOperation(OperationRequest request) { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info = manager.FindConnectorInfo( request.ConnectorKey); if (info == null) { throw new Exception("No such connector: " + request.ConnectorKey); } String connectorFacadeKey = request.ConnectorFacadeKey; ConnectorFacade facade = ConnectorFacadeFactory.GetManagedInstance().NewInstance(info, connectorFacadeKey); return(facade.GetOperation(request.Operation)); }
public override ConnectorFacade NewInstance(APIConfiguration config) { ConnectorFacade ret = null; APIConfigurationImpl impl = (APIConfigurationImpl)config; AbstractConnectorInfo connectorInfo = impl.ConnectorInfo; if (connectorInfo is LocalConnectorInfoImpl) { LocalConnectorInfoImpl localInfo = (LocalConnectorInfoImpl)connectorInfo; // create a new Provisioner.. ret = new LocalConnectorFacadeImpl(localInfo, impl); } else { ret = new RemoteConnectorFacadeImpl(impl); } return(ret); }
private APIOperation GetAPIOperation(OperationRequest request) { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info = manager.FindConnectorInfo( request.ConnectorKey); if (info == null) { throw new Exception("No such connector: " + request.ConnectorKey); } APIConfigurationImpl config = request.Configuration; //re-wire the configuration with its connector info config.ConnectorInfo = (AbstractConnectorInfo)info; ConnectorFacade facade = ConnectorFacadeFactory.GetInstance().NewInstance(config); return(facade.GetOperation(request.Operation)); }
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 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); }
public void TestSearchWithManyResults() { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector"); Assert.IsNotNull(info); APIConfiguration api = info.CreateDefaultAPIConfiguration(); api.ProducerBufferSize = 0; ConfigurationProperties props = api.ConfigurationProperties; ConfigurationProperty property = props.GetProperty("numResults"); //1000 is several times the remote size between pauses property.Value = 1000; ConnectorFacadeFactory facf = ConnectorFacadeFactory.GetInstance(); ConnectorFacade facade = facf.NewInstance(api); IList <ConnectorObject> results = new List <ConnectorObject>(); SearchResult searchResult = facade.Search(ObjectClass.ACCOUNT, null, new ResultsHandler() { Handle = obj => { results.Add(obj); return(true); } }, null); Assert.AreEqual(1000, results.Count); Assert.AreEqual(0, searchResult.RemainingPagedResults); for (int i = 0; i < results.Count; i++) { ConnectorObject obj = results[i]; Assert.AreEqual(i.ToString(), obj.Uid.GetUidValue()); } results.Clear(); searchResult = facade.Search(ObjectClass.ACCOUNT, null, new ResultsHandler() { Handle = obj => { if (results.Count < 500) { results.Add(obj); return(true); } else { return(false); } } }, null); Assert.AreEqual(500, results.Count); Assert.IsTrue(500 == searchResult.RemainingPagedResults || 401 == searchResult.RemainingPagedResults); for (int i = 0; i < results.Count; i++) { ConnectorObject obj = results[i]; Assert.AreEqual(i.ToString(), obj.Uid.GetUidValue()); } }
public void TestSyncWithManyResults() { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector"); Assert.IsNotNull(info); APIConfiguration api = info.CreateDefaultAPIConfiguration(); ConfigurationProperties props = api.ConfigurationProperties; ConfigurationProperty property = props.GetProperty("numResults"); //1000 is several times the remote size between pauses property.Value = (1000); ConnectorFacadeFactory facf = ConnectorFacadeFactory.GetInstance(); ConnectorFacade facade = facf.NewInstance(api); SyncToken latest = facade.GetLatestSyncToken(ObjectClass.ACCOUNT); Assert.AreEqual("mylatest", latest.Value); IList <SyncDelta> results = new List <SyncDelta>(); facade.Sync(ObjectClass.ACCOUNT, null, new SyncResultsHandler() { Handle = obj => { results.Add(obj); return(true); } }, null); Assert.AreEqual(1000, results.Count); for (int i = 0; i < results.Count; i++) { SyncDelta obj = results[i]; Assert.AreEqual(i.ToString(), obj.Uid.GetUidValue()); } results.Clear(); facade.Sync(ObjectClass.ACCOUNT, null, new SyncResultsHandler() { Handle = obj => { if (results.Count < 500) { results.Add(obj); return(true); } else { return(false); } } } , null); Assert.AreEqual(500, results.Count); for (int i = 0; i < results.Count; i++) { SyncDelta obj = results[i]; Assert.AreEqual(i.ToString(), obj.Uid.GetUidValue()); } }
public void TestScripting() { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector"); Assert.IsNotNull(info); APIConfiguration api = info.CreateDefaultAPIConfiguration(); ConnectorFacadeFactory facf = ConnectorFacadeFactory.GetInstance(); ConnectorFacade facade = facf.NewInstance(api); ScriptContextBuilder builder = new ScriptContextBuilder(); builder.AddScriptArgument("arg1", "value1"); builder.AddScriptArgument("arg2", "value2"); builder.ScriptLanguage = ("BOO"); //test that they can run the script and access the //connector object { String SCRIPT = "connector.concat(arg1,arg2)"; builder.ScriptText = (SCRIPT); String result = (String)facade.RunScriptOnConnector(builder.Build(), null); Assert.AreEqual("value1value2", result); } //test that they can access a class in the class loader { String SCRIPT = "import org.identityconnectors.testconnector\n" + "TstConnector.GetVersion()"; builder.ScriptText = (SCRIPT); String result = (String)facade.RunScriptOnConnector(builder.Build(), null); Assert.AreEqual("1.0", result); } //test that they cannot access a class in internal { Type clazz = typeof(ConfigurationPropertyImpl); String SCRIPT = "import " + clazz.Namespace + "\n" + clazz.Name + "()"; builder.ScriptText = (SCRIPT); try { facade.RunScriptOnConnector(builder.Build(), null); Assert.Fail("exception expected"); } catch (Exception e) { String msg = e.Message; String expectedMessage = "Namespace '" + clazz.Namespace + "' not found"; Assert.IsTrue( msg.Contains(expectedMessage), "Unexpected message: " + msg); } } // test that they can access a class in common { Type clazz = typeof(ConnectorAttributeBuilder); String SCRIPT = "import " + clazz.Namespace + "\n" + clazz.Name + ".Build(\"myattr\")"; builder.ScriptText = (SCRIPT); ConnectorAttribute attr = (ConnectorAttribute)facade.RunScriptOnConnector(builder.Build(), null); Assert.AreEqual("myattr", attr.Name); } }
public ConnectorFacade CreateConnectorFacade(SafeType<Connector> clazz) { if (null == _facade) { PropertyBag propertyBag = TestHelpers.GetProperties(clazz.RawType); string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string testModulePath = Path.GetFullPath(Path.Combine(assemblyFolder, "..\\..\\..\\Samples\\Tests\\TestModule.psm1")); string objectChacheModulePath = typeof(ObjectCacheLibrary).Assembly.Location; var importModules = new string[] { testModulePath, objectChacheModulePath }; APIConfiguration impl = TestHelpers.CreateTestConfiguration(clazz, propertyBag, "configuration"); impl.ConfigurationProperties.SetPropertyValue("PsModulesToImport", importModules); // impl.ProducerBufferSize = 0; impl.ResultsHandlerConfiguration.EnableAttributesToGetSearchResultsHandler = false; impl.ResultsHandlerConfiguration.EnableCaseInsensitiveFilter = false; impl.ResultsHandlerConfiguration.EnableFilteredResultsHandler = false; impl.ResultsHandlerConfiguration.EnableNormalizingResultsHandler = false; //We timeout after 10s impl.SetTimeout(SafeType<APIOperation>.ForRawType(typeof(CreateApiOp)), 10000); impl.SetTimeout(SafeType<APIOperation>.ForRawType(typeof(UpdateApiOp)), 10000); impl.SetTimeout(SafeType<APIOperation>.ForRawType(typeof(DeleteApiOp)), 10000); _facade = ConnectorFacadeFactory.GetInstance().NewInstance(impl); } return _facade; }
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); }