KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > i18n > TestCmsMessages


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/i18n/TestCmsMessages.java,v $
3  * Date : $Date: 2006/03/27 14:52:51 $
4  * Version: $Revision: 1.7 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.i18n;
33
34
35 import java.util.Locale JavaDoc;
36
37 import junit.framework.TestCase;
38
39 /**
40  * Tests for the CmsMessages.<p>
41  *
42  * @author Alexander Kandzior
43  *
44  * @version $Revision: 1.7 $
45  *
46  * @since 6.0.0
47  */

48 public class TestCmsMessages extends TestCase {
49
50     /**
51      * Tests parameter replacement in messages.<p>
52      *
53      * @throws Exception if the test fails
54      */

55     public void testMessageWithParameters() throws Exception JavaDoc {
56
57         String JavaDoc value;
58
59         CmsMessages messages = new CmsMessages(org.opencms.xml.content.Messages.get().getBundleName(), Locale.ENGLISH);
60
61         value = messages.key("GUI_EDITOR_XMLCONTENT_VALIDATION_WARNING_2");
62         assertEquals("Bad value \"{0}\" according to rule {1}", value);
63
64         value = messages.key("GUI_EDITOR_XMLCONTENT_VALIDATION_WARNING_2", new Object JavaDoc[] {"some value", "the rule"});
65         assertEquals("Bad value \"some value\" according to rule the rule", value);
66     }
67
68     /**
69      * Tests for for missing localized keys.<p>
70      *
71      * @throws Exception if the test fails
72      */

73     public void testUnknownKeys() throws Exception JavaDoc {
74
75         String JavaDoc value = null;
76
77         // check for null value
78
assertTrue(CmsMessages.isUnknownKey(value));
79
80         // test key formatted as unknown
81
value = CmsMessages.formatUnknownKey("somekey");
82         assertTrue(CmsMessages.isUnknownKey(value));
83
84         // check a value certainly NOT unknown
85
value = "Title";
86         assertFalse(CmsMessages.isUnknownKey(value));
87
88         // the empty String is also NOT an unknown key
89
value = "";
90         assertFalse(CmsMessages.isUnknownKey(value));
91
92         CmsMessages messages = new CmsMessages(org.opencms.workplace.Messages.get().getBundleName(), Locale.ENGLISH);
93         value = messages.key("GUI_LOGIN_BUTTON_0");
94         assertFalse(CmsMessages.isUnknownKey(value));
95         assertEquals("Login", value);
96
97         String JavaDoc defaultValue = "This value does not exist!";
98         value = messages.keyDefault("idontexist", defaultValue);
99         assertFalse(CmsMessages.isUnknownKey(defaultValue));
100         assertEquals(defaultValue, value);
101     }
102 }
103
Popular Tags