001: package com.ecyrd.jspwiki;
002:
003: import java.util.Properties;
004:
005: import junit.framework.Test;
006: import junit.framework.TestCase;
007: import junit.framework.TestSuite;
008:
009: public class PropertyReaderTest extends TestCase {
010: public void testVariableExpansion() {
011: Properties p = new Properties();
012:
013: p.put("var.basedir", "/p/mywiki");
014:
015: p.put("jspwiki.fileSystemProvider.pageDir", "$basedir/www/");
016: p.put("jspwiki.basicAttachmentProvider.storageDir",
017: "$basedir/www/");
018: p.put("jspwiki.workDir", "$basedir/wrk/");
019: p.put("jspwiki.xyz", "test basedir"); //don't touch this
020:
021: PropertyReader.expandVars(p);
022:
023: assertTrue(p.getProperty("jspwiki.fileSystemProvider.pageDir")
024: .equals("/p/mywiki/www/"));
025: assertTrue(p.getProperty(
026: "jspwiki.basicAttachmentProvider.storageDir").equals(
027: "/p/mywiki/www/"));
028: assertTrue(p.getProperty("jspwiki.fileSystemProvider.pageDir")
029: .equals("/p/mywiki/www/"));
030: assertTrue(p.getProperty("jspwiki.workDir").endsWith(
031: "/p/mywiki/wrk/"));
032: assertTrue(p.getProperty("jspwiki.xyz")
033: .endsWith("test basedir")); //don't touch this
034:
035: System.out.println(p.getProperty("jspwiki.workDir"));
036:
037: assertFalse(p.getProperty("jspwiki.workDir").endsWith(
038: "$basedir/wrk/"));
039: }
040:
041: public void testVariableExpansion2() {
042: Properties p = new Properties();
043:
044: //this time, declare the var at the end... (should overwrite this one);
045: p.put("var.basedir", "xxx");
046:
047: p.put("jspwiki.fileSystemProvider.pageDir", "$basedir/www/");
048: p.put("jspwiki.basicAttachmentProvider.storageDir",
049: "$basedir/www/");
050: p.put("jspwiki.workDir", "$basedir/wrk/");
051: p.put("jspwiki.xyz", "test basedir"); //don't touch this
052: p.put("jspwiki.abc", "test $x2"); //don't touch this
053:
054: p.put("var.basedir", " /p/mywiki"); //note that this var has a space at the beginning...
055: p.put("var.x2", " wiki "); //note that this var has a space at the beginning...
056:
057: PropertyReader.expandVars(p);
058:
059: assertTrue(p.getProperty("jspwiki.fileSystemProvider.pageDir")
060: .equals("/p/mywiki/www/"));
061: assertTrue(p.getProperty(
062: "jspwiki.basicAttachmentProvider.storageDir").equals(
063: "/p/mywiki/www/"));
064: assertTrue(p.getProperty("jspwiki.fileSystemProvider.pageDir")
065: .equals("/p/mywiki/www/"));
066: assertTrue(p.getProperty("jspwiki.workDir").endsWith(
067: "/p/mywiki/wrk/"));
068: assertTrue(p.getProperty("jspwiki.xyz")
069: .endsWith("test basedir")); //don't touch this
070:
071: //System.out.println(p.getProperty("jspwiki.abc"));
072:
073: assertFalse(p.getProperty("jspwiki.workDir").endsWith(
074: "$basedir/wrk/"));
075: assertTrue(p.getProperty("jspwiki.abc").endsWith("test wiki"));
076: }
077:
078: public void testMultipleVariableExpansion() {
079: Properties p = new Properties();
080:
081: //this time, declare the var at the end... (should overwrite this one);
082: p.put("var.x1", "a");
083: p.put("var.x2", "b");
084:
085: p.put("jspwiki.x1", "$x1");
086: p.put("jspwiki.x2", "$x2");
087: p.put("jspwiki.x3", "$x1/$x2");
088:
089: PropertyReader.expandVars(p);
090:
091: //System.out.println(p.getProperty("jspwiki.x1"));
092: //System.out.println(p.getProperty("jspwiki.x2"));
093: //System.out.println(p.getProperty("jspwiki.x3"));
094:
095: assertTrue(p.getProperty("jspwiki.x1").equals("a"));
096: assertTrue(p.getProperty("jspwiki.x2").equals("b"));
097: assertTrue(p.getProperty("jspwiki.x3").equals("a/b"));
098: }
099:
100: public static Test suite() {
101: return new TestSuite(PropertyReaderTest.class);
102: }
103: }
|