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