svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.i18n / src / test / java / org / gvsig / i18n / TestMessages.java @ 40769
History | View | Annotate | Download (4.65 KB)
1 | 40435 | jjdelcerro | /**
|
---|---|---|---|
2 | 40559 | jjdelcerro | * gvSIG. Desktop Geographic Information System.
|
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | 40435 | jjdelcerro | package org.gvsig.i18n; |
25 | |||
26 | import java.io.File; |
||
27 | import java.net.MalformedURLException; |
||
28 | import java.util.ArrayList; |
||
29 | import java.util.Locale; |
||
30 | |||
31 | import junit.framework.TestCase; |
||
32 | |||
33 | /**
|
||
34 | * @author cesar
|
||
35 | *
|
||
36 | */
|
||
37 | public class TestMessages extends TestCase { |
||
38 | |||
39 | /*
|
||
40 | * @see TestCase#setUp()
|
||
41 | */
|
||
42 | protected void setUp() throws Exception { |
||
43 | super.setUp();
|
||
44 | } |
||
45 | |||
46 | /*
|
||
47 | * @see TestCase#tearDown()
|
||
48 | */
|
||
49 | protected void tearDown() throws Exception { |
||
50 | super.tearDown();
|
||
51 | } |
||
52 | |||
53 | public void testSetPreferredLocales() { |
||
54 | setPreferredLocales(); |
||
55 | removeLocales(); |
||
56 | } |
||
57 | |||
58 | private void setPreferredLocales() { |
||
59 | ArrayList preferred = new ArrayList(); |
||
60 | preferred.add(new Locale("en")); |
||
61 | preferred.add(new Locale("es")); |
||
62 | Messages.setPreferredLocales(preferred); |
||
63 | ArrayList resultPref = Messages.getPreferredLocales();
|
||
64 | |||
65 | TestCase.assertEquals(resultPref.size(), 2);
|
||
66 | |||
67 | Locale lang1 = (Locale) resultPref.get(0); |
||
68 | TestCase.assertEquals(lang1.getLanguage(), "en");
|
||
69 | Locale lang2 = (Locale) resultPref.get(1); |
||
70 | TestCase.assertEquals(lang2.getLanguage(), "es");
|
||
71 | } |
||
72 | |||
73 | private void removeLocales() { |
||
74 | Locale lang1 = new Locale("en"); |
||
75 | Locale lang2 = new Locale("es"); |
||
76 | ArrayList resultPref = Messages.getPreferredLocales();
|
||
77 | Messages.removeLocale(lang1); |
||
78 | TestCase.assertEquals(resultPref.size(), 1);
|
||
79 | Messages.removeLocale(lang2); |
||
80 | TestCase.assertEquals(resultPref.size(), 0);
|
||
81 | } |
||
82 | |||
83 | public void testAddResourceFamily() { |
||
84 | setPreferredLocales(); |
||
85 | //this.getClass().getClassLoader().getResource("text_en.properties");
|
||
86 | |||
87 | try {
|
||
88 | Messages.addResourceFamily("text", new File("src-test/org/gvsig/i18n/dataset1/")); |
||
89 | } catch (MalformedURLException e) { |
||
90 | TestCase.fail("Fichero de recursos no encontrado");
|
||
91 | } |
||
92 | TestCase.assertEquals(5, Messages.size(new Locale("en"))); |
||
93 | TestCase.assertEquals(4,Messages.size(new Locale("es"))); |
||
94 | TestCase.assertEquals(0,Messages.size(new Locale("fr"))); |
||
95 | |||
96 | TestCase.assertEquals("OK", Messages.getText("aceptar")); |
||
97 | TestCase.assertEquals("Cancel", Messages.getText("cancelar")); |
||
98 | TestCase.assertEquals("Cascade", Messages.getText("Cascada")); |
||
99 | TestCase.assertEquals("Window", Messages.getText("ventana")); |
||
100 | TestCase.assertEquals("Debe haber al menos una ventana abierta", Messages.getText("cascada_enable")); |
||
101 | TestCase.assertEquals("Configurar", Messages.getText("Configurar")); |
||
102 | TestCase.assertEquals(null, Messages.getText("Configurar", false)); |
||
103 | |||
104 | // load another file now
|
||
105 | try {
|
||
106 | Messages.addResourceFamily("text", new File( |
||
107 | "src-test/org/gvsig/i18n/dataset2/"));
|
||
108 | } catch (MalformedURLException e) { |
||
109 | TestCase.fail("Fichero de recursos no encontrado");
|
||
110 | } |
||
111 | // check that the right amount of translations was loaded
|
||
112 | TestCase.assertEquals(7, Messages.size(new Locale("en"))); |
||
113 | TestCase.assertEquals(6, Messages.size(new Locale("es"))); |
||
114 | TestCase.assertEquals(0, Messages.size(new Locale("fr"))); |
||
115 | |||
116 | // test that keys didn't get overwritten by the new files
|
||
117 | // (only new keys should have been added for each language)
|
||
118 | TestCase.assertEquals("OK", Messages.getText("aceptar")); |
||
119 | TestCase.assertEquals("Cancel", Messages.getText("cancelar")); |
||
120 | TestCase.assertEquals("Cascade", Messages.getText("Cascada")); |
||
121 | // check the new keys
|
||
122 | TestCase.assertEquals("At least one window should be open", Messages.getText("cascada_enable")); |
||
123 | TestCase.assertEquals("Insert first corner point", Messages.getText("insert_first_point_corner")); |
||
124 | TestCase.assertEquals("Capa exportada", Messages.getText("capa_exportada")); |
||
125 | TestCase.assertEquals("Circunscrito", Messages.getText("circumscribed")); |
||
126 | |||
127 | Messages.removeResources(); |
||
128 | TestCase.assertEquals(0, Messages.size(new Locale("en"))); |
||
129 | TestCase.assertEquals(0, Messages.size(new Locale("es"))); |
||
130 | TestCase.assertEquals(0, Messages.size(new Locale("fr"))); |
||
131 | |||
132 | removeLocales(); |
||
133 | } |
||
134 | } |