root / trunk / libraries / libInternationalization / src-utils-test / org / gvsig / i18n / utils / TestUtils.java @ 13424
History | View | Annotate | Download (3.8 KB)
1 |
package org.gvsig.i18n.utils; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.IOException; |
5 |
|
6 |
import junit.framework.TestCase; |
7 |
|
8 |
/**
|
9 |
* @author cesar
|
10 |
*
|
11 |
*/
|
12 |
public class TestUtils extends TestCase { |
13 |
|
14 |
public ConfigOptions loadConfig() {
|
15 |
ConfigOptions config = new ConfigOptions();
|
16 |
config.setConfigFile("src-test"+File.separator+"org"+File.separator+"gvsig"+File.separator+"i18n"+File.separator+"utils"+File.separator+"config.xml"); |
17 |
config.load(); |
18 |
return config;
|
19 |
} |
20 |
|
21 |
public void testConfigOptions() { |
22 |
ConfigOptions config = loadConfig(); |
23 |
|
24 |
String databaseDir=null, basedir=null; |
25 |
try {
|
26 |
databaseDir = new File("test-data/database").getCanonicalPath(); |
27 |
basedir = new File("test-data").getCanonicalPath(); |
28 |
} catch (IOException e) { |
29 |
// TODO Auto-generated catch block
|
30 |
e.printStackTrace(); |
31 |
} |
32 |
|
33 |
// the values of the projects. They are pairs (dir, basename).
|
34 |
String projectValues[]={"src/appgvSIG", "otro", "sources", "src/_fwAndami", "text", "sources"}; |
35 |
for (int i=0; i<projectValues.length; i=i+3) { |
36 |
try {
|
37 |
// set the canonical path
|
38 |
projectValues[i]= new File(basedir+File.separator+projectValues[i]).getCanonicalPath(); |
39 |
} catch (IOException e) { |
40 |
// TODO Auto-generated catch block
|
41 |
e.printStackTrace(); |
42 |
} |
43 |
} |
44 |
|
45 |
TestCase.assertEquals(databaseDir, config.databaseDir); |
46 |
TestCase.assertEquals(basedir, config.defaultBaseDir); |
47 |
TestCase.assertEquals("text", config.defaultBaseName);
|
48 |
|
49 |
String languages = config.languages[0]; |
50 |
for (int i=1; i<config.languages.length; i++) { |
51 |
languages=languages+";"+config.languages[i];
|
52 |
} |
53 |
TestCase.assertEquals("ca;cs;de;en;es;eu;fr;gl;it;pt", languages);
|
54 |
|
55 |
for (int i=0; i<config.projects.size(); i=i+3) { |
56 |
Project project = (Project) config.projects.get(i); |
57 |
TestCase.assertEquals(projectValues[i], project.dir); |
58 |
TestCase.assertEquals(projectValues[i+1], project.basename);
|
59 |
TestCase.assertEquals(projectValues[i+2], project.sourceKeys);
|
60 |
} |
61 |
} |
62 |
|
63 |
public void testTranslationDatabase() { |
64 |
ConfigOptions config = loadConfig(); |
65 |
TranslationDatabase database = new TranslationDatabase(config);
|
66 |
database.load(); |
67 |
TestCase.assertEquals("A?adir Capa" , database.getTranslation("es", "Anadir_Capa")); |
68 |
TestCase.assertEquals("Add Layer" , database.getTranslation("en", "Anadir_Capa")); |
69 |
TestCase.assertEquals("Afegir Capa" , database.getTranslation("ca", "Anadir_Capa")); |
70 |
TestCase.assertEquals("Layer hinzuf?gen" , database.getTranslation("de", "Anadir_Capa")); |
71 |
TestCase.assertEquals("Ayuda" , database.getTranslation("es", "Ayuda")); |
72 |
TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe")); |
73 |
|
74 |
// add a translation
|
75 |
database.setTranslation("es", "test_case.clave_que_no_existe", "Clave que no existe"); |
76 |
// is it present now?
|
77 |
TestCase.assertEquals("Clave que no existe" , database.getTranslation("es", "test_case.clave_que_no_existe")); |
78 |
|
79 |
// remove the translation
|
80 |
database.removeTranslation("es", "test_case.clave_que_no_existe"); |
81 |
// was really removed?
|
82 |
TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe")); |
83 |
|
84 |
// add the translation again
|
85 |
database.setTranslation("es", "test_case.clave_que_no_existe", "Clave que no existe"); |
86 |
// save to disk
|
87 |
database.save(); |
88 |
// load from disk
|
89 |
database.load(); |
90 |
// is the translation still there?
|
91 |
TestCase.assertEquals("Clave que no existe" , database.getTranslation("es", "test_case.clave_que_no_existe")); |
92 |
|
93 |
// remove the translation again and save to disk
|
94 |
database.removeTranslation("es", "test_case.clave_que_no_existe"); |
95 |
TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe")); |
96 |
TestCase.assertEquals("", database.getTranslation("es", "prueba")); |
97 |
database.save(); |
98 |
} |
99 |
|
100 |
public void testKeys() { |
101 |
ConfigOptions config = loadConfig(); |
102 |
Keys keys = new Keys(config);
|
103 |
keys.load(); |
104 |
} |
105 |
|
106 |
} |