KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > test > LocaleCompleteTest


1 /*
2  * Created on 02.01.2005
3  * Last commit $Date: 2005/01/05 00:52:25 $
4  * $Revision: 1.2 $
5  * $Author: keyboardsamurai $
6  */

7
8 package com.j2biz.blogunity.test;
9
10 import java.io.File JavaDoc;
11 import java.io.FileInputStream JavaDoc;
12 import java.io.FileNotFoundException JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.Properties JavaDoc;
17
18 import org.apache.commons.lang.StringUtils;
19
20 import junit.framework.TestCase;
21
22 /**
23  * @author tag Juan Antonio Agudo
24  *
25  */

26 public class LocaleCompleteTest extends TestCase {
27
28     private static String JavaDoc[] locales = { "_de", "_ru", "_es", "_en", ""};
29
30     private static String JavaDoc 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 JavaDoc prefix) {
45         ArrayList JavaDoc properties = new ArrayList JavaDoc();
46         try {
47             // preload properties
48
for (int i = 0; i < locales.length; i++) {
49                 Properties JavaDoc p = new Properties JavaDoc();
50                 p.load(new FileInputStream JavaDoc(new File JavaDoc(prefix + locales[i] + suffix)));
51                 Iterator JavaDoc it = p.keySet().iterator();
52                 properties.add(p);
53             }
54         } catch (FileNotFoundException JavaDoc e) {
55             fail(e.toString());
56         } catch (IOException JavaDoc e) {
57             fail(e.toString());
58         }
59
60         Properties JavaDoc firstPropertyFile = null;
61         for (Iterator JavaDoc iter = properties.iterator(); iter.hasNext();) {
62             firstPropertyFile = (Properties JavaDoc) iter.next();
63         }
64
65         int i = 0; // to indicate which file we are treating
66
for (Iterator JavaDoc iterator = properties.iterator(); iterator.hasNext();) {
67             Properties JavaDoc propertyFile = (Properties JavaDoc) iterator.next();
68             Iterator JavaDoc firstFileIter = firstPropertyFile.keySet().iterator();
69             // see if every key from the first file is contained in the current
70
// file
71
while (firstFileIter.hasNext()) {
72                 String JavaDoc key = (String JavaDoc) firstFileIter.next();
73                 String JavaDoc 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             // and now the other way around
80
Iterator JavaDoc secondFileIter = propertyFile.keySet().iterator();
81
82             while (secondFileIter.hasNext()) {
83
84                 String JavaDoc key = (String JavaDoc) secondFileIter.next();
85                 String JavaDoc 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