1 7 8 package com.j2biz.blogunity.test; 9 10 import java.io.File ; 11 import java.io.FileInputStream ; 12 import java.io.FileNotFoundException ; 13 import java.io.IOException ; 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import java.util.Properties ; 17 18 import org.apache.commons.lang.StringUtils; 19 20 import junit.framework.TestCase; 21 22 26 public class LocaleCompleteTest extends TestCase { 27 28 private static String [] locales = { "_de", "_ru", "_es", "_en", ""}; 29 30 private static String suffix = ".properties"; 31 32 public void testMessagePropertiess() { 33 propsTest("translations/i18n_messages"); 34 } 35 36 public void testDisplaytagProperties() { 37 propsTest("translations/displaytag"); 38 } 39 40 public void testNavigationProperties() { 41 propsTest("translations/i18n_navigation"); 42 } 43 44 private void propsTest(String prefix) { 45 ArrayList properties = new ArrayList (); 46 try { 47 for (int i = 0; i < locales.length; i++) { 49 Properties p = new Properties (); 50 p.load(new FileInputStream (new File (prefix + locales[i] + suffix))); 51 Iterator it = p.keySet().iterator(); 52 properties.add(p); 53 } 54 } catch (FileNotFoundException e) { 55 fail(e.toString()); 56 } catch (IOException e) { 57 fail(e.toString()); 58 } 59 60 Properties firstPropertyFile = null; 61 for (Iterator iter = properties.iterator(); iter.hasNext();) { 62 firstPropertyFile = (Properties ) iter.next(); 63 } 64 65 int i = 0; for (Iterator iterator = properties.iterator(); iterator.hasNext();) { 67 Properties propertyFile = (Properties ) iterator.next(); 68 Iterator firstFileIter = firstPropertyFile.keySet().iterator(); 69 while (firstFileIter.hasNext()) { 72 String key = (String ) firstFileIter.next(); 73 String msg = propertyFile.getProperty(key); 74 if (StringUtils.isEmpty(msg)) { 75 fail("String for key " + key + " was empty in file " + prefix + locales[i] + suffix); 76 } 77 } 78 79 Iterator secondFileIter = propertyFile.keySet().iterator(); 81 82 while (secondFileIter.hasNext()) { 83 84 String key = (String ) secondFileIter.next(); 85 String msg = firstPropertyFile.getProperty(key); 86 87 if (StringUtils.isEmpty(msg)) { 88 fail("String for key " + key + " was empty in file " + prefix + locales[0] + suffix); 89 } 90 } 91 92 if (firstPropertyFile.keySet().size() != propertyFile.keySet().size()) { 93 fail("File: " + prefix + locales[0] + suffix + "Was not the same size as: " + prefix + locales[i] + suffix); 94 } 95 i++; 96 } 97 } 98 } 99 | Popular Tags |