01: /*
02: * $Id: SettingsTest.java 499294 2007-01-24 07:33:24Z mrdon $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts2.config;
22:
23: import java.util.Iterator;
24: import java.util.Locale;
25:
26: import org.apache.struts2.StrutsConstants;
27: import org.apache.struts2.StrutsTestCase;
28:
29: import com.opensymphony.xwork2.util.LocalizedTextUtil;
30:
31: /**
32: * Unit test for {@link SettingsTest}.
33: *
34: */
35: public class SettingsTest extends StrutsTestCase {
36:
37: public void testSettings() {
38: assertEquals("12345", Settings
39: .get(StrutsConstants.STRUTS_MULTIPART_MAXSIZE));
40: assertEquals("\temp", Settings
41: .get(StrutsConstants.STRUTS_MULTIPART_SAVEDIR));
42:
43: assertEquals("test,org/apache/struts2/othertest", Settings
44: .get(StrutsConstants.STRUTS_CUSTOM_PROPERTIES));
45: assertEquals("testvalue", Settings.get("testkey"));
46: assertEquals("othertestvalue", Settings.get("othertestkey"));
47:
48: Locale locale = Settings.getLocale();
49: assertEquals("de", locale.getLanguage());
50:
51: int count = getKeyCount();
52: assertEquals(11, count);
53: }
54:
55: public void testDefaultResourceBundlesLoaded() {
56: assertEquals("testmessages,testmessages2", Settings
57: .get(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES));
58: assertEquals("This is a test message", LocalizedTextUtil
59: .findDefaultText("default.testmessage", Locale
60: .getDefault()));
61: assertEquals("This is another test message", LocalizedTextUtil
62: .findDefaultText("default.testmessage2", Locale
63: .getDefault()));
64: }
65:
66: public void testSetSettings() {
67: Settings.setInstance(new TestSettings());
68:
69: String keyName = "a.long.property.key.name";
70: assertEquals(keyName, Settings.get(keyName));
71: assertEquals(2, getKeyCount());
72: }
73:
74: private int getKeyCount() {
75: int count = 0;
76: Iterator keyNames = Settings.list();
77:
78: while (keyNames.hasNext()) {
79: keyNames.next();
80: count++;
81: }
82:
83: return count;
84: }
85: }
|