001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: PrioritizedMsg.java,v 1.2 2006/09/29 12:32:09 drmlipp Exp $
021: *
022: * $Log: PrioritizedMsg.java,v $
023: * Revision 1.2 2006/09/29 12:32:09 drmlipp
024: * Consistently using WfMOpen as projct name now.
025: *
026: * Revision 1.1.1.2 2003/08/26 13:23:25 drmlipp
027: * Update to 1.0rc2
028: *
029: * Revision 1.4 2003/08/25 13:57:26 lipp
030: * Fixed test.
031: *
032: * Revision 1.3 2003/06/27 09:44:13 lipp
033: * Fixed copyright/license information.
034: *
035: * Revision 1.2 2003/03/31 16:50:29 huaiyang
036: * Logging using common-logging.
037: *
038: * Revision 1.1 2003/03/07 10:31:40 huaiyang
039: * Moved from the directory of api.
040: *
041: * Revision 1.3 2003/03/07 09:35:21 huaiyang
042: * Changed because of the new ImportMessage.properties.
043: *
044: * Revision 1.2 2003/03/07 08:02:24 huaiyang
045: * add the test for Locale.ENGLISH and Locale.GERMAN.
046: *
047: * Revision 1.1 2003/03/05 14:36:46 huaiyang
048: * Initial.
049: *
050: *
051: *
052: */
053: package util;
054:
055: import java.util.Locale;
056:
057: import de.danet.an.workflow.api.PrioritizedMessage;
058:
059: import junit.framework.Test;
060: import junit.framework.TestSuite;
061: import junit.framework.TestCase;
062:
063: /**
064: * Test the functionality of the class
065: * <code>de.danet.an.workflow.api.PrioritizedMessage</code>.
066: */
067: public class PrioritizedMsg extends TestCase {
068:
069: /** logger of this class */
070: static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory
071: .getLog(PrioritizedMsg.class);
072:
073: /**
074: * Constructor of this TestCase
075: *
076: * @param name name of this test case.
077: */
078: public PrioritizedMsg(String name) {
079: super (name);
080: }
081:
082: /**
083: * build this testsuite.
084: * @return the constructed test suite.
085: */
086: public static Test suite() {
087: TestSuite suite = new TestSuite();
088: suite.addTest(new PrioritizedMsg("message"));
089: suite.addTest(new PrioritizedMsg("messageInEnglish"));
090: suite.addTest(new PrioritizedMsg("messageInGerman"));
091: return suite;
092: }
093:
094: /**
095: * construct a prioritized message with a message that does not have
096: * the format "<code>a.resource.bundle.base.name#key</code>", then check
097: * the return value of the method <code>message()</code>.
098: */
099: public void message() {
100: String testMsg = "test message without key";
101: PrioritizedMessage pm = new PrioritizedMessage(
102: PrioritizedMessage.Priority.WARN, testMsg);
103: assertTrue(pm.message().equals(testMsg));
104: }
105:
106: /**
107: * construct a prioritized message with a message that does have
108: * the format "<code>a.resource.bundle.base.name#key</code>", then check
109: * the return value of the method <code>message(Locale.ENGLISH)</code>.
110: */
111: public void messageInEnglish() {
112: // get the default locale
113: Locale defaultLocale = Locale.getDefault();
114: Locale.setDefault(Locale.CHINESE);
115: String testMsg = "OTHERWISE-transition not at the end of "
116: + "TransitionRestrictions (will be ignored!)";
117: assertTrue(getMessageWithKey(Locale.ENGLISH).equals(testMsg));
118: String atestMsg = "Process testProcess is not unique";
119: logger.debug("set Locale default: " + Locale.getDefault());
120: assertTrue(getMessageWithKeyAndObjects(Locale.ENGLISH).equals(
121: atestMsg));
122: Locale.setDefault(defaultLocale);
123: logger.debug("restore Locale default: " + Locale.getDefault());
124: }
125:
126: /**
127: * construct a prioritized message with a message that does have
128: * the format "<code>a.resource.bundle.base.name#key</code>", then check
129: * the return value of the method <code>message(Locale.GERMAN)</code>.
130: */
131: public void messageInGerman() {
132: String testMsg = "OTHERWISE-Transition nicht am Ende von "
133: + "TransitionRestrictions, sie wird ignoriert!";
134: assertTrue(getMessageWithKey(Locale.GERMAN).equals(testMsg));
135: String atestMsg = "Prozess testProcess ist nicht eindeutig";
136: assertTrue(getMessageWithKeyAndObjects(Locale.GERMAN).equals(
137: atestMsg));
138: }
139:
140: private String getMessageWithKey(Locale locale) {
141: PrioritizedMessage pm = new PrioritizedMessage(
142: PrioritizedMessage.Priority.ERROR,
143: "ImportMessages#procdef.transition.otherwise.notatend");
144: String internationizedMsg = pm.message(locale);
145: logger.debug("internationized message: " + internationizedMsg);
146: return internationizedMsg;
147: }
148:
149: private String getMessageWithKeyAndObjects(Locale locale) {
150: Object[] objects = { "testProcess" };
151: PrioritizedMessage pm = new PrioritizedMessage(
152: PrioritizedMessage.Priority.ERROR,
153: "ImportMessages#procdef.process.ununique", objects);
154: String internationizedMsg = pm.message(locale);
155: logger.debug("internationized message: " + internationizedMsg);
156: return internationizedMsg;
157: }
158:
159: }
|