KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > config > ConfigurationTest


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.config;
6
7 import com.opensymphony.webwork.WebWorkTestCase;
8 import com.opensymphony.xwork.util.LocalizedTextUtil;
9
10 import java.util.Iterator JavaDoc;
11 import java.util.Locale JavaDoc;
12
13
14 /**
15  * ConfigurationTest
16  *
17  * @author Jason Carreira
18  * Created Apr 9, 2003 10:42:30 PM
19  */

20 public class ConfigurationTest extends WebWorkTestCase {
21     //~ Methods ////////////////////////////////////////////////////////////////
22

23     public void testConfiguration() {
24         assertEquals("12345", Configuration.getString("webwork.multipart.maxSize"));
25         assertEquals("\temp", Configuration.getString("webwork.multipart.saveDir"));
26
27         assertEquals("test,com/opensymphony/webwork/othertest", Configuration.getString("webwork.custom.properties"));
28         assertEquals("testvalue", Configuration.getString("testkey"));
29         assertEquals("othertestvalue", Configuration.getString("othertestkey"));
30
31         Locale JavaDoc locale = Configuration.getLocale();
32         assertEquals("de", locale.getLanguage());
33
34         int count = getKeyCount();
35         assertEquals(21, count);
36     }
37
38     public void testDefaultResourceBundlesLoaded() {
39         assertEquals("testmessages,testmessages2", Configuration.getString("webwork.custom.i18n.resources"));
40         assertEquals("This is a test message", LocalizedTextUtil.findDefaultText("default.testmessage", Locale.getDefault()));
41         assertEquals("This is another test message", LocalizedTextUtil.findDefaultText("default.testmessage2", Locale.getDefault()));
42     }
43
44     public void testSetConfiguration() {
45         Configuration.setConfiguration(new TestConfiguration());
46
47         String JavaDoc keyName = "a.long.property.key.name";
48         assertEquals(keyName, Configuration.getString(keyName));
49         assertEquals(2, getKeyCount());
50     }
51
52     private int getKeyCount() {
53         int count = 0;
54         Iterator JavaDoc keyNames = Configuration.list();
55
56         while (keyNames.hasNext()) {
57             String JavaDoc key = (String JavaDoc) keyNames.next();
58             count++;
59         }
60
61         return count;
62     }
63 }
64
Popular Tags