KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > error > AlfrescoRuntimeExceptionTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.error;
18
19 import java.util.Locale JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import org.alfresco.i18n.I18NUtil;
24
25 /**
26  * Alfresco runtime exception test
27  *
28  * @author Roy Wetherall
29  */

30 public class AlfrescoRuntimeExceptionTest extends TestCase
31 {
32     private static final String JavaDoc BASE_RESOURCE_NAME = "org.alfresco.i18n.testMessages";
33     private static final String JavaDoc PARAM_VALUE = "television";
34     private static final String JavaDoc MSG_PARAMS = "msg_params";
35     private static final String JavaDoc MSG_ERROR = "msg_error";
36     private static final String JavaDoc VALUE_ERROR = "This is an error message. \n This is on a new line.";
37     private static final String JavaDoc VALUE_FR_ERROR = "C'est un message d'erreur. \n C'est sur une nouvelle ligne.";
38     private static final String JavaDoc VALUE_PARAMS = "What no " + PARAM_VALUE + "?";
39     private static final String JavaDoc VALUE_FR_PARAMS = "Que non " + PARAM_VALUE + "?";
40     private static final String JavaDoc NON_I18NED_MSG = "This is a non i18ned error message.";
41    
42     @Override JavaDoc
43     protected void setUp() throws Exception JavaDoc
44     {
45         // Re-set the current locale to be the default
46
I18NUtil.setLocale(Locale.getDefault());
47     }
48     
49     public void testI18NBehaviour()
50     {
51         // Register the bundle
52
I18NUtil.registerResourceBundle(BASE_RESOURCE_NAME);
53         
54         AlfrescoRuntimeException exception1 = new AlfrescoRuntimeException(MSG_PARAMS, new Object JavaDoc[]{PARAM_VALUE});
55         assertEquals(VALUE_PARAMS, exception1.getMessage());
56         AlfrescoRuntimeException exception3 = new AlfrescoRuntimeException(MSG_ERROR);
57         assertEquals(VALUE_ERROR, exception3.getMessage());
58             
59         // Change the locale and re-test
60
I18NUtil.setLocale(new Locale JavaDoc("fr", "FR"));
61         
62         AlfrescoRuntimeException exception2 = new AlfrescoRuntimeException(MSG_PARAMS, new Object JavaDoc[]{PARAM_VALUE});
63         assertEquals(VALUE_FR_PARAMS, exception2.getMessage());
64         AlfrescoRuntimeException exception4 = new AlfrescoRuntimeException(MSG_ERROR);
65         assertEquals(VALUE_FR_ERROR, exception4.getMessage());
66         
67         AlfrescoRuntimeException exception5 = new AlfrescoRuntimeException(NON_I18NED_MSG);
68         assertEquals(NON_I18NED_MSG, exception5.getMessage());
69     }
70 }
71
Popular Tags