1 23 24 package com.sun.enterprise.cli.framework; 25 26 32 import junit.framework.*; 33 import java.util.Properties ; 34 import java.util.HashSet ; 35 import java.util.Set ; 36 import junit.textui.TestRunner; 37 import java.util.ResourceBundle ; 38 import java.util.Enumeration ; 39 import java.util.List ; 40 import java.util.ArrayList ; 41 46 47 52 53 public class LocalStringsManagerFactoryTest extends TestCase { 54 private static final String P1_PROP = "P1"; 56 private static final String P2_PROP = "P2"; 57 private static final String PACKAGE = "com.sun.enterprise.cli.framework"; 58 59 public void testConstructor(){ 60 final LocalStringsManagerFactory lsmf = new LocalStringsManagerFactory(); 61 } 62 public void testSetInstance() throws Exception { 63 final LocalStringsManager lsm = new LocalStringsManager(PACKAGE, P1_PROP); 64 LocalStringsManagerFactory.setInstance(PACKAGE, lsm); 65 assertEquals(lsm, LocalStringsManagerFactory.getLocalStringsManager(PACKAGE, P1_PROP)); 66 } 67 68 public void testMultiplePropertyUniqueValuesMissing() throws Exception { 71 Set hs = new HashSet (); 72 hs.add(p1); 73 hs.add(p2); 74 LocalStringsManagerFactory.setCommandLocalStringsManagerProperties(hs.iterator()); 75 LocalStringsManager lsm = LocalStringsManagerFactory.getCommandLocalStringsManager(); 76 assertEquals("expected b to be from P1", "P1.b", lsm.getString("b")); 77 assertEquals("expected c to be from P2", "P2.c", lsm.getString("c")); 78 } 79 80 81 public void testMultiplePropertyLookupOverride() throws Exception { 84 List hs = new ArrayList (); 85 hs.add(p1); 86 hs.add(p2); 87 88 LocalStringsManagerFactory.setCommandLocalStringsManagerProperties(hs.iterator()); 89 LocalStringsManager lsm = LocalStringsManagerFactory.getCommandLocalStringsManager(); 90 assertEquals("expected a to be overridden and come from P1", "P1.a", lsm.getString("a")); 91 } 92 93 public void testP1Lookup() throws Exception { 96 Set hs = new HashSet (); 97 hs.add(p1); 98 LocalStringsManagerFactory.setCommandLocalStringsManagerProperties(hs.iterator()); 99 LocalStringsManager lsm = LocalStringsManagerFactory.getCommandLocalStringsManager(); 100 assertEquals("P1.a", lsm.getString("a")); 101 assertEquals("P1.b", lsm.getString("b")); 102 } 103 104 public void testP2Lookup() throws Exception { 105 Set hs = new HashSet (); 106 hs.add(p2); 107 LocalStringsManagerFactory.setCommandLocalStringsManagerProperties(hs.iterator()); 108 LocalStringsManager lsm = LocalStringsManagerFactory.getCommandLocalStringsManager(); 109 assertEquals("P2.a", lsm.getString("a")); 110 assertEquals("P2.c", lsm.getString("c")); 111 112 } 113 114 public LocalStringsManagerFactoryTest(String name){ 115 super(name); 116 } 117 118 Properties p1; 119 Properties p2; 120 121 protected void setUp() { 122 p1 = new Properties (); 123 p2 = new Properties (); 124 initProperty(p1, P1_PROP); 125 initProperty(p2, P2_PROP); 126 } 127 128 void initProperty(Properties prop, String file){ 129 prop.setProperty("base-package", PACKAGE); 130 prop.setProperty("property-file-name", file); 131 } 132 133 134 protected void tearDown() { 135 } 136 137 private void nyi(){ 138 fail("Not Yet Implemented"); 139 } 140 141 public static Test suite(){ 142 TestSuite suite = new TestSuite(LocalStringsManagerFactoryTest.class); 143 return suite; 144 } 145 146 public static void main(String args[]) throws Exception { 147 final TestRunner runner= new TestRunner(); 148 final TestResult result = runner.doRun(LocalStringsManagerFactoryTest.suite(), false); 149 System.exit(result.errorCount() + result.failureCount()); 150 } 151 } 152 153 | Popular Tags |