001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: /*
019: * Filename: ApplicationResourcesTest.java
020: *
021: * Created on 24-May-04
022: */
023: package org.apache.roller.ui;
024:
025: import java.io.FileInputStream;
026: import java.util.Iterator;
027: import java.util.Properties;
028: import java.util.Set;
029:
030: import junit.framework.Test;
031: import junit.framework.TestCase;
032: import junit.framework.TestSuite;
033:
034: /**
035: * The purpose of this class is to verify that all messages in
036: * the base ApplicationResources.properties file also appear
037: * in the localized properties files.
038: *
039: * If messages do not appear, the test fails and the 'evil-doers' are
040: * printed to System.out.
041: *
042: * Note: we need to make sure that new property files are added to this
043: * test.
044: *
045: * @author <a href="mailto:molen@mail.com">Jaap van der Molen</a>
046: * @version $Revision: 1.7 $
047: */
048: public class ApplicationResourcesTest extends TestCase {
049: private String userDir = null;
050: private Properties baseProps = null;
051:
052: /**
053: * @param arg0
054: */
055: public ApplicationResourcesTest(String name) {
056: super (name);
057: }
058:
059: public static Test suite() {
060: TestSuite suite = new TestSuite();
061: //suite.addTest(new ApplicationResourcesTest("testSystemProperties"));
062: suite.addTest(new ApplicationResourcesTest(
063: "testApplicationResources_nl"));
064: suite.addTest(new ApplicationResourcesTest(
065: "testApplicationResources_zh_cn"));
066: suite.addTest(new ApplicationResourcesTest(
067: "testApplicationResources_zh_tw"));
068: suite.addTest(new ApplicationResourcesTest(
069: "testApplicationResources_vi"));
070: return suite;
071: }
072:
073: /**
074: * @see junit.framework.TestCase#setUp()
075: */
076: protected void setUp() throws Exception {
077: super .setUp();
078: userDir = System.getProperty("user.dir");
079:
080: // load base ApplicationResources.properties file
081: baseProps = new Properties();
082: baseProps.load(new FileInputStream(userDir
083: + "/WEB-INF/classes/ApplicationResources.properties"));
084: }
085:
086: /**
087: * Test Dutch stuff.
088: *
089: * @throws Exception
090: */
091: public void testApplicationResources_nl() throws Exception {
092: verifyResourceBundle("ApplicationResources_nl");
093: }
094:
095: /**
096: * Test Simple Chinese stuff.
097: *
098: * @throws Exception
099: */
100: public void testApplicationResources_zh_cn() throws Exception {
101: verifyResourceBundle("ApplicationResources_zh_cn");
102: }
103:
104: /**
105: * Test Traditional Chinese stuff.
106: *
107: * @throws Exception
108: */
109: public void testApplicationResources_zh_tw() throws Exception {
110: verifyResourceBundle("ApplicationResources_zh_tw");
111: }
112:
113: /**
114: * Test Vietnamese stuff.
115: *
116: * @throws Exception
117: */
118: public void testApplicationResources_vi() throws Exception {
119: verifyResourceBundle("ApplicationResources_vi");
120: }
121:
122: public void testSystemProperties() {
123: Properties sysProps = System.getProperties();
124: Set keys = sysProps.keySet();
125: for (Iterator iter = keys.iterator(); iter.hasNext();) {
126: String key = (String) iter.next();
127: System.out.println(key + " = " + sysProps.getProperty(key));
128: }
129: }
130:
131: /**
132: * Helper method to do the actual testing.
133: *
134: * @param bundle name of bundle to test
135: * @throws Exception if file not found, or if io ecxeption occurs.
136: */
137: private void verifyResourceBundle(String bundle) throws Exception {
138: // verify user-dir; should end with roller
139: assertNotNull(userDir);
140: assertTrue(userDir.endsWith("roller"));
141:
142: // load Chinese resource file
143: Properties props = new Properties();
144: props.load(new FileInputStream(userDir
145: + "/web/WEB-INF/classes/" + bundle + ".properties"));
146:
147: Set keys = baseProps.keySet();
148: boolean missingMessage = false;
149:
150: // check Chinese
151: System.out.println("Veriyfing " + bundle + "...");
152: for (Iterator iter = keys.iterator(); iter.hasNext();) {
153: String key = (String) iter.next();
154: if (props.getProperty(key) == null) {
155: System.err.println(key + " = "
156: + baseProps.getProperty(key));
157: missingMessage = true;
158: }
159: }
160:
161: assertFalse(missingMessage);
162: }
163:
164: }
|