1 6 package org.jzonic.jlo; 7 8 import junit.framework.Test; 9 import junit.framework.TestCase; 10 import junit.framework.TestSuite; 11 17 public class VariableManagerTest extends TestCase { 18 19 20 public VariableManagerTest(String name) { 21 super(name); 22 } 23 28 public static void main(String [] 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 line = "please ${replace}"; 54 String 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 line = "please ${replace} ${replace} ${replace}"; 62 String 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 line = "please ${replacer}"; 70 String ret = vm.replaceVariables(line,"replace2"); 71 assertEquals("please ${replacer}",ret); 72 } 73 74 public void testReplaceNECVariable() { 75 VariableManager vm = VariableManager.getInstance(); 76 String line = "please ${replacer}"; 77 String ret = vm.replaceVariables(line,null); 78 assertEquals("please ${replacer}",ret); 79 } 80 81 public void testReplaceEnvVariable() { 85 VariableManager vm = VariableManager.getInstance(); 86 String line = "please ${env:NUMBER_OF_PROCESSORS}"; 87 String ret = vm.replaceEnvVar(line); 88 assertEquals("please 1",ret); 89 } 90 91 public void testReplaceNEEnvVariable() { 92 VariableManager vm = VariableManager.getInstance(); 93 String line = "please ${env:HELLO_WORLD}"; 94 String ret = vm.replaceEnvVar(line); 95 assertEquals("please ${env:HELLO_WORLD}",ret); 96 } 97 98 public void _testReplaceSeveralEnvVariable() { 99 VariableManager vm = VariableManager.getInstance(); 100 String line = "please ${env:NUMBER_OF_PROCESSORS} - ${env:NUMBER_OF_PROCESSORS} - ${env:NUMBER_OF_PROCESSORS} - ${env:NUMBER_OF_PROCESSORS}"; 101 String ret = vm.replaceEnvVar(line); 102 assertEquals("please 1 - 1 - 1 - 1",ret); 103 } 104 105 public void _testReplaceSystemVariable() { 106 VariableManager vm = VariableManager.getInstance(); 107 String line = "please ${system:java.io.tmpdir}"; 109 String ret = vm.replaceVariables(line,"anyway"); 110 assertEquals("please C:\\DOCUME~1\\ADMINI~1\\LOCALS~1\\Temp\\",ret); 111 } 112 113 } 114 | Popular Tags |