01: /*--------------------------------------------------------------------------*
02: | Copyright (C) 2006 Christopher Kohlhaas |
03: | |
04: | This program is free software; you can redistribute it and/or modify |
05: | it under the terms of the GNU General Public License as published by the |
06: | Free Software Foundation. A copy of the license has been included with |
07: | these distribution in the COPYING file, if not go to www.fsf.org |
08: | |
09: | As a special exception, you are granted the permissions to link this |
10: | program with every library, which license fulfills the Open Source |
11: | Definition as published by the Open Source Initiative (OSI). |
12: *--------------------------------------------------------------------------*/
13: package org.rapla;
14:
15: import java.text.ParseException;
16: import java.util.Calendar;
17: import java.util.Locale;
18:
19: import junit.framework.Test;
20: import junit.framework.TestCase;
21: import junit.framework.TestSuite;
22:
23: import org.apache.avalon.framework.configuration.DefaultConfiguration;
24: import org.rapla.components.util.SerializableDateTimeFormat;
25: import org.rapla.framework.RaplaException;
26: import org.rapla.framework.RaplaLocale;
27:
28: public class RaplaLocaleTest extends TestCase {
29: DefaultConfiguration config;
30:
31: public RaplaLocaleTest(String name) {
32: super (name);
33: }
34:
35: public static Test suite() {
36: return new TestSuite(RaplaLocaleTest.class);
37: }
38:
39: private DefaultConfiguration createConfig(String defaultLanguage,
40: String countryString) {
41: DefaultConfiguration config = new DefaultConfiguration(
42: "locale", this .toString());
43: DefaultConfiguration country = new DefaultConfiguration(
44: "country", this .toString());
45: country.setValue(countryString);
46: config.addChild(country);
47: DefaultConfiguration languages = new DefaultConfiguration(
48: "languages", this .toString());
49: config.addChild(languages);
50: languages.setAttribute("default", defaultLanguage);
51: DefaultConfiguration language1 = new DefaultConfiguration(
52: "language", this .toString());
53: language1.setValue("de");
54: DefaultConfiguration language2 = new DefaultConfiguration(
55: "language", this .toString());
56: language2.setValue("en");
57: languages.addChild(language1);
58: languages.addChild(language2);
59: return config;
60: }
61:
62: public void testDateFormat3() throws ParseException, RaplaException {
63: RaplaLocale raplaLocale = new RaplaLocaleImpl(createConfig(
64: "de", "DE"));
65: String s = raplaLocale
66: .formatDate(new SerializableDateTimeFormat().parseDate(
67: "2001-01-12", false));
68: assertEquals("12.01.01", s);
69: }
70:
71: public void testTimeFormat4() throws ParseException, RaplaException {
72: RaplaLocale raplaLocale = new RaplaLocaleImpl(createConfig(
73: "en", "US"));
74: Calendar cal = Calendar.getInstance(raplaLocale.getTimeZone(),
75: Locale.US);
76: cal.set(Calendar.HOUR_OF_DAY, 21);
77: cal.set(Calendar.MINUTE, 0);
78: String s = raplaLocale.formatTime(cal.getTime());
79: assertEquals("9:00 PM", s);
80: }
81:
82: }
|