1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.model.description;
|
11
|
|
12
|
import static org.junit.Assert.*;
|
13
|
|
14
|
import java.util.ArrayList;
|
15
|
import java.util.Arrays;
|
16
|
import java.util.List;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.junit.After;
|
20
|
import org.junit.AfterClass;
|
21
|
import org.junit.Before;
|
22
|
import org.junit.BeforeClass;
|
23
|
import org.junit.Test;
|
24
|
import org.springframework.beans.factory.annotation.Autowired;
|
25
|
|
26
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
27
|
import eu.etaxonomy.cdm.model.common.Language;
|
28
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
29
|
import eu.etaxonomy.cdm.model.common.MultilanguageText;
|
30
|
|
31
|
/**
|
32
|
* @author a.mueller
|
33
|
* @created 23.04.2008
|
34
|
* @version 1.0
|
35
|
*/
|
36
|
public class TextDataTest {
|
37
|
private static Logger logger = Logger.getLogger(TextDataTest.class);
|
38
|
|
39
|
|
40
|
private TextData textDataLeer;
|
41
|
private TextData textData1;
|
42
|
private TextFormat format1;
|
43
|
private LanguageString languageString1;
|
44
|
|
45
|
|
46
|
@BeforeClass
|
47
|
public static void setUpBeforeClass() {
|
48
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
49
|
vocabularyStore.initialize();
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* @throws java.lang.Exception
|
54
|
*/
|
55
|
@Before
|
56
|
public void setUp() throws Exception {
|
57
|
textDataLeer = TextData.NewInstance();
|
58
|
format1 = TextFormat.NewInstance();
|
59
|
textData1 = TextData.NewInstance("testText", Language.DEFAULT(), format1);
|
60
|
languageString1 = LanguageString.NewInstance("langText", Language.GERMAN());
|
61
|
}
|
62
|
|
63
|
/* ************************** TESTS **********************************************************/
|
64
|
|
65
|
/**
|
66
|
* Test method for {@link eu.etaxonomy.cdm.model.description.TextData#NewInstance()}.
|
67
|
*/
|
68
|
@Test
|
69
|
public void testNewInstance() {
|
70
|
assertNotNull(textDataLeer);
|
71
|
assertNotNull(textDataLeer.getMultilanguageText());
|
72
|
assertEquals(0, textDataLeer.getMultilanguageText().size());
|
73
|
assertEquals(0, textDataLeer.countLanguages());
|
74
|
assertNull(textDataLeer.getFormat());
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* Test method for {@link eu.etaxonomy.cdm.model.description.TextData#NewInstance()}.
|
79
|
*/
|
80
|
@Test
|
81
|
public void testNewInstanceStringLanguageTextFormat() {
|
82
|
assertNotNull(textData1);
|
83
|
assertNotNull(textData1.getMultilanguageText());
|
84
|
assertEquals(1, textData1.getMultilanguageText().size());
|
85
|
assertEquals(1, textData1.countLanguages());
|
86
|
LanguageString languageString = LanguageString.NewInstance("testText", Language.DEFAULT());
|
87
|
// assertEquals("testText", textData1.getMultilanguageText().getText(Language.DEFAULT()));
|
88
|
assertNotNull(textData1.getFormat());
|
89
|
assertSame(format1, textData1.getFormat());
|
90
|
}
|
91
|
|
92
|
|
93
|
/**
|
94
|
* Test method for {@link eu.etaxonomy.cdm.model.description.TextData#TextData()}.
|
95
|
*/
|
96
|
@Test
|
97
|
public void testTextData() {
|
98
|
textDataLeer = new TextData();
|
99
|
assertNotNull(textDataLeer);
|
100
|
assertNotNull(textDataLeer.getMultilanguageText());
|
101
|
assertEquals(0, textDataLeer.getMultilanguageText().size());
|
102
|
assertEquals(0, textDataLeer.countLanguages());
|
103
|
assertNull(textDataLeer.getFormat());
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* Test method for {@link eu.etaxonomy.cdm.model.description.TextData#getTexts()}.
|
108
|
*/
|
109
|
@Test
|
110
|
public void testGetText() {
|
111
|
assertNotNull(textData1.getText(Language.DEFAULT()));
|
112
|
assertNull(textDataLeer.getText(Language.DEFAULT()));
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* Test method for {@link eu.etaxonomy.cdm.model.description.TextData#getMultilanguageText()}.
|
117
|
*/
|
118
|
@Test
|
119
|
public void testGetMultilanguageText() {
|
120
|
assertNotNull(textData1.getMultilanguageText());
|
121
|
// assertEquals("testText", textData1.getMultilanguageText().getText(Language.DEFAULT()));
|
122
|
assertNotNull(textDataLeer.getMultilanguageText());
|
123
|
// assertNull(textDataLeer.getMultilanguageText().getText(Language.DEFAULT()));
|
124
|
assertEquals(0, textDataLeer.getMultilanguageText().size());
|
125
|
}
|
126
|
|
127
|
/**
|
128
|
* This test reproduces a bug in java runtime.
|
129
|
* The HashMap used to implement the MultilanguageText fails in jre1.6_11 b03 win32 to
|
130
|
* to find existing Language keys.
|
131
|
* FIXME this test fails to reproduce the bug -> integration test needed?
|
132
|
*/
|
133
|
@Test
|
134
|
public void testPreferredLanguageString() {
|
135
|
//FIXME move to integration test: List<Language> languages = termService.getLanguagesByLocale(locales.elements());
|
136
|
List<Language> preferredLanguages = Arrays.asList(new Language[]{Language.DEFAULT()});
|
137
|
assertNotNull(textData1.getPreferredLanguageString(preferredLanguages));
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* Test method for {@link eu.etaxonomy.cdm.model.description.TextData#setMultilanguageText()}.
|
142
|
*/
|
143
|
@Test
|
144
|
public void testSetMultilanguageText() {
|
145
|
MultilanguageText multilanguageText = MultilanguageText.NewInstance();
|
146
|
assertFalse(multilanguageText.equals(textData1.getMultilanguageText()));
|
147
|
|
148
|
textData1.getMultilanguageText().clear();
|
149
|
assertNotNull(textData1.getMultilanguageText());
|
150
|
assertEquals(0, textData1.getMultilanguageText().size());
|
151
|
}
|
152
|
|
153
|
/**
|
154
|
* Test method for {@link eu.etaxonomy.cdm.model.description.TextData#addText(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}.
|
155
|
*/
|
156
|
@Test
|
157
|
public void testPutTextStringLanguage() {
|
158
|
textDataLeer.putText("xx", Language.GERMAN());
|
159
|
assertNull(textDataLeer.putText("francais", Language.FRENCH()));
|
160
|
textDataLeer.putText("nothing", null);
|
161
|
textDataLeer.putText(null, Language.CHINESE());
|
162
|
assertNotNull(textDataLeer.getMultilanguageText());
|
163
|
assertEquals(4 , textDataLeer.getMultilanguageText().size());
|
164
|
assertEquals("xx", textDataLeer.putText("deutsch", Language.GERMAN()).getText() );
|
165
|
assertEquals(4 , textDataLeer.getMultilanguageText().size());
|
166
|
assertEquals("deutsch", textDataLeer.getText(Language.GERMAN()));
|
167
|
assertEquals("francais", textDataLeer.getText(Language.FRENCH()));
|
168
|
assertEquals("nothing", textDataLeer.getText(null));
|
169
|
assertEquals(null, textDataLeer.getText(Language.CHINESE()));
|
170
|
}
|
171
|
|
172
|
/**
|
173
|
* Test method for {@link eu.etaxonomy.cdm.model.description.TextData#addText(eu.etaxonomy.cdm.model.common.LanguageString)}.
|
174
|
*/
|
175
|
@Test
|
176
|
public void testPutTextLanguageString() {
|
177
|
LanguageString deutsch = LanguageString.NewInstance("xx", Language.GERMAN());
|
178
|
textDataLeer.putText(deutsch);
|
179
|
assertNull(textDataLeer.putText(LanguageString.NewInstance("francais", Language.FRENCH())));
|
180
|
textDataLeer.putText(LanguageString.NewInstance("nothing", null));
|
181
|
textDataLeer.putText(LanguageString.NewInstance(null, Language.CHINESE()));
|
182
|
assertNotNull(textDataLeer.getMultilanguageText());
|
183
|
assertEquals(4 , textDataLeer.getMultilanguageText().size());
|
184
|
assertEquals(deutsch, textDataLeer.putText(LanguageString.NewInstance("deutsch", Language.GERMAN())));
|
185
|
assertEquals(4 , textDataLeer.getMultilanguageText().size());
|
186
|
|
187
|
assertEquals("deutsch", textDataLeer.getText(Language.GERMAN()));
|
188
|
assertEquals("francais", textDataLeer.getText(Language.FRENCH()));
|
189
|
assertEquals("nothing", textDataLeer.getText(null));
|
190
|
assertEquals(null, textDataLeer.getText(Language.CHINESE()));
|
191
|
}
|
192
|
|
193
|
/**
|
194
|
* Test method for {@link eu.etaxonomy.cdm.model.description.TextData#removeText(eu.etaxonomy.cdm.model.common.Language)}.
|
195
|
*/
|
196
|
@Test
|
197
|
public void testRemoveText() {
|
198
|
assertEquals(1, textData1.countLanguages());
|
199
|
assertNull(textData1.removeText(Language.CHINESE()));
|
200
|
assertEquals(1, textData1.countLanguages());
|
201
|
LanguageString deutsch = LanguageString.NewInstance("xx", Language.GERMAN());
|
202
|
textData1.putText(deutsch);
|
203
|
textData1.putText(LanguageString.NewInstance("nothing", null));
|
204
|
assertEquals(3, textData1.countLanguages());
|
205
|
assertEquals(deutsch, textData1.removeText(Language.GERMAN()));
|
206
|
assertEquals(2, textData1.countLanguages());
|
207
|
textData1.removeText(null);
|
208
|
assertEquals(1, textData1.countLanguages());
|
209
|
}
|
210
|
|
211
|
/**
|
212
|
* Test method for {@link eu.etaxonomy.cdm.model.description.TextData#getFormat()}.
|
213
|
* Test method for {@link eu.etaxonomy.cdm.model.description.TextData#setFormat(eu.etaxonomy.cdm.model.description.TextFormat)}.
|
214
|
*/
|
215
|
@Test
|
216
|
public void testGetSetFormat() {
|
217
|
textDataLeer.setFormat(format1);
|
218
|
assertSame(format1, textDataLeer.getFormat());
|
219
|
textDataLeer.setFormat(null);
|
220
|
assertNull(textDataLeer.getFormat());
|
221
|
}
|
222
|
|
223
|
/**
|
224
|
* Test method for {@link eu.etaxonomy.cdm.model.description.TextData#countLanguages()}.
|
225
|
*/
|
226
|
@Test
|
227
|
public void testCountLanguages() {
|
228
|
assertEquals(1, textData1.countLanguages());
|
229
|
textData1.putText(LanguageString.NewInstance("nothing", null));
|
230
|
assertEquals(2, textData1.countLanguages());
|
231
|
textData1.removeText(null);
|
232
|
assertEquals(1, textData1.countLanguages());
|
233
|
textData1.removeText(Language.FRENCH());
|
234
|
assertEquals(1, textData1.countLanguages());
|
235
|
textData1.removeText(Language.DEFAULT());
|
236
|
assertEquals(0, textData1.countLanguages());
|
237
|
|
238
|
}
|
239
|
|
240
|
|
241
|
}
|