KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jzonic > jlo > VariableManagerTest


1 /*
2  * ConfigurationTest.java
3  *
4  * Created on 19. November 2002, 22:37
5  */

6 package org.jzonic.jlo;
7
8 import junit.framework.Test;
9 import junit.framework.TestCase;
10 import junit.framework.TestSuite;
11 /**
12  * test cases for the for the VariableManager
13  *
14  * @author Andreas Mecky <andreas.mecky@xcom.de>
15  * @author Terry Dye <terry.dye@xcom.de>
16  */

17 public class VariableManagerTest extends TestCase {
18     
19     
20     public VariableManagerTest(String JavaDoc name) {
21         super(name);
22     }
23     /**
24      * The main program for the ConfigurationTest class
25      *
26      *@param args The command line arguments
27      */

28     public static void main(String JavaDoc[] args) {
29         junit.textui.TestRunner.run(VariableManagerTest.class);
30     }
31
32     public static Test suite() {
33         TestSuite suite = new TestSuite(VariableManagerTest.class);
34         return suite;
35     }
36     
37     protected void setUp() {
38     }
39     
40     protected void tearDown() {
41     }
42     
43     public void testAddVars() {
44         VariableManager vm = VariableManager.getInstance();
45         vm.addVariable("test1", "hello", "test");
46         vm.addVariable("test2","world","test");
47         assertEquals(2,vm.getVariableCount("test"));
48     }
49     
50     public void testReplaceVariable() {
51         VariableManager vm = VariableManager.getInstance();
52         vm.addVariable("replace","me", "replace1");
53         String JavaDoc line = "please ${replace}";
54         String JavaDoc ret = vm.replaceVariables(line,"replace1");
55         assertEquals("please me",ret);
56     }
57     
58     public void testReplaceSeveralVariable() {
59         VariableManager vm = VariableManager.getInstance();
60         vm.addVariable("replace","me", "replace2");
61         String JavaDoc line = "please ${replace} ${replace} ${replace}";
62         String JavaDoc ret = vm.replaceVariables(line,"replace2");
63         assertEquals("please me me me",ret);
64     }
65     
66     public void testReplaceNEVariable() {
67         VariableManager vm = VariableManager.getInstance();
68         vm.addVariable("replace","me", "replace2");
69         String JavaDoc line = "please ${replacer}";
70         String JavaDoc ret = vm.replaceVariables(line,"replace2");
71         assertEquals("please ${replacer}",ret);
72     }
73     
74     public void testReplaceNECVariable() {
75         VariableManager vm = VariableManager.getInstance();
76         String JavaDoc line = "please ${replacer}";
77         String JavaDoc ret = vm.replaceVariables(line,null);
78         assertEquals("please ${replacer}",ret);
79     }
80     
81     //
82
// This section covers the env-variables
83
//
84
public void testReplaceEnvVariable() {
85         VariableManager vm = VariableManager.getInstance();
86         String JavaDoc line = "please ${env:NUMBER_OF_PROCESSORS}";
87         String JavaDoc ret = vm.replaceEnvVar(line);
88         assertEquals("please 1",ret);
89     }
90     
91     public void testReplaceNEEnvVariable() {
92         VariableManager vm = VariableManager.getInstance();
93         String JavaDoc line = "please ${env:HELLO_WORLD}";
94         String JavaDoc ret = vm.replaceEnvVar(line);
95         assertEquals("please ${env:HELLO_WORLD}",ret);
96     }
97     
98     public void _testReplaceSeveralEnvVariable() {
99         VariableManager vm = VariableManager.getInstance();
100         String JavaDoc line = "please ${env:NUMBER_OF_PROCESSORS} - ${env:NUMBER_OF_PROCESSORS} - ${env:NUMBER_OF_PROCESSORS} - ${env:NUMBER_OF_PROCESSORS}";
101         String JavaDoc ret = vm.replaceEnvVar(line);
102         assertEquals("please 1 - 1 - 1 - 1",ret);
103     }
104     
105     public void _testReplaceSystemVariable() {
106         VariableManager vm = VariableManager.getInstance();
107         // TODO: find a better property that is the same on every machine
108
String JavaDoc line = "please ${system:java.io.tmpdir}";
109         String JavaDoc ret = vm.replaceVariables(line,"anyway");
110         assertEquals("please C:\\DOCUME~1\\ADMINI~1\\LOCALS~1\\Temp\\",ret);
111     }
112
113 }
114
Popular Tags