001: /*
002: * Copyright (c) 2002-2006 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.config;
006:
007: import com.opensymphony.webwork.WebWorkTestCase;
008: import com.opensymphony.webwork.WebWorkConstants;
009: import com.opensymphony.xwork.util.LocalizedTextUtil;
010:
011: import java.util.Iterator;
012: import java.util.Locale;
013:
014: /**
015: * Unit test for {@link ConfigurationTest}.
016: *
017: * @author Jason Carreira
018: * @version $Date: 2007-02-16 08:15:36 +0100 (Fri, 16 Feb 2007) $ $Id: ConfigurationTest.java 2846 2007-02-16 07:15:36Z tm_jee $
019: */
020: public class ConfigurationTest extends WebWorkTestCase {
021:
022: public void testConfiguration() {
023: assertEquals("get", Configuration
024: .getString(WebWorkConstants.WEBWORK_URL_INCLUDEPARAMS));
025: assertEquals("12345", Configuration
026: .getString(WebWorkConstants.WEBWORK_MULTIPART_MAXSIZE));
027: assertEquals("\temp", Configuration
028: .getString(WebWorkConstants.WEBWORK_MULTIPART_SAVEDIR));
029:
030: assertEquals(
031: "test,com/opensymphony/webwork/othertest",
032: Configuration
033: .getString(WebWorkConstants.WEBWORK_CUSTOM_PROPERTIES));
034: assertEquals("testvalue", Configuration.getString("testkey"));
035: assertEquals("othertestvalue", Configuration
036: .getString("othertestkey"));
037:
038: Locale locale = Configuration.getLocale();
039: assertEquals("de", locale.getLanguage());
040:
041: int count = getKeyCount();
042: assertEquals(29, count);
043: }
044:
045: public void testDefaultResourceBundlesLoaded() {
046: assertEquals(
047: "testmessages,testmessages2",
048: Configuration
049: .getString(WebWorkConstants.WEBWORK_CUSTOM_I18N_RESOURCES));
050: assertEquals("This is a test message", LocalizedTextUtil
051: .findDefaultText("default.testmessage", Locale
052: .getDefault()));
053: assertEquals("This is another test message", LocalizedTextUtil
054: .findDefaultText("default.testmessage2", Locale
055: .getDefault()));
056: }
057:
058: public void testReplaceDefaultMessages() {
059: Locale.setDefault(Locale.US); // force to US locale as we also have _de and _da properties
060:
061: LocalizedTextUtil.clearDefaultResourceBundles();
062: LocalizedTextUtil
063: .addDefaultResourceBundle("com/opensymphony/webwork/webwork-messages");
064: assertEquals(
065: "The form has already been processed or no token was supplied, please try again.",
066: LocalizedTextUtil.findDefaultText(
067: "webwork.messages.invalid.token", Locale
068: .getDefault()));
069: Configuration.reset();
070:
071: assertEquals(
072: "testmessages,testmessages2",
073: Configuration
074: .getString(WebWorkConstants.WEBWORK_CUSTOM_I18N_RESOURCES));
075: assertEquals("Replaced message for token tag",
076: LocalizedTextUtil.findDefaultText(
077: "webwork.messages.invalid.token", Locale
078: .getDefault()));
079: }
080:
081: public void testSetConfiguration() {
082: Configuration.setConfiguration(new TestConfiguration());
083:
084: String keyName = "a.long.property.key.name";
085: assertEquals(keyName, Configuration.getString(keyName));
086: assertEquals(2, getKeyCount());
087: }
088:
089: private int getKeyCount() {
090: int count = 0;
091: Iterator keyNames = Configuration.list();
092:
093: while (keyNames.hasNext()) {
094: String key = (String) keyNames.next();
095: count++;
096: }
097:
098: return count;
099: }
100: }
|