Esempio n. 1
0
        public void Test_ExtendedProperties()
        {
            FileInfo     file = new FileInfo("test1.properties");
            StreamWriter sw   = file.CreateText();

            sw.WriteLine("# lines starting with # are comments.  Blank lines are ignored");
            sw.WriteLine(string.Empty);
            sw.WriteLine("# This is the simplest property");
            sw.WriteLine("prefix.key = value");
            sw.WriteLine(string.Empty);
            sw.WriteLine("# A long property may be separated on multiple lines");
            sw.WriteLine("prefix.longvalue = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \\");
            sw.WriteLine("                   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            sw.WriteLine(string.Empty);
            sw.WriteLine("# This is a property with many tokens");
            sw.WriteLine("prefix.tokens_on_a_line = first token, second token");
            sw.WriteLine(string.Empty);
            sw.WriteLine("# This sequence generates exactly the same result");
            sw.WriteLine("prefix.tokens_on_multiple_lines = first token");
            sw.WriteLine("prefix.tokens_on_multiple_lines = second token");
            sw.WriteLine(string.Empty);
            sw.WriteLine("# commas may be escaped in tokens");
            sw.WriteLine("prefix.commas.excaped = Hi\\, what'up?");
            sw.Flush();
            sw.Close();

            StreamReader sr = file.OpenText();
            String       s  = sr.ReadToEnd();

            sr.Close();

            ExtendedProperties props = new ExtendedProperties(file.FullName);

            VerifyProperties(props, "prefix.");

            StringWriter writer = new StringWriter();

            props.Save(writer, "header");

            // make sure that combine does not change types
            ExtendedProperties p = new ExtendedProperties();

            p.Combine(props);
            VerifyProperties(p, "prefix.");

            // make sure that subset does not change property types
            ExtendedProperties p2 = p.Subset("prefix");

            VerifyProperties(p2, string.Empty);
        }
Esempio n. 2
0
        public void Test_ExtendedProperties()
        {
            FileInfo file = new FileInfo("test1.properties");
            StreamWriter sw = file.CreateText();
            sw.WriteLine("# lines starting with # are comments.  Blank lines are ignored");
            sw.WriteLine(string.Empty);
            sw.WriteLine("# This is the simplest property");
            sw.WriteLine("prefix.key = value");
            sw.WriteLine(string.Empty);
            sw.WriteLine("# A long property may be separated on multiple lines");
            sw.WriteLine("prefix.longvalue = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \\");
            sw.WriteLine("                   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            sw.WriteLine(string.Empty);
            sw.WriteLine("# This is a property with many tokens");
            sw.WriteLine("prefix.tokens_on_a_line = first token, second token");
            sw.WriteLine(string.Empty);
            sw.WriteLine("# This sequence generates exactly the same result");
            sw.WriteLine("prefix.tokens_on_multiple_lines = first token");
            sw.WriteLine("prefix.tokens_on_multiple_lines = second token");
            sw.WriteLine(string.Empty);
            sw.WriteLine("# commas may be escaped in tokens");
            sw.WriteLine("prefix.commas.excaped = Hi\\, what'up?");
            sw.Flush();
            sw.Close();

            StreamReader sr = file.OpenText();
            String s = sr.ReadToEnd();
            sr.Close();

            ExtendedProperties props = new ExtendedProperties(file.FullName);
            VerifyProperties(props, "prefix.");

            StringWriter writer = new StringWriter();
            props.Save(writer, "header");

            // make sure that combine does not change types
            ExtendedProperties p = new ExtendedProperties();
            p.Combine(props);
            VerifyProperties(p, "prefix.");

            // make sure that subset does not change property types
            ExtendedProperties p2 = p.Subset("prefix");
            VerifyProperties(p2, string.Empty);
        }
Esempio n. 3
0
        public virtual void  Test_run()
        {
            System.IO.StreamWriter result = null;
            ExtendedProperties     c      = null;

            try {
                assureResultsDirectoryExists(RESULTS_DIR);
                c      = new ExtendedProperties(TEST_CONFIG);
                result = new System.IO.StreamWriter(getFileName(RESULTS_DIR, "output", "res"));
            } catch (System.Exception e) {
                throw new System.Exception("Cannot setup CommonsExtPropTestCase!", e);
            }

            message(result, "Testing order of keys ...");
            showIterator(result, c.Keys);

            message(result, "Testing retrieval of CSV values ...");
            showVector(result, c.GetVector("resource.loader"));

            message(result, "Testing subset(prefix).getKeys() ...");
            ExtendedProperties subset = c.Subset("file.resource.loader");

            showIterator(result, subset.Keys);

            message(result, "Testing getVector(prefix) ...");
            showVector(result, subset.GetVector("path"));

            message(result, "Testing getString(key) ...");
            result.Write(c.GetString("config.string.value"));
            result.Write("\n\n");

            message(result, "Testing getBoolean(key) ...");
            //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Boolean.toString' may return a different value. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1043"'
            result.Write(c.GetBoolean("config.boolean.value").ToString());
            result.Write("\n\n");

            message(result, "Testing getByte(key) ...");
            result.Write(c.GetByte("config.byte.value").ToString());
            result.Write("\n\n");

            message(result, "Testing getShort(key) ...");
            result.Write(c.GetShort("config.short.value").ToString());
            result.Write("\n\n");

            message(result, "Testing getInt(key) ...");
            result.Write(c.GetInt("config.int.value").ToString());
            result.Write("\n\n");

            message(result, "Testing getLong(key) ...");
            result.Write(c.GetLong("config.long.value").ToString());
            result.Write("\n\n");

            message(result, "Testing getFloat(key) ...");
            result.Write(c.GetFloat("config.float.value").ToString());
            result.Write("\n\n");

            message(result, "Testing getDouble(key) ...");
            result.Write(c.GetDouble("config.double.value").ToString());
            result.Write("\n\n");

            message(result, "Testing escaped-comma scalar...");
            result.Write(c.GetString("escape.comma1"));
            result.Write("\n\n");

            message(result, "Testing escaped-comma vector...");
            showVector(result, c.GetVector("escape.comma2"));
            result.Write("\n\n");

            result.Flush();
            result.Close();

            if (!isMatch(RESULTS_DIR, COMPARE_DIR, "output", "res", "cmp"))
            {
                Assertion.Fail("Output incorrect.");
            }
        }