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
|
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 = Logger.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 emptyPerson;
|
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("P1FN");
|
49
|
person1.setFamilyName("P1LN");
|
50
|
person1.setPrefix("Dr1.");
|
51
|
person1.setSuffix("Suff1");
|
52
|
|
53
|
person2 = Person.NewInstance();
|
54
|
person2.setNomenclaturalTitle("P2NomT");
|
55
|
person2.setFamilyName("P2LN");
|
56
|
person2.setGivenName("P2FN");
|
57
|
person2.setSuffix("P2Suff");
|
58
|
|
59
|
person3 = Person.NewInstance();
|
60
|
person3.setNomenclaturalTitle("P3NomT");
|
61
|
|
62
|
emptyPerson = Person.NewInstance(); //empty person
|
63
|
|
64
|
team1.addTeamMember(person1);
|
65
|
team2.addTeamMember(person2);
|
66
|
team2.addTeamMember(person1);
|
67
|
team2.addTeamMember(person3);
|
68
|
}
|
69
|
|
70
|
//**************************************** TESTS **************************************
|
71
|
|
72
|
@Test
|
73
|
public final void testNewInstance() {
|
74
|
TeamDefaultCacheStrategy cacheStrategy = TeamDefaultCacheStrategy.NewInstance();
|
75
|
assertNotNull(cacheStrategy);
|
76
|
}
|
77
|
|
78
|
@Test
|
79
|
public final void testGetNomenclaturalTitleCache(){
|
80
|
Assert.assertNotNull("team1 nomenclatural title must not to be null",
|
81
|
team1.getNomenclaturalTitle());
|
82
|
Assert.assertEquals("team1 nomenclatural title should be created by elements",
|
83
|
"P1LN, P.", team1.getNomenclaturalTitle());
|
84
|
person1.setSuffix(null);
|
85
|
Assert.assertEquals("team1 nomenclatural title should be P1LN, P.",
|
86
|
"P1LN, P.", team1.getNomenclaturalTitle());
|
87
|
//team2
|
88
|
Assert.assertEquals("team2 nomenclatural title should be 'P2NomT, P1LN, P. & P3NomT'",
|
89
|
"P2NomT, P1LN, P. & P3NomT", team2.getNomenclaturalTitle());
|
90
|
((TeamDefaultCacheStrategy)team2.getCacheStrategy()).setEtAlPosition(3);;
|
91
|
team2.setTitleCache(null);
|
92
|
Assert.assertEquals("team2 nomenclatural title should still be 'P2NomT, P1LN, P. & P3NomT' now.",
|
93
|
"P2NomT, P1LN, P. & P3NomT", team2.getNomenclaturalTitle());
|
94
|
|
95
|
//team3/empty team
|
96
|
Assert.assertNotNull("team3 nomenclatural title must not to be null",
|
97
|
team3.getNomenclaturalTitle());
|
98
|
Assert.assertTrue("team3 nomenclatural title must not be empty",
|
99
|
StringUtils.isNotBlank(team3.getNomenclaturalTitle()));
|
100
|
|
101
|
team2.setHasMoreMembers(true);
|
102
|
Assert.assertEquals("team2 nomenclatural title should be 'P2NomT, P1LN, P. & P3NomT & al.'",
|
103
|
"P2NomT, P1LN, P., P3NomT & al.", team2.getNomenclaturalTitle());
|
104
|
|
105
|
//don't take next test to serious, may be also something different, but not empty
|
106
|
Assert.assertEquals("team3 nomenclatural title should be empty team replacement string", TeamDefaultCacheStrategy.EMPTY_TEAM, team3.getNomenclaturalTitle());
|
107
|
}
|
108
|
|
109
|
@Test
|
110
|
public final void testGetTitleCache(){
|
111
|
Assert.assertNotNull("team1 title cache must not to be null",
|
112
|
team1.getTitleCache());
|
113
|
Assert.assertEquals("team1 title cache should be created by members titleCache",
|
114
|
"P1LN, P.", team1.getTitleCache());
|
115
|
person1.setSuffix(null);
|
116
|
Assert.assertEquals("team1 title cache should be P1LN, P.",
|
117
|
"P1LN, P.", team1.getTitleCache());
|
118
|
//peson2
|
119
|
Assert.assertEquals("team2 title cache should be 'P2FN P2LN P2Suff, Dr1. P1FN P1LN & P3NomT'",
|
120
|
"P2LN, P., P1LN, P. & P3NomT", team2.getTitleCache());
|
121
|
team2.setHasMoreMembers(true);
|
122
|
|
123
|
Assert.assertEquals("team2 title cache should be 'P2FN P2LN P2Suff, Dr1. P1FN P1LN, P3NomT & al.'",
|
124
|
"P2LN, P., P1LN, P., P3NomT & al.", team2.getTitleCache());
|
125
|
|
126
|
((TeamDefaultCacheStrategy)team2.getCacheStrategy()).setEtAlPosition(3);
|
127
|
team2.setHasMoreMembers(false);
|
128
|
team2.setTitleCache(null);
|
129
|
Assert.assertEquals("team2 nomenclatural title should still be 'P2LN, P., P1LN, P. & al.' now.",
|
130
|
"P2LN, P., P1LN, P. & al.", team2.getTitleCache());
|
131
|
|
132
|
//person3
|
133
|
Assert.assertNotNull("team3 title cache must not to be null",
|
134
|
team3.getTitleCache());
|
135
|
Assert.assertTrue("team3 title cache must not be empty",
|
136
|
StringUtils.isNotBlank(team3.getTitleCache()));
|
137
|
|
138
|
|
139
|
//don't take to exact, may be also something different, but not empty
|
140
|
Assert.assertEquals("team3 title cache should should be empty team replacement string",
|
141
|
TeamDefaultCacheStrategy.EMPTY_TEAM, team3.getTitleCache());
|
142
|
}
|
143
|
|
144
|
@Test
|
145
|
public final void testFullTitle(){
|
146
|
Assert.assertNotNull("team1 full title must not to be null", team1.getFullTitle());
|
147
|
Assert.assertEquals("team1 full title should be created by elements",
|
148
|
"Dr1. P1FN P1LN Suff1", team1.getFullTitle());
|
149
|
person1.setSuffix(null);
|
150
|
Assert.assertEquals("team1 full title should be Dr1. P1FN P1LN", "Dr1. P1FN P1LN",
|
151
|
team1.getFullTitle());
|
152
|
//peson2
|
153
|
Assert.assertEquals("team2 full title should be 'P2FN P2LN P2Suff, Dr1. P1FN P1LN & P3NomT'",
|
154
|
"P2FN P2LN P2Suff, Dr1. P1FN P1LN & P3NomT", team2.getFullTitle());
|
155
|
//person3
|
156
|
Assert.assertNotNull("team3 full title must not to be null",
|
157
|
team3.getFullTitle());
|
158
|
Assert.assertTrue("team3 full title must not be empty",
|
159
|
StringUtils.isNotBlank(team3.getFullTitle()));
|
160
|
|
161
|
team2.setHasMoreMembers(true);
|
162
|
Assert.assertEquals("team2 full title should be 'P2FN P2LN P2Suff, Dr1. P1FN P1LN, P3NomT & al.'",
|
163
|
"P2FN P2LN P2Suff, Dr1. P1FN P1LN, P3NomT & al.", team2.getFullTitle());
|
164
|
|
165
|
//don't take to serious, may be also something different, but not empty
|
166
|
Assert.assertEquals("team3 full title should should be empty team replacement string",
|
167
|
TeamDefaultCacheStrategy.EMPTY_TEAM, team3.getFullTitle());
|
168
|
}
|
169
|
|
170
|
@Test
|
171
|
public final void testListenersOnMembers(){
|
172
|
Assert.assertNotNull("team1 title cache must not to be null", team1.getTitleCache());
|
173
|
Assert.assertEquals("team1 title cache should be created by elements",
|
174
|
"P1LN, P.", team1.getTitleCache());
|
175
|
person1.setGivenName("O.");
|
176
|
Assert.assertEquals("team1 title cache should be P1LN, O.", "P1LN, O.", team1.getTitleCache());
|
177
|
}
|
178
|
|
179
|
}
|