KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > ApplicationResourcesTest


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 /*
19  * Filename: ApplicationResourcesTest.java
20  *
21  * Created on 24-May-04
22  */

23 package org.apache.roller.ui;
24
25 import java.io.FileInputStream JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Properties JavaDoc;
28 import java.util.Set JavaDoc;
29
30 import junit.framework.Test;
31 import junit.framework.TestCase;
32 import junit.framework.TestSuite;
33
34 /**
35  * The purpose of this class is to verify that all messages in
36  * the base ApplicationResources.properties file also appear
37  * in the localized properties files.
38  *
39  * If messages do not appear, the test fails and the 'evil-doers' are
40  * printed to System.out.
41  *
42  * Note: we need to make sure that new property files are added to this
43  * test.
44  *
45  * @author <a HREF="mailto:molen@mail.com">Jaap van der Molen</a>
46  * @version $Revision: 1.7 $
47  */

48 public class ApplicationResourcesTest extends TestCase
49 {
50     private String JavaDoc userDir = null;
51     private Properties JavaDoc baseProps = null;
52
53     /**
54      * @param arg0
55      */

56     public ApplicationResourcesTest(String JavaDoc name)
57     {
58         super(name);
59     }
60     
61     public static Test suite() {
62         TestSuite suite = new TestSuite();
63         //suite.addTest(new ApplicationResourcesTest("testSystemProperties"));
64
suite.addTest(
65             new ApplicationResourcesTest("testApplicationResources_nl"));
66         suite.addTest(
67             new ApplicationResourcesTest("testApplicationResources_zh_cn"));
68         suite.addTest(
69             new ApplicationResourcesTest("testApplicationResources_zh_tw"));
70         suite.addTest(
71             new ApplicationResourcesTest("testApplicationResources_vi"));
72         return suite;
73     }
74     
75     /**
76      * @see junit.framework.TestCase#setUp()
77      */

78     protected void setUp() throws Exception JavaDoc
79     {
80         super.setUp();
81         userDir = System.getProperty("user.dir");
82         
83         // load base ApplicationResources.properties file
84
baseProps = new Properties JavaDoc();
85         baseProps.load(new FileInputStream JavaDoc(
86                 userDir + "/WEB-INF/classes/ApplicationResources.properties"));
87     }
88
89     /**
90      * Test Dutch stuff.
91      *
92      * @throws Exception
93      */

94     public void testApplicationResources_nl() throws Exception JavaDoc
95     {
96         verifyResourceBundle("ApplicationResources_nl");
97     }
98
99     /**
100      * Test Simple Chinese stuff.
101      *
102      * @throws Exception
103      */

104     public void testApplicationResources_zh_cn() throws Exception JavaDoc
105     {
106         verifyResourceBundle("ApplicationResources_zh_cn");
107     }
108
109     /**
110      * Test Traditional Chinese stuff.
111      *
112      * @throws Exception
113      */

114     public void testApplicationResources_zh_tw() throws Exception JavaDoc
115     {
116         verifyResourceBundle("ApplicationResources_zh_tw");
117     }
118
119     /**
120      * Test Vietnamese stuff.
121      *
122      * @throws Exception
123      */

124     public void testApplicationResources_vi() throws Exception JavaDoc
125     {
126         verifyResourceBundle("ApplicationResources_vi");
127     }
128
129     public void testSystemProperties()
130     {
131         Properties JavaDoc sysProps = System.getProperties();
132         Set JavaDoc keys = sysProps.keySet();
133         for (Iterator JavaDoc iter = keys.iterator(); iter.hasNext();)
134         {
135             String JavaDoc key = (String JavaDoc) iter.next();
136             System.out.println(key + " = " + sysProps.getProperty(key));
137         }
138     }
139
140     /**
141      * Helper method to do the actual testing.
142      *
143      * @param bundle name of bundle to test
144      * @throws Exception if file not found, or if io ecxeption occurs.
145      */

146     private void verifyResourceBundle(String JavaDoc bundle) throws Exception JavaDoc
147     {
148         // verify user-dir; should end with roller
149
assertNotNull(userDir);
150         assertTrue(userDir.endsWith("roller"));
151         
152         // load Chinese resource file
153
Properties JavaDoc props = new Properties JavaDoc();
154         props.load(
155             new FileInputStream JavaDoc(
156                 userDir
157                     + "/web/WEB-INF/classes/"
158                     + bundle
159                     + ".properties"));
160
161         Set JavaDoc keys = baseProps.keySet();
162         boolean missingMessage = false;
163
164         // check Chinese
165
System.out.println("Veriyfing " + bundle + "...");
166         for (Iterator JavaDoc iter = keys.iterator(); iter.hasNext();)
167         {
168             String JavaDoc key = (String JavaDoc) iter.next();
169             if (props.getProperty(key) == null)
170             {
171                 System.err.println(key + " = " + baseProps.getProperty(key));
172                 missingMessage = true;
173             }
174         }
175
176         assertFalse(missingMessage);
177     }
178
179 }
180
Popular Tags