001: /*
002: * ConfigurationTest.java
003: *
004: * Created on 19. November 2002, 22:37
005: */
006: package org.jzonic.jlo;
007:
008: import junit.framework.Test;
009: import junit.framework.TestCase;
010: import junit.framework.TestSuite;
011:
012: /**
013: * test cases for the for the VariableManager
014: *
015: * @author Andreas Mecky <andreas.mecky@xcom.de>
016: * @author Terry Dye <terry.dye@xcom.de>
017: */
018: public class VariableManagerTest extends TestCase {
019:
020: public VariableManagerTest(String name) {
021: super (name);
022: }
023:
024: /**
025: * The main program for the ConfigurationTest class
026: *
027: *@param args The command line arguments
028: */
029: public static void main(String[] args) {
030: junit.textui.TestRunner.run(VariableManagerTest.class);
031: }
032:
033: public static Test suite() {
034: TestSuite suite = new TestSuite(VariableManagerTest.class);
035: return suite;
036: }
037:
038: protected void setUp() {
039: }
040:
041: protected void tearDown() {
042: }
043:
044: public void testAddVars() {
045: VariableManager vm = VariableManager.getInstance();
046: vm.addVariable("test1", "hello", "test");
047: vm.addVariable("test2", "world", "test");
048: assertEquals(2, vm.getVariableCount("test"));
049: }
050:
051: public void testReplaceVariable() {
052: VariableManager vm = VariableManager.getInstance();
053: vm.addVariable("replace", "me", "replace1");
054: String line = "please ${replace}";
055: String ret = vm.replaceVariables(line, "replace1");
056: assertEquals("please me", ret);
057: }
058:
059: public void testReplaceSeveralVariable() {
060: VariableManager vm = VariableManager.getInstance();
061: vm.addVariable("replace", "me", "replace2");
062: String line = "please ${replace} ${replace} ${replace}";
063: String ret = vm.replaceVariables(line, "replace2");
064: assertEquals("please me me me", ret);
065: }
066:
067: public void testReplaceNEVariable() {
068: VariableManager vm = VariableManager.getInstance();
069: vm.addVariable("replace", "me", "replace2");
070: String line = "please ${replacer}";
071: String ret = vm.replaceVariables(line, "replace2");
072: assertEquals("please ${replacer}", ret);
073: }
074:
075: public void testReplaceNECVariable() {
076: VariableManager vm = VariableManager.getInstance();
077: String line = "please ${replacer}";
078: String ret = vm.replaceVariables(line, null);
079: assertEquals("please ${replacer}", ret);
080: }
081:
082: //
083: // This section covers the env-variables
084: //
085: public void testReplaceEnvVariable() {
086: VariableManager vm = VariableManager.getInstance();
087: String line = "please ${env:NUMBER_OF_PROCESSORS}";
088: String ret = vm.replaceEnvVar(line);
089: assertEquals("please 1", ret);
090: }
091:
092: public void testReplaceNEEnvVariable() {
093: VariableManager vm = VariableManager.getInstance();
094: String line = "please ${env:HELLO_WORLD}";
095: String ret = vm.replaceEnvVar(line);
096: assertEquals("please ${env:HELLO_WORLD}", ret);
097: }
098:
099: public void _testReplaceSeveralEnvVariable() {
100: VariableManager vm = VariableManager.getInstance();
101: String line = "please ${env:NUMBER_OF_PROCESSORS} - ${env:NUMBER_OF_PROCESSORS} - ${env:NUMBER_OF_PROCESSORS} - ${env:NUMBER_OF_PROCESSORS}";
102: String ret = vm.replaceEnvVar(line);
103: assertEquals("please 1 - 1 - 1 - 1", ret);
104: }
105:
106: public void _testReplaceSystemVariable() {
107: VariableManager vm = VariableManager.getInstance();
108: // TODO: find a better property that is the same on every machine
109: String line = "please ${system:java.io.tmpdir}";
110: String ret = vm.replaceVariables(line, "anyway");
111: assertEquals("please C:\\DOCUME~1\\ADMINI~1\\LOCALS~1\\Temp\\",
112: ret);
113: }
114:
115: }
|