1 6 package org.roller.presentation; 7 8 import java.io.FileInputStream ; 9 import java.util.Iterator ; 10 import java.util.Properties ; 11 import java.util.Set ; 12 13 import junit.framework.Test; 14 import junit.framework.TestCase; 15 import junit.framework.TestSuite; 16 17 31 public class ApplicationResourcesTest extends TestCase 32 { 33 private String userDir = null; 34 private Properties baseProps = null; 35 36 39 public ApplicationResourcesTest(String name) 40 { 41 super(name); 42 } 43 44 public static Test suite() { 45 TestSuite suite = new TestSuite(); 46 suite.addTest( 48 new ApplicationResourcesTest("testApplicationResources_nl")); 49 suite.addTest( 50 new ApplicationResourcesTest("testApplicationResources_zh_cn")); 51 suite.addTest( 52 new ApplicationResourcesTest("testApplicationResources_zh_tw")); 53 suite.addTest( 54 new ApplicationResourcesTest("testApplicationResources_vi")); 55 return suite; 56 } 57 58 61 protected void setUp() throws Exception 62 { 63 super.setUp(); 64 userDir = System.getProperty("user.dir"); 65 66 baseProps = new Properties (); 68 baseProps.load(new FileInputStream ( 69 userDir + "/WEB-INF/classes/ApplicationResources.properties")); 70 } 71 72 77 public void testApplicationResources_nl() throws Exception 78 { 79 verifyResourceBundle("ApplicationResources_nl"); 80 } 81 82 87 public void testApplicationResources_zh_cn() throws Exception 88 { 89 verifyResourceBundle("ApplicationResources_zh_cn"); 90 } 91 92 97 public void testApplicationResources_zh_tw() throws Exception 98 { 99 verifyResourceBundle("ApplicationResources_zh_tw"); 100 } 101 102 107 public void testApplicationResources_vi() throws Exception 108 { 109 verifyResourceBundle("ApplicationResources_vi"); 110 } 111 112 public void testSystemProperties() 113 { 114 Properties sysProps = System.getProperties(); 115 Set keys = sysProps.keySet(); 116 for (Iterator iter = keys.iterator(); iter.hasNext();) 117 { 118 String key = (String ) iter.next(); 119 System.out.println(key + " = " + sysProps.getProperty(key)); 120 } 121 } 122 123 129 private void verifyResourceBundle(String bundle) throws Exception 130 { 131 assertNotNull(userDir); 133 assertTrue(userDir.endsWith("roller")); 134 135 Properties props = new Properties (); 137 props.load( 138 new FileInputStream ( 139 userDir 140 + "/web/WEB-INF/classes/" 141 + bundle 142 + ".properties")); 143 144 Set keys = baseProps.keySet(); 145 boolean missingMessage = false; 146 147 System.out.println("Veriyfing " + bundle + "..."); 149 for (Iterator iter = keys.iterator(); iter.hasNext();) 150 { 151 String key = (String ) iter.next(); 152 if (props.getProperty(key) == null) 153 { 154 System.err.println(key + " = " + baseProps.getProperty(key)); 155 missingMessage = true; 156 } 157 } 158 159 assertFalse(missingMessage); 160 } 161 162 } 163 | Popular Tags |