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.logging.log4j.LogManager;import org.apache.logging.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
|
import eu.etaxonomy.cdm.model.agent.Team;
|
21
|
|
22
|
/**
|
23
|
* @author a.mueller
|
24
|
* @since 29.09.2009
|
25
|
*/
|
26
|
public class TeamDefaultCacheStrategyTest {
|
27
|
|
28
|
@SuppressWarnings("unused")
|
29
|
private static final Logger logger = LogManager.getLogger(TeamDefaultCacheStrategyTest.class);
|
30
|
|
31
|
private static Team team1;
|
32
|
private static Team team2;
|
33
|
private static Team team3;
|
34
|
|
35
|
private static Person person1;
|
36
|
private static Person person2;
|
37
|
private static Person person3;
|
38
|
private static Person person4;
|
39
|
|
40
|
@Before
|
41
|
public void setUp() throws Exception {
|
42
|
team1 = Team.NewInstance();
|
43
|
team2 = Team.NewInstance();
|
44
|
team3 = Team.NewInstance(); //empty team
|
45
|
|
46
|
person1 = Person.NewInstance();
|
47
|
|
48
|
person1.setGivenName("P1GN");
|
49
|
person1.setFamilyName("P1FN");
|
50
|
person1.setPrefix("Dr1.");
|
51
|
person1.setSuffix("Suff1");
|
52
|
person1.setCollectorTitle("P1CT");
|
53
|
|
54
|
person2 = Person.NewInstance();
|
55
|
person2.setNomenclaturalTitle("P2NomT");
|
56
|
person2.setFamilyName("P2FN");
|
57
|
person2.setGivenName("P2GN");
|
58
|
person2.setSuffix("P2Suff");
|
59
|
|
60
|
person3 = Person.NewInstance();
|
61
|
person3.setNomenclaturalTitle("P3NomT");
|
62
|
|
63
|
person4 = Person.NewInstance();
|
64
|
person4.setNomenclaturalTitle("P4NomT");
|
65
|
person4.setFamilyName("P4FN");
|
66
|
|
67
|
team1.addTeamMember(person1);
|
68
|
|
69
|
team2.addTeamMember(person2);
|
70
|
team2.addTeamMember(person1);
|
71
|
team2.addTeamMember(person3);
|
72
|
team2.addTeamMember(person4);
|
73
|
}
|
74
|
|
75
|
//**************************************** TESTS **************************************
|
76
|
|
77
|
@Test
|
78
|
public final void testNewInstance() {
|
79
|
TeamDefaultCacheStrategy cacheStrategy = TeamDefaultCacheStrategy.NewInstance();
|
80
|
assertNotNull(cacheStrategy);
|
81
|
}
|
82
|
|
83
|
@Test
|
84
|
public final void testGetNomenclaturalTitleCache(){
|
85
|
Assert.assertNotNull("team1 nomenclatural title must not to be null",
|
86
|
team1.getNomenclaturalTitleCache());
|
87
|
Assert.assertEquals("team1 nomenclatural title should be created by elements",
|
88
|
"P1FN, P.", team1.getNomenclaturalTitleCache());
|
89
|
person1.setSuffix(null);
|
90
|
Assert.assertEquals("team1 nomenclatural title should be P1FN, P.",
|
91
|
"P1FN, P.", team1.getNomenclaturalTitleCache());
|
92
|
|
93
|
//team2
|
94
|
Assert.assertEquals("team2 nomenclatural title should be 'P2NomT, P1FN, P., P3NomT & P4NomT'",
|
95
|
"P2NomT, P1FN, P., P3NomT & P4NomT", team2.getNomenclaturalTitleCache());
|
96
|
//more
|
97
|
team2.setHasMoreMembers(true);
|
98
|
Assert.assertEquals("team2 nomenclatural title should be 'P2NomT, P1FN, P., P3NomT, P4NomT & al.'",
|
99
|
"P2NomT, P1FN, P., P3NomT, P4NomT & al.", team2.getNomenclaturalTitleCache());
|
100
|
team2.setHasMoreMembers(false);
|
101
|
//3 members
|
102
|
team2.setCacheStrategy(TeamDefaultCacheStrategy.NewInstanceNomEtAl(3));
|
103
|
team2.setTitleCache(null, false);
|
104
|
Assert.assertEquals("team2 nomenclatural title should still be 'P2NomT, P1FN, P. & al.' now.",
|
105
|
"P2NomT, P1FN, P. & al.", team2.getNomenclaturalTitleCache());
|
106
|
//4 members
|
107
|
team2.setCacheStrategy(TeamDefaultCacheStrategy.NewInstanceNomEtAl(4));
|
108
|
team2.setTitleCache(null, false);
|
109
|
Assert.assertEquals("team2 nomenclatural title should still be 'P2NomT, P1FN, P., P3NomT & P4NomT' now.",
|
110
|
"P2NomT, P1FN, P., P3NomT & P4NomT", team2.getNomenclaturalTitleCache());
|
111
|
|
112
|
|
113
|
//team3/empty team
|
114
|
Assert.assertNotNull("team3 nomenclatural title must not to be null",
|
115
|
team3.getNomenclaturalTitleCache());
|
116
|
Assert.assertTrue("team3 nomenclatural title must not be empty",
|
117
|
StringUtils.isNotBlank(team3.getNomenclaturalTitleCache()));
|
118
|
|
119
|
//don't take next test to serious, may be also something different, but not empty
|
120
|
Assert.assertEquals("team3 nomenclatural title should be empty team replacement string", TeamDefaultCacheStrategy.EMPTY_TEAM, team3.getNomenclaturalTitleCache());
|
121
|
}
|
122
|
|
123
|
@Test
|
124
|
public final void testGetTitleCache(){
|
125
|
Assert.assertNotNull("team1 title cache must not to be null",
|
126
|
team1.getTitleCache());
|
127
|
Assert.assertEquals("team1 title cache should be created by members titleCache",
|
128
|
"P1FN, P.", team1.getTitleCache());
|
129
|
person1.setSuffix(null);
|
130
|
Assert.assertEquals("team1 title cache should be P1FN, P.",
|
131
|
"P1FN, P.", team1.getTitleCache());
|
132
|
//peson2
|
133
|
Assert.assertEquals("team2 title cache should be 'P2FN, P., P1FN, P., P3NomT & P4FN'",
|
134
|
"P2FN, P., P1FN, P., P3NomT & P4FN", team2.getTitleCache());
|
135
|
team2.setHasMoreMembers(true);
|
136
|
|
137
|
Assert.assertEquals("team2 title cache should be 'P2FN, P., P1FN, P., P3NomT, P4FN & al.'",
|
138
|
"P2FN, P., P1FN, P., P3NomT, P4FN & al.", team2.getTitleCache());
|
139
|
team2.setHasMoreMembers(false);
|
140
|
|
141
|
team2.setCacheStrategy(TeamDefaultCacheStrategy.NewInstanceTitleEtAl(3));
|
142
|
team2.setTitleCache(null, false);
|
143
|
Assert.assertEquals("team2 nomenclatural title should still be 'P2FN, P., P1FN, P. & al.' now.",
|
144
|
"P2FN, P., P1FN, P. & al.", team2.getTitleCache());
|
145
|
|
146
|
team2.setCacheStrategy(TeamDefaultCacheStrategy.NewInstanceTitleEtAl(4));
|
147
|
team2.setTitleCache(null, false);
|
148
|
Assert.assertEquals("team2 nomenclatural title should still be 'P2FN, P., P1FN, P., P3NomT & P4FN' now.",
|
149
|
"P2FN, P., P1FN, P., P3NomT & P4FN", team2.getTitleCache());
|
150
|
team2.setHasMoreMembers(true);
|
151
|
team2.setTitleCache(null, false);
|
152
|
Assert.assertEquals("team2 nomenclatural title should still be 'P2FN, P., P1FN, P., P3NomT & al.' now.",
|
153
|
"P2FN, P., P1FN, P., P3NomT & al.", team2.getTitleCache());
|
154
|
|
155
|
|
156
|
//person3
|
157
|
Assert.assertNotNull("team3 title cache must not to be null",
|
158
|
team3.getTitleCache());
|
159
|
Assert.assertTrue("team3 title cache must not be empty",
|
160
|
StringUtils.isNotBlank(team3.getTitleCache()));
|
161
|
|
162
|
//don't take to exact, may be also something different, but not empty
|
163
|
Assert.assertEquals("team3 title cache should be empty team replacement string",
|
164
|
TeamDefaultCacheStrategy.EMPTY_TEAM, team3.getTitleCache());
|
165
|
}
|
166
|
|
167
|
@Test
|
168
|
public final void testFullTitle(){
|
169
|
Assert.assertNotNull("team1 full title must not to be null", team1.getFullTitle());
|
170
|
Assert.assertEquals("team1 full title should be created by elements",
|
171
|
"Dr1. P1GN P1FN Suff1", team1.getFullTitle());
|
172
|
person1.setSuffix(null);
|
173
|
Assert.assertEquals("team1 full title should be Dr1. P1GN P1FN", "Dr1. P1GN P1FN",
|
174
|
team1.getFullTitle());
|
175
|
//team2
|
176
|
Assert.assertEquals("team2 full title should be 'P2GN P2FN P2Suff, Dr1. P1GN P1FN, P3NomT & P4FN'",
|
177
|
"P2GN P2FN P2Suff, Dr1. P1GN P1FN, P3NomT & P4FN", team2.getFullTitle());
|
178
|
team2.setHasMoreMembers(true);
|
179
|
Assert.assertEquals("team2 full title should be 'P2GN P2FN P2Suff, Dr1. P1GN P1FN, P3NomT, P4FN & al.'",
|
180
|
"P2GN P2FN P2Suff, Dr1. P1GN P1FN, P3NomT, P4FN & al.", team2.getFullTitle());
|
181
|
|
182
|
//team3
|
183
|
Assert.assertNotNull("team3 full title must not to be null",
|
184
|
team3.getFullTitle());
|
185
|
Assert.assertTrue("team3 full title must not be empty",
|
186
|
StringUtils.isNotBlank(team3.getFullTitle()));
|
187
|
|
188
|
//don't take to serious, may be also something different, but not empty
|
189
|
Assert.assertEquals("team3 full title should should be empty team replacement string",
|
190
|
TeamDefaultCacheStrategy.EMPTY_TEAM, team3.getFullTitle());
|
191
|
}
|
192
|
|
193
|
@Test
|
194
|
public final void testGetCollectorTitleCache(){
|
195
|
Assert.assertNotNull("team1 collector title cache must not to be null",
|
196
|
team1.getCollectorTitleCache());
|
197
|
Assert.assertEquals("team1 collector title cache title should be created by elements",
|
198
|
"P1CT", team1.getCollectorTitleCache());
|
199
|
person1.setSuffix(null);
|
200
|
Assert.assertEquals("team1 collector title cache should be P1FN, P.",
|
201
|
"P1CT", team1.getCollectorTitleCache());
|
202
|
|
203
|
//team2
|
204
|
Assert.assertEquals("team2 collector title cache should be 'P. P2FN, P1CT, P3NomT & P4FN'",
|
205
|
"P. P2FN, P1CT, P3NomT & P4FN", team2.getCollectorTitleCache());
|
206
|
//more
|
207
|
team2.setHasMoreMembers(true);
|
208
|
Assert.assertEquals("team2 collector title cache should be 'P. P2FN, P1CT, P3NomT, P4FN & al.'",
|
209
|
"P. P2FN, P1CT, P3NomT, P4FN & al.", team2.getCollectorTitleCache());
|
210
|
team2.setHasMoreMembers(false);
|
211
|
//3 members
|
212
|
team2.setCacheStrategy(TeamDefaultCacheStrategy.NewInstance(3));
|
213
|
team2.resetCaches();
|
214
|
Assert.assertEquals("team2 collector title cache should still be 'P. P2FN, P1CT & al.' now.",
|
215
|
"P. P2FN, P1CT & al.", team2.getCollectorTitleCache());
|
216
|
//4 members
|
217
|
team2.setCacheStrategy(TeamDefaultCacheStrategy.NewInstance(4));
|
218
|
team2.resetCaches();
|
219
|
Assert.assertEquals("team2 collector title cache should still be 'P. P2FN, P1CT, P3NomT & P4FN' now.",
|
220
|
"P. P2FN, P1CT, P3NomT & P4FN", team2.getCollectorTitleCache());
|
221
|
|
222
|
|
223
|
//team3/empty team
|
224
|
Assert.assertNotNull("team3 collector title cache must not to be null",
|
225
|
team3.getCollectorTitleCache());
|
226
|
Assert.assertTrue("team3 collector title cache must not be empty",
|
227
|
StringUtils.isNotBlank(team3.getCollectorTitleCache()));
|
228
|
|
229
|
//don't take next test to serious, may be also something different, but not empty
|
230
|
Assert.assertEquals("team3 collector title cache should be empty team replacement string", TeamDefaultCacheStrategy.EMPTY_TEAM, team3.getCollectorTitleCache());
|
231
|
}
|
232
|
|
233
|
@Test
|
234
|
public final void testListenersOnMembers(){
|
235
|
Assert.assertNotNull("team1 title cache must not to be null", team1.getTitleCache());
|
236
|
Assert.assertEquals("team1 title cache should be created by elements",
|
237
|
"P1FN, P.", team1.getTitleCache());
|
238
|
person1.setGivenName("O.");
|
239
|
Assert.assertEquals("team1 title cache should be P1FN, O.", "P1FN, O.", team1.getTitleCache());
|
240
|
}
|
241
|
}
|