svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.i18n / src / test / java / org / gvsig / i18n / TestMessages.java @ 40559
History | View | Annotate | Download (4.66 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 | /**
|
||
25 | 40435 | jjdelcerro | *
|
26 | */
|
||
27 | package org.gvsig.i18n; |
||
28 | |||
29 | import java.io.File; |
||
30 | import java.net.MalformedURLException; |
||
31 | import java.util.ArrayList; |
||
32 | import java.util.Locale; |
||
33 | |||
34 | import junit.framework.TestCase; |
||
35 | |||
36 | /**
|
||
37 | * @author cesar
|
||
38 | *
|
||
39 | */
|
||
40 | public class TestMessages extends TestCase { |
||
41 | |||
42 | /*
|
||
43 | * @see TestCase#setUp()
|
||
44 | */
|
||
45 | protected void setUp() throws Exception { |
||
46 | super.setUp();
|
||
47 | } |
||
48 | |||
49 | /*
|
||
50 | * @see TestCase#tearDown()
|
||
51 | */
|
||
52 | protected void tearDown() throws Exception { |
||
53 | super.tearDown();
|
||
54 | } |
||
55 | |||
56 | public void testSetPreferredLocales() { |
||
57 | setPreferredLocales(); |
||
58 | removeLocales(); |
||
59 | } |
||
60 | |||
61 | private void setPreferredLocales() { |
||
62 | ArrayList preferred = new ArrayList(); |
||
63 | preferred.add(new Locale("en")); |
||
64 | preferred.add(new Locale("es")); |
||
65 | Messages.setPreferredLocales(preferred); |
||
66 | ArrayList resultPref = Messages.getPreferredLocales();
|
||
67 | |||
68 | TestCase.assertEquals(resultPref.size(), 2);
|
||
69 | |||
70 | Locale lang1 = (Locale) resultPref.get(0); |
||
71 | TestCase.assertEquals(lang1.getLanguage(), "en");
|
||
72 | Locale lang2 = (Locale) resultPref.get(1); |
||
73 | TestCase.assertEquals(lang2.getLanguage(), "es");
|
||
74 | } |
||
75 | |||
76 | private void removeLocales() { |
||
77 | Locale lang1 = new Locale("en"); |
||
78 | Locale lang2 = new Locale("es"); |
||
79 | ArrayList resultPref = Messages.getPreferredLocales();
|
||
80 | Messages.removeLocale(lang1); |
||
81 | TestCase.assertEquals(resultPref.size(), 1);
|
||
82 | Messages.removeLocale(lang2); |
||
83 | TestCase.assertEquals(resultPref.size(), 0);
|
||
84 | } |
||
85 | |||
86 | public void testAddResourceFamily() { |
||
87 | setPreferredLocales(); |
||
88 | //this.getClass().getClassLoader().getResource("text_en.properties");
|
||
89 | |||
90 | try {
|
||
91 | Messages.addResourceFamily("text", new File("src-test/org/gvsig/i18n/dataset1/")); |
||
92 | } catch (MalformedURLException e) { |
||
93 | TestCase.fail("Fichero de recursos no encontrado");
|
||
94 | } |
||
95 | TestCase.assertEquals(5, Messages.size(new Locale("en"))); |
||
96 | TestCase.assertEquals(4,Messages.size(new Locale("es"))); |
||
97 | TestCase.assertEquals(0,Messages.size(new Locale("fr"))); |
||
98 | |||
99 | TestCase.assertEquals("OK", Messages.getText("aceptar")); |
||
100 | TestCase.assertEquals("Cancel", Messages.getText("cancelar")); |
||
101 | TestCase.assertEquals("Cascade", Messages.getText("Cascada")); |
||
102 | TestCase.assertEquals("Window", Messages.getText("ventana")); |
||
103 | TestCase.assertEquals("Debe haber al menos una ventana abierta", Messages.getText("cascada_enable")); |
||
104 | TestCase.assertEquals("Configurar", Messages.getText("Configurar")); |
||
105 | TestCase.assertEquals(null, Messages.getText("Configurar", false)); |
||
106 | |||
107 | // load another file now
|
||
108 | try {
|
||
109 | Messages.addResourceFamily("text", new File( |
||
110 | "src-test/org/gvsig/i18n/dataset2/"));
|
||
111 | } catch (MalformedURLException e) { |
||
112 | TestCase.fail("Fichero de recursos no encontrado");
|
||
113 | } |
||
114 | // check that the right amount of translations was loaded
|
||
115 | TestCase.assertEquals(7, Messages.size(new Locale("en"))); |
||
116 | TestCase.assertEquals(6, Messages.size(new Locale("es"))); |
||
117 | TestCase.assertEquals(0, Messages.size(new Locale("fr"))); |
||
118 | |||
119 | // test that keys didn't get overwritten by the new files
|
||
120 | // (only new keys should have been added for each language)
|
||
121 | TestCase.assertEquals("OK", Messages.getText("aceptar")); |
||
122 | TestCase.assertEquals("Cancel", Messages.getText("cancelar")); |
||
123 | TestCase.assertEquals("Cascade", Messages.getText("Cascada")); |
||
124 | // check the new keys
|
||
125 | TestCase.assertEquals("At least one window should be open", Messages.getText("cascada_enable")); |
||
126 | TestCase.assertEquals("Insert first corner point", Messages.getText("insert_first_point_corner")); |
||
127 | TestCase.assertEquals("Capa exportada", Messages.getText("capa_exportada")); |
||
128 | TestCase.assertEquals("Circunscrito", Messages.getText("circumscribed")); |
||
129 | |||
130 | Messages.removeResources(); |
||
131 | TestCase.assertEquals(0, Messages.size(new Locale("en"))); |
||
132 | TestCase.assertEquals(0, Messages.size(new Locale("es"))); |
||
133 | TestCase.assertEquals(0, Messages.size(new Locale("fr"))); |
||
134 | |||
135 | removeLocales(); |
||
136 | } |
||
137 | } |