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