Ejemplo n.º 1
0
        public void TestBasicTypes()
        {
            var def = new ConfigDef().Define("a", ConfigDef.Type.Int, 5, ConfigDef.Range.Between(0, 14),
                ConfigDef.Importance.High, "docs")
                .Define("b", ConfigDef.Type.Long, ConfigDef.Importance.High, "docs")
                .Define("c", ConfigDef.Type.String, "hello", ConfigDef.Importance.High, "docs")
                .Define("d", ConfigDef.Type.List, ConfigDef.Importance.High, "docs")
                .Define("e", ConfigDef.Type.Double, ConfigDef.Importance.High, "docs")
                //.Define("f", ConfigDef.Type.Class, ConfigDef.Importance.High, "docs")
                .Define("g", ConfigDef.Type.Bool, ConfigDef.Importance.High, "docs")
                .Define("h", ConfigDef.Type.Bool, ConfigDef.Importance.High, "docs")
                .Define("i", ConfigDef.Type.Bool, ConfigDef.Importance.High, "docs")
                .Define("j", ConfigDef.Type.Password, ConfigDef.Importance.High, "docs");

            var props = new Dictionary<string, object>();
            props.Add("a", "1   ");
            props.Add("b", 2);
            props.Add("d", " a , b, c");
            props.Add("e", 42.5d);
            //props.Add("f", string.class.etName());
            props.Add("g", "true");
            props.Add("h", "FalSE");
            props.Add("i", "TRUE");
            props.Add("j", "password");

            var vals = def.Parse(props);

            Assert.Equal(1, vals["a"]);
            Assert.Equal(2L, vals["b"]);
            Assert.Equal("hello", vals["c"]);
            Assert.Equal(new List<string> {"a", "b", "c"}, vals["d"]);
            Assert.Equal(42.5d, vals["e"]);
            //Assert.Equal(String.class, vals.get("f"));
            Assert.Equal(true, vals["g"]);
            Assert.Equal(false, vals["h"]);
            Assert.Equal(true, vals["i"]);
            Assert.Equal(new Password("password"), vals["j"]);
            Assert.Equal(Password.Hidden, vals["j"].ToString());
        }
Ejemplo n.º 2
0
        private void TestValidator(ConfigDef.Type type, ConfigDef.IValidator validator, object defaultVal,
            object[] okValues, object[] badValues)
        {
            var def = new ConfigDef().Define("name", type, defaultVal, validator, ConfigDef.Importance.High, "docs");

            foreach (var value in okValues) {
                var m = new Dictionary<string, object> {{"name", value}};
                def.Parse(m);
            }

            foreach (var value in badValues) {
                var m = new Dictionary<string, object> {{"name", value}};
                try {
                    def.Parse(m);
                    Assert.True(false, "Expected a config exception due to invalid value " + value);
                }
                catch (ConfigException x) {
                    //good to go
                }
            }
        }
Ejemplo n.º 3
0
        public void TestSslPasswords()
        {
            var def = new ConfigDef();
            SslConfigs.AddClientSslSupport(def);

            var props = new Dictionary<string, object> {
                {SslConfigs.SslKeyPasswordConfig, "key_password"},
                {SslConfigs.SslKeystorePasswordConfig, "keystore_password"},
                {SslConfigs.SslTruststorePasswordConfig, "truststore_password"}
            };

            var vals = def.Parse(props);

            Assert.Equal(new Password("key_password"), vals[SslConfigs.SslKeyPasswordConfig]);
            Assert.Equal(Password.Hidden, vals[SslConfigs.SslKeyPasswordConfig].ToString());
            Assert.Equal(new Password("keystore_password"), vals[SslConfigs.SslKeystorePasswordConfig]);
            Assert.Equal(Password.Hidden, vals[SslConfigs.SslKeystorePasswordConfig].ToString());
            Assert.Equal(new Password("truststore_password"), vals[SslConfigs.SslTruststorePasswordConfig]);
            Assert.Equal(Password.Hidden, vals[SslConfigs.SslTruststorePasswordConfig].ToString());
        }
Ejemplo n.º 4
0
 private void TestBadInputs(ConfigDef.Type type, IEnumerable<object> values)
 {
     foreach (var value in values) {
         var m = new Dictionary<string, object> {{"name", value}};
         var def = new ConfigDef().Define("name", type, ConfigDef.Importance.High, "docs");
         try {
             def.Parse(m);
             Assert.True(false, "Expected a config exception due to invalid value " + value);
         }
         catch (ConfigException x) {
             //good to go
         }
     }
 }
Ejemplo n.º 5
0
 public void TestNullDefault()
 {
     var def = new ConfigDef().Define("a", ConfigDef.Type.Int, null, null, ConfigDef.Importance.Medium, "docs");
     var vals = def.Parse(new Dictionary<string, object>());
     Assert.Equal(null, vals["a"]);
 }