1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 /***
33 * Unit test for {@link SettingsTest}.
34 *
35 */
36 public class SettingsTest extends StrutsTestCase {
37
38 public void testSettings() {
39 assertEquals("12345", Settings.get(StrutsConstants.STRUTS_MULTIPART_MAXSIZE));
40 assertEquals("\temp", Settings.get(StrutsConstants.STRUTS_MULTIPART_SAVEDIR));
41
42 assertEquals("test,org/apache/struts2/othertest", Settings.get( StrutsConstants.STRUTS_CUSTOM_PROPERTIES));
43 assertEquals("testvalue", Settings.get("testkey"));
44 assertEquals("othertestvalue", Settings.get("othertestkey"));
45
46 Locale locale = Settings.getLocale();
47 assertEquals("de", locale.getLanguage());
48
49 int count = getKeyCount();
50 assertEquals(11, count);
51 }
52
53 public void testDefaultResourceBundlesLoaded() {
54 assertEquals("testmessages,testmessages2", Settings.get(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES));
55 assertEquals("This is a test message", LocalizedTextUtil.findDefaultText("default.testmessage", Locale.getDefault()));
56 assertEquals("This is another test message", LocalizedTextUtil.findDefaultText("default.testmessage2", Locale.getDefault()));
57 }
58
59 public void testSetSettings() {
60 Settings.setInstance(new TestSettings());
61
62 String keyName = "a.long.property.key.name";
63 assertEquals(keyName, Settings.get(keyName));
64 assertEquals(2, getKeyCount());
65 }
66
67 private int getKeyCount() {
68 int count = 0;
69 Iterator keyNames = Settings.list();
70
71 while (keyNames.hasNext()) {
72 keyNames.next();
73 count++;
74 }
75
76 return count;
77 }
78 }