public void TestScriptOnConnector()
        {
            var builder = new ScriptContextBuilder();

            builder.ScriptLanguage = "POWERShell";
            builder.ScriptText     = "Write-Warning \"Test\"; return $Connector.Arguments.uid.GetUidValue()";
            var uid = new Uid("foo", "12345");

            builder.AddScriptArgument("uid", uid);
            var res = GetFacade().RunScriptOnConnector(builder.Build(), null) as Collection <object>;

            if (res != null)
            {
                Assert.AreEqual(res[0], uid.GetUidValue());
            }
        }
        public void TestScriptContext()
        {
            ScriptContextBuilder builder = new ScriptContextBuilder();

            builder.ScriptLanguage = ("language");
            builder.ScriptText     = ("text");
            builder.AddScriptArgument("foo", "bar");
            builder.AddScriptArgument("foo2", "bar2");
            ScriptContext v1 = builder.Build();
            ScriptContext v2 = (ScriptContext)CloneObject(v1);

            Assert.AreEqual(2, v2.ScriptArguments.Count);
            Assert.AreEqual("bar", v2.ScriptArguments["foo"]);
            Assert.AreEqual("bar2", v2.ScriptArguments["foo2"]);
            Assert.AreEqual("language", v2.ScriptLanguage);
            Assert.AreEqual("text", v2.ScriptText);
        }
        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);
            }
        }