01: /*
02: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package de.odysseus.calyxo.control.impl;
17:
18: import java.util.ArrayList;
19: import java.util.Locale;
20:
21: import de.odysseus.calyxo.base.test.TestPageContext;
22: import de.odysseus.calyxo.base.test.TestRequest;
23:
24: import junit.framework.TestCase;
25:
26: /**
27: *
28: * @author Christoph Beck
29: */
30: public class DefaultI18nSupportTest extends TestCase {
31: private final String BUNDLE_NAME = getClass().getPackage()
32: .getName()
33: + ".resources";
34:
35: /**
36: * Constructor for DefaultI18nSupportTest.
37: * @param arg0
38: */
39: public DefaultI18nSupportTest(String arg0) {
40: super (arg0);
41: }
42:
43: public static void main(String[] args) {
44: junit.textui.TestRunner.run(DefaultI18nSupportTest.class);
45: }
46:
47: public void testLocale() {
48: TestRequest request = new TestRequest();
49: Locale locale = new Locale("cc", "");
50: DefaultI18nSupport support = new DefaultI18nSupport();
51: support.setLocale(request, locale);
52: assertSame(locale, support.getLocale(request));
53: assertSame(locale, support.getLocale(new TestPageContext(
54: request)));
55: }
56:
57: public void testResource() {
58: Locale locale = new Locale("cc", "");
59: DefaultI18nSupport support = new DefaultI18nSupport();
60: String s = support.getResource(locale, BUNDLE_NAME, "msg0");
61: assertEquals("message0", s);
62: }
63:
64: public void testMessage() {
65: Locale locale = new Locale("cc", "");
66: DefaultI18nSupport support = new DefaultI18nSupport();
67: ArrayList args = new ArrayList();
68: String s = null;
69:
70: s = support.getMessage(locale, BUNDLE_NAME, "msg0", args
71: .toArray());
72: assertEquals("message0", s);
73: args.add("arg1");
74: s = support.getMessage(locale, BUNDLE_NAME, "msg1", args
75: .toArray());
76: assertEquals("message1: arg1", s);
77: args.add("arg2");
78: s = support.getMessage(locale, BUNDLE_NAME, "msg2", args
79: .toArray());
80: assertEquals("message2: arg1, arg2", s);
81: }
82: }
|