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.strategy.cache.agent;
|
11
|
|
12
|
|
13
|
import static org.junit.Assert.assertNotNull;
|
14
|
|
15
|
import org.apache.commons.lang3.StringUtils;
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.junit.After;
|
18
|
import org.junit.AfterClass;
|
19
|
import org.junit.Assert;
|
20
|
import org.junit.Before;
|
21
|
import org.junit.BeforeClass;
|
22
|
import org.junit.Test;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.agent.Person;
|
25
|
|
26
|
/**
|
27
|
* @author a.mueller
|
28
|
* @since 29.09.2009
|
29
|
*/
|
30
|
public class PersonDefaultCacheStrategyTest {
|
31
|
@SuppressWarnings("unused")
|
32
|
private static final Logger logger = Logger.getLogger(PersonDefaultCacheStrategyTest.class);
|
33
|
|
34
|
private static Person person1;
|
35
|
private static Person person2;
|
36
|
private static Person person3;
|
37
|
|
38
|
/**
|
39
|
* @throws java.lang.Exception
|
40
|
*/
|
41
|
@BeforeClass
|
42
|
public static void setUpBeforeClass() throws Exception {
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* @throws java.lang.Exception
|
47
|
*/
|
48
|
@AfterClass
|
49
|
public static void tearDownAfterClass() throws Exception {
|
50
|
|
51
|
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* @throws java.lang.Exception
|
56
|
*/
|
57
|
@Before
|
58
|
public void setUp() throws Exception {
|
59
|
person1 = Person.NewInstance();
|
60
|
|
61
|
person1.setGivenName("P1FN");
|
62
|
person1.setFamilyName("P1LN");
|
63
|
person1.setPrefix("Dr1.");
|
64
|
person1.setSuffix("Suff1");
|
65
|
|
66
|
person2 = Person.NewInstance();
|
67
|
person2.setNomenclaturalTitle("P2NomT");
|
68
|
person2.setFamilyName("P2LN");
|
69
|
person2.setGivenName("P2FN");
|
70
|
person2.setSuffix("P2Suff");
|
71
|
|
72
|
person3 = Person.NewInstance(); //empty person
|
73
|
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* @throws java.lang.Exception
|
78
|
*/
|
79
|
@After
|
80
|
public void tearDown() throws Exception {
|
81
|
}
|
82
|
|
83
|
//**************************************** TESTS **************************************
|
84
|
|
85
|
/**
|
86
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy#NewInstance()}.
|
87
|
*/
|
88
|
@Test
|
89
|
public final void testNewInstance() {
|
90
|
PersonDefaultCacheStrategy cacheStrategy = PersonDefaultCacheStrategy.NewInstance();
|
91
|
assertNotNull(cacheStrategy);
|
92
|
}
|
93
|
|
94
|
@Test
|
95
|
public final void testGetNomenclaturalTitleCache(){
|
96
|
Assert.assertNotNull("person1 nomenclatural title must not to be null", person1.getNomenclaturalTitle());
|
97
|
Assert.assertEquals("Person1 nomenclatural title should be taken from titleCache", "P1LN, P.", person1.getNomenclaturalTitle());
|
98
|
person1.setSuffix(null);
|
99
|
Assert.assertEquals("Person1 title should be taken from titleCache", "P1LN, P.", person1.getNomenclaturalTitle());
|
100
|
//peson2
|
101
|
Assert.assertEquals("Person2 title should be P2NomT", "P2NomT", person2.getNomenclaturalTitle());
|
102
|
//person3
|
103
|
Assert.assertNotNull("person3 nomenclatural title must not to be null", person3.getNomenclaturalTitle());
|
104
|
Assert.assertTrue("Person3 nomenclatural title must not be empty", StringUtils.isNotBlank(person3.getNomenclaturalTitle()));
|
105
|
//don't take to serious, may be also something different, but not empty
|
106
|
Assert.assertEquals("Person3 title should start with Person#0", "Person#0", person3.getNomenclaturalTitle().substring(0, 8));
|
107
|
}
|
108
|
|
109
|
|
110
|
@Test
|
111
|
public final void testGetTitleCacheAdaptedFromOldVersion(){
|
112
|
Assert.assertNotNull("person1 title cache must not to be null", person1.getTitleCache());
|
113
|
Assert.assertEquals("Person1 title cache should be created by familyname and computed initials", "P1LN, P.", person1.getTitleCache());
|
114
|
person1.setSuffix(null);
|
115
|
Assert.assertEquals("Person1 title cache should be Dr1. P1FN P1LN", "P1LN, P.", person1.getTitleCache());
|
116
|
//peson2
|
117
|
Assert.assertEquals("Person2 title cache should be P2NomT", "P2LN, P.", person2.getTitleCache());
|
118
|
//person3
|
119
|
Assert.assertNotNull("person3 title cache must not to be null", person3.getTitleCache());
|
120
|
Assert.assertTrue("Person3 title cache must not be empty", StringUtils.isNotBlank(person3.getTitleCache()));
|
121
|
//don't take to serious, may be also something different, but not empty
|
122
|
Assert.assertEquals("Person3 title cache should start with Person#0", "Person#0", person3.getTitleCache().substring(0, 8));
|
123
|
person3.setGivenName("Klaus");
|
124
|
Assert.assertEquals("Person3 title cache should be Klaus", "K.", person3.getTitleCache());
|
125
|
}
|
126
|
|
127
|
@Test
|
128
|
public final void testGetTitleCache(){
|
129
|
Person pers = Person.NewInstance();
|
130
|
pers.setFamilyName("Last");
|
131
|
pers.setInitials("E.M.");
|
132
|
|
133
|
String expected = "Last, E.M.";
|
134
|
Assert.assertNotNull("pers title cache must not to be null", pers.getTitleCache());
|
135
|
Assert.assertEquals("pers title cache should be created by familyname and initials",
|
136
|
expected, pers.getTitleCache());
|
137
|
|
138
|
pers.setSuffix("xyz");
|
139
|
Assert.assertEquals("Suffix should not influence title cache",
|
140
|
expected, pers.getTitleCache());
|
141
|
pers.setPrefix("abc");
|
142
|
Assert.assertEquals("Prefix should not influence title cache",
|
143
|
expected, pers.getTitleCache());
|
144
|
|
145
|
pers.setGivenName("First");
|
146
|
Assert.assertEquals("Given name should not influence title cache if initials are set",
|
147
|
expected, pers.getTitleCache());
|
148
|
|
149
|
pers.setInitials(null);
|
150
|
expected = "Last, F.";
|
151
|
Assert.assertEquals("Initials should be computed from givenname if not set manually",
|
152
|
expected, pers.getTitleCache());
|
153
|
}
|
154
|
|
155
|
|
156
|
@Test
|
157
|
public final void testGetFullTitle(){
|
158
|
Assert.assertNotNull("person1 full titlemust not to be null", person1.getFullTitle());
|
159
|
Assert.assertEquals("Person1 full title should be created by elements",
|
160
|
"Dr1. P1FN P1LN Suff1", person1.getFullTitle());
|
161
|
person1.setSuffix(null);
|
162
|
Assert.assertEquals("Person1 full title should be Dr1. P1FN P1LN",
|
163
|
"Dr1. P1FN P1LN", person1.getFullTitle());
|
164
|
//peson2
|
165
|
Assert.assertEquals("Person2 full title should be P2NomT",
|
166
|
"P2FN P2LN P2Suff", person2.getFullTitle());
|
167
|
//person3
|
168
|
Assert.assertNotNull("person3 full title must not to be null",
|
169
|
person3.getFullTitle());
|
170
|
Assert.assertTrue("Person3 full title must not be empty",
|
171
|
StringUtils.isNotBlank(person3.getFullTitle()));
|
172
|
//don't take to serious, may be also something different, but not empty
|
173
|
Assert.assertEquals("Person3 full title should start with Person#0",
|
174
|
"Person#0", person3.getFullTitle().substring(0, 8));
|
175
|
person3.setGivenName("Klaus");
|
176
|
Assert.assertEquals("Person3 full title should be Klaus",
|
177
|
"Klaus", person3.getFullTitle());
|
178
|
}
|
179
|
|
180
|
@Test
|
181
|
public final void testInitialsFromGivenName(){
|
182
|
PersonDefaultCacheStrategy formatter = PersonDefaultCacheStrategy.NewInstance();
|
183
|
boolean force = true;
|
184
|
|
185
|
String givenname = null;
|
186
|
Assert.assertNull(formatter.getInitialsFromGivenName(givenname, force));
|
187
|
|
188
|
givenname = "";
|
189
|
Assert.assertEquals("", formatter.getInitialsFromGivenName(givenname, force));
|
190
|
|
191
|
givenname = " ";
|
192
|
Assert.assertEquals("We expect blanks to be trimmed", "", formatter.getInitialsFromGivenName(givenname, force));
|
193
|
|
194
|
givenname = "John Michael ";
|
195
|
Assert.assertEquals("J.M.", formatter.getInitialsFromGivenName(givenname, force));
|
196
|
|
197
|
givenname = "Walter G.";
|
198
|
Assert.assertEquals("W.G.", formatter.getInitialsFromGivenName(givenname, force));
|
199
|
|
200
|
givenname = "A.L.";
|
201
|
Assert.assertEquals("A.L.", formatter.getInitialsFromGivenName(givenname, force));
|
202
|
|
203
|
givenname = "A.Ludw. W.";
|
204
|
Assert.assertEquals("A.L.W.", formatter.getInitialsFromGivenName(givenname, force));
|
205
|
|
206
|
givenname = "A. Ludw. Norbert W.";
|
207
|
Assert.assertEquals("A.L.N.W.", formatter.getInitialsFromGivenName(givenname, force));
|
208
|
|
209
|
force = false;
|
210
|
givenname = "A. Ludw. Norbert W.";
|
211
|
Assert.assertEquals("A.Ludw.N.W.", formatter.getInitialsFromGivenName(givenname, force));
|
212
|
|
213
|
givenname = "W.-H.";
|
214
|
Assert.assertEquals("W.-H.", formatter.getInitialsFromGivenName(givenname, force));
|
215
|
givenname = "W.-Henning";
|
216
|
Assert.assertEquals("W.-H.", formatter.getInitialsFromGivenName(givenname, force));
|
217
|
givenname = "W.-Henn.";
|
218
|
Assert.assertEquals("W.-Henn.", formatter.getInitialsFromGivenName(givenname, force));
|
219
|
givenname = "Wolf-Henning";
|
220
|
Assert.assertEquals("W.-H.", formatter.getInitialsFromGivenName(givenname, force));
|
221
|
givenname = "Wolf\u2013 Henning";
|
222
|
Assert.assertEquals("W.\u2013H.", formatter.getInitialsFromGivenName(givenname, force));
|
223
|
|
224
|
|
225
|
givenname = "W";
|
226
|
Assert.assertEquals("W.", formatter.getInitialsFromGivenName(givenname, force));
|
227
|
|
228
|
givenname = "W K";
|
229
|
Assert.assertEquals("W.K.", formatter.getInitialsFromGivenName(givenname, force));
|
230
|
|
231
|
givenname = "WK";
|
232
|
Assert.assertEquals("W.K.", formatter.getInitialsFromGivenName(givenname, force));
|
233
|
|
234
|
givenname = "WKH";
|
235
|
Assert.assertEquals("W.K.H.", formatter.getInitialsFromGivenName(givenname, force));
|
236
|
|
237
|
|
238
|
//force
|
239
|
force = true;
|
240
|
givenname = "W.-H.";
|
241
|
Assert.assertEquals("W.-H.", formatter.getInitialsFromGivenName(givenname, force));
|
242
|
givenname = "W.-Henning";
|
243
|
Assert.assertEquals("W.-H.", formatter.getInitialsFromGivenName(givenname, force));
|
244
|
givenname = "W.-Henn.";
|
245
|
Assert.assertEquals("W.-H.", formatter.getInitialsFromGivenName(givenname, force));
|
246
|
givenname = "Wolf-Henning";
|
247
|
Assert.assertEquals("W.-H.", formatter.getInitialsFromGivenName(givenname, force));
|
248
|
|
249
|
givenname = "W";
|
250
|
Assert.assertEquals("W.", formatter.getInitialsFromGivenName(givenname, force));
|
251
|
|
252
|
givenname = "W K";
|
253
|
Assert.assertEquals("W.K.", formatter.getInitialsFromGivenName(givenname, force));
|
254
|
|
255
|
givenname = "WK";
|
256
|
Assert.assertEquals("W.K.", formatter.getInitialsFromGivenName(givenname, force));
|
257
|
|
258
|
givenname = "WKH";
|
259
|
Assert.assertEquals("W.K.H.", formatter.getInitialsFromGivenName(givenname, force));
|
260
|
|
261
|
force = false;
|
262
|
givenname = "Pe. Y.";
|
263
|
Assert.assertEquals("Pe.Y.", formatter.getInitialsFromGivenName(givenname, force));
|
264
|
|
265
|
//brackets
|
266
|
force = true;
|
267
|
givenname = "Constantin (Konstantin) Georg Alexander";
|
268
|
Assert.assertEquals("C.G.A.", formatter.getInitialsFromGivenName(givenname, force));
|
269
|
givenname = "Franz (Joseph Andreas Nicolaus)";
|
270
|
Assert.assertEquals("F.", formatter.getInitialsFromGivenName(givenname, force));
|
271
|
givenname = "Viktor V. (W.W.)";
|
272
|
Assert.assertEquals("V.V.", formatter.getInitialsFromGivenName(givenname, force));
|
273
|
givenname = "(Georg Ferdinand) Otto";
|
274
|
Assert.assertEquals("O.", formatter.getInitialsFromGivenName(givenname, force));
|
275
|
givenname = "(Sébastien-) René";
|
276
|
Assert.assertEquals("R.", formatter.getInitialsFromGivenName(givenname, force));
|
277
|
givenname = "Joyce (M.) Chismore Lewin";
|
278
|
Assert.assertEquals("J.C.L.", formatter.getInitialsFromGivenName(givenname, force));
|
279
|
givenname = "Joyce (M.) Chismore Lewin";
|
280
|
Assert.assertEquals("J.C.L.", formatter.getInitialsFromGivenName(givenname, force));
|
281
|
|
282
|
// "Robert. K." wurde auf "Robert. K." gemapped
|
283
|
|
284
|
//must not throw exception (exact result may change in future)
|
285
|
givenname = "W.-H.-";
|
286
|
Assert.assertEquals("W.-H.-", formatter.getInitialsFromGivenName(givenname, force));
|
287
|
givenname = "W.-Hennin-";
|
288
|
Assert.assertEquals("W.-H.-", formatter.getInitialsFromGivenName(givenname, force));
|
289
|
|
290
|
force = false;
|
291
|
givenname = "W.-H.-";
|
292
|
Assert.assertEquals("W.-H.-", formatter.getInitialsFromGivenName(givenname, force));
|
293
|
givenname = "W.-Hennin-";
|
294
|
Assert.assertEquals("W.-H.-", formatter.getInitialsFromGivenName(givenname, force));
|
295
|
|
296
|
}
|
297
|
|
298
|
}
|