1 23 24 package com.sun.enterprise.cli.framework; 25 26 import junit.framework.*; 27 import java.util.ResourceBundle ; 28 import java.util.Enumeration ; 29 import java.util.HashMap ; 30 import java.util.Locale ; 31 32 37 38 public class GlobalsManagerTest extends TestCase { 39 private static final String getCommandPackageName(){ 44 return "com.sun.enterprise.cli"; 45 } 46 47 public void testCommandStringLocalization() throws Exception { 48 final ICommandEnvironment env = new Env(); 49 final GlobalsManager gm = new GlobalsManager(env); 50 GlobalsManager.setInstance(gm); 51 GlobalsManager.setBasePackage(getCommandPackageName()); 52 GlobalsManager.setPropertyFile("CommandPropertyFile"); 53 assertEquals("command property", GlobalsManager.getString("a")); 54 assertEquals("command property", GlobalsManager.getString("a", (Object []) null)); 55 GlobalsManager.setBasePackage((String ) null); 56 } 57 58 public void testCommandStringLocalizationNoBundle() { 59 final ICommandEnvironment env = new Env(); 60 final GlobalsManager gm = new GlobalsManager(env); 61 GlobalsManager.setInstance(gm); 62 try { 63 assertEquals("", GlobalsManager.getString("a")); 64 fail("Expected error indicating no base package could be found"); 65 } 66 catch (CommandException ce){ 67 assertEquals("Can't find bundle for base name null.CommandPropertyFile, locale "+Locale.getDefault(), ce.getMessage()); 69 assertNull(ce.getCause()); 70 } 71 } 72 73 public void testFrameworkStringLocalization() throws Exception { 74 final ICommandEnvironment env = new Env(); 75 final GlobalsManager gm = new GlobalsManager(env); 76 GlobalsManager.setInstance(gm); 77 assertEquals("framework property", GlobalsManager.getFrameworkString("a", (Object []) null)); 78 assertEquals("framework property", GlobalsManager.getFrameworkString("a")); 79 } 80 81 82 83 public void testEnvironment(){ 84 final ICommandEnvironment env = new Env(); 85 final GlobalsManager gm = new GlobalsManager(env); 86 final ICommandEnvironment env2 = new Env(); 87 gm.setGlobalsEnv(env2); 88 assertEquals(env2, gm.getGlobalsEnv()); 89 } 90 91 public void testSingletonMethods(){ 92 final ICommandEnvironment env = new Env(); 93 final GlobalsManager gm = new GlobalsManager(env); 94 GlobalsManager.setInstance(gm); 95 assertEquals(gm, GlobalsManager.getInstance()); 96 } 97 98 public void testGetSetRemove() { 99 final ICommandEnvironment env = new Env(); 100 final GlobalsManager gm = new GlobalsManager(env); 101 gm.setOption("key", "value"); 102 assertEquals("value", gm.getOption("key")); 103 gm.removeOption("key"); 104 assertNull(gm.getOption("key")); 105 } 106 107 108 public void testSimpleConstructionAndObservers() { 109 final ICommandEnvironment env = new Env(); 110 final GlobalsManager gm = new GlobalsManager(env); 111 assertEquals(env, gm.getGlobalsEnv()); 112 } 113 114 public GlobalsManagerTest(String name){ 115 super(name); 116 } 117 118 protected void setUp() { 119 } 120 121 protected void tearDown() { 122 } 123 124 private void nyi(){ 125 fail("Not Yet Implemented"); 126 } 127 128 public static void main(String args[]){ 129 if (args.length == 0){ 130 junit.textui.TestRunner.run(GlobalsManagerTest.class); 131 } else { 132 junit.textui.TestRunner.run(makeSuite(args)); 133 } 134 } 135 private static TestSuite makeSuite(String args[]){ 136 final TestSuite ts = new TestSuite(); 137 for (int i = 0; i < args.length; i++){ 138 ts.addTest(new GlobalsManagerTest(args[i])); 139 } 140 return ts; 141 } 142 143 private class Env implements ICommandEnvironment 144 { 145 HashMap h = new HashMap (); 146 147 public void setEnvironment(String name, String value){ 148 h.put(name, value); 149 } 150 151 public Object removeEnvironment( String name ){ 152 final Object result = h.get(name); 153 h.remove(name); 154 return result; 155 } 156 157 public HashMap getEnvironments(){ 158 return new HashMap (h); 159 } 160 161 public Object getEnvironmentValue(String key){ 162 return h.get(key); 163 } 164 165 public String toString(){ 166 return h.toString(); 167 } 168 169 public int getNumEnvironments(){ 170 return h.size(); 171 } 172 } 173 174 } 175 | Popular Tags |