Project

General

Profile

Download (7.46 KB) Statistics
| Branch: | Tag: | Revision:
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.lang.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
import eu.etaxonomy.cdm.model.agent.Team;
26

    
27
/**
28
 * @author a.mueller
29
 * @since 29.09.2009
30
 */
31
public class TeamDefaultCacheStrategyTest {
32
	@SuppressWarnings("unused")
33
	private static final Logger logger = Logger.getLogger(TeamDefaultCacheStrategyTest.class);
34

    
35
	private static Team team1;
36
	private static Team team2;
37
	private static Team team3;
38

    
39
	private static Person person1;
40
	private static Person person2;
41
	private static Person person3;
42
	private static Person person4;
43

    
44
	/**
45
	 * @throws java.lang.Exception
46
	 */
47
	@BeforeClass
48
	public static void setUpBeforeClass() throws Exception {
49
	}
50

    
51
	/**
52
	 * @throws java.lang.Exception
53
	 */
54
	@AfterClass
55
	public static void tearDownAfterClass() throws Exception {
56

    
57

    
58
	}
59

    
60
	/**
61
	 * @throws java.lang.Exception
62
	 */
63
	@Before
64
	public void setUp() throws Exception {
65
		team1 = Team.NewInstance();
66
		team2 = Team.NewInstance();
67
		team3 = Team.NewInstance(); //empty team
68

    
69
		person1 = Person.NewInstance();
70

    
71
		person1.setFirstname("P1FN");
72
		person1.setLastname("P1LN");
73
		person1.setPrefix("Dr1.");
74
		person1.setSuffix("Suff1");
75

    
76
		person2 = Person.NewInstance();
77
		person2.setNomenclaturalTitle("P2NomT");
78
		person2.setLastname("P2LN");
79
		person2.setFirstname("P2FN");
80
		person2.setSuffix("P2Suff");
81

    
82
		person3 = Person.NewInstance();
83
		person3.setNomenclaturalTitle("P3NomT");
84

    
85

    
86
		person4 = Person.NewInstance(); //empty person
87

    
88
		team1.addTeamMember(person1);
89
		team2.addTeamMember(person2);
90
		team2.addTeamMember(person1);
91
		team2.addTeamMember(person3);
92

    
93

    
94

    
95
	}
96

    
97
	/**
98
	 * @throws java.lang.Exception
99
	 */
100
	@After
101
	public void tearDown() throws Exception {
102
	}
103

    
104
//**************************************** TESTS **************************************
105

    
106
	/**
107
	 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy#NewInstance()}.
108
	 */
109
	@Test
110
	public final void testNewInstance() {
111
		TeamDefaultCacheStrategy cacheStrategy = TeamDefaultCacheStrategy.NewInstance();
112
		assertNotNull(cacheStrategy);
113
	}
114

    
115
	@Test
116
	public final void testGetNomenclaturalTitleCache(){
117
		Assert.assertNotNull("team1 nomenclatural title must not to be null",
118
		        team1.getNomenclaturalTitle());
119
		Assert.assertEquals("team1 nomenclatural title should be created by elements",
120
		        "P1LN, P.", team1.getNomenclaturalTitle());
121
		person1.setSuffix(null);
122
		Assert.assertEquals("team1 nomenclatural title should be P1LN, P.",
123
		        "P1LN, P.", team1.getNomenclaturalTitle());
124
		//team2
125
		Assert.assertEquals("team2 nomenclatural title should be 'P2NomT, P1LN, P. & P3NomT'",
126
		        "P2NomT, P1LN, P. & P3NomT", team2.getNomenclaturalTitle());
127
        ((TeamDefaultCacheStrategy)team2.getCacheStrategy()).setEtAlPosition(3);;
128
        team2.setTitleCache(null);
129
        Assert.assertEquals("team2 nomenclatural title should still be 'P2NomT, P1LN, P. & P3NomT' now.",
130
                "P2NomT, P1LN, P. & P3NomT", team2.getNomenclaturalTitle());
131

    
132
		//team3/empty team
133
		Assert.assertNotNull("team3 nomenclatural title must not to be null",
134
		        team3.getNomenclaturalTitle());
135
		Assert.assertTrue("team3 nomenclatural title must not be empty",
136
		        StringUtils.isNotBlank(team3.getNomenclaturalTitle()));
137

    
138
		team2.setHasMoreMembers(true);
139
		Assert.assertEquals("team2 nomenclatural title should be 'P2NomT, P1LN, P. & P3NomT & al.'",
140
		        "P2NomT, P1LN, P., P3NomT & al.", team2.getNomenclaturalTitle());
141

    
142
		//don't take next test to serious, may be also something different, but not empty
143
		Assert.assertEquals("team3 nomenclatural title should be empty team replacement string", TeamDefaultCacheStrategy.EMPTY_TEAM, team3.getNomenclaturalTitle());
144
	}
145

    
146
	@Test
147
	public final void testGetTitleCache(){
148
		Assert.assertNotNull("team1 title cache must not to be null",
149
		        team1.getTitleCache());
150
		Assert.assertEquals("team1 title cache should be created by members titleCache",
151
		        "P1LN, P.", team1.getTitleCache());
152
		person1.setSuffix(null);
153
		Assert.assertEquals("team1 title cache should be P1LN, P.",
154
		        "P1LN, P.", team1.getTitleCache());
155
		//peson2
156
		Assert.assertEquals("team2 title cache should be 'P2FN P2LN P2Suff, Dr1. P1FN P1LN & P3NomT'",
157
		        "P2LN, P., P1LN, P. & P3NomT", team2.getTitleCache());
158
        team2.setHasMoreMembers(true);
159

    
160
        Assert.assertEquals("team2 title cache should be 'P2FN P2LN P2Suff, Dr1. P1FN P1LN, P3NomT & al.'",
161
                "P2LN, P., P1LN, P., P3NomT & al.", team2.getTitleCache());
162

    
163
		((TeamDefaultCacheStrategy)team2.getCacheStrategy()).setEtAlPosition(3);
164
		team2.setHasMoreMembers(false);
165
		team2.setTitleCache(null);
166
        Assert.assertEquals("team2 nomenclatural title should still be 'P2LN, P., P1LN, P. & al.' now.",
167
                "P2LN, P., P1LN, P. & al.", team2.getTitleCache());
168

    
169

    
170
		//person3
171
		Assert.assertNotNull("team3 title cache must not to be null",
172
		        team3.getTitleCache());
173
		Assert.assertTrue("team3 title cache must not be empty",
174
		        StringUtils.isNotBlank(team3.getTitleCache()));
175

    
176

    
177
		//don't take to serious, may be also something different, but not empty
178
		Assert.assertEquals("team3 title cache should should be empty team replacement string",
179
		        TeamDefaultCacheStrategy.EMPTY_TEAM, team3.getTitleCache());
180
	}
181

    
182
    @Test
183
    public final void testFullTitle(){
184
        Assert.assertNotNull("team1 full title must not to be null", team1.getFullTitle());
185
        Assert.assertEquals("team1 full title should be created by elements",
186
                "Dr1. P1FN P1LN Suff1", team1.getFullTitle());
187
        person1.setSuffix(null);
188
        Assert.assertEquals("team1 full title should be Dr1. P1FN P1LN", "Dr1. P1FN P1LN",
189
                team1.getFullTitle());
190
        //peson2
191
        Assert.assertEquals("team2 full title should be 'P2FN P2LN P2Suff, Dr1. P1FN P1LN & P3NomT'",
192
                "P2FN P2LN P2Suff, Dr1. P1FN P1LN & P3NomT", team2.getFullTitle());
193
        //person3
194
        Assert.assertNotNull("team3 full title must not to be null",
195
                team3.getFullTitle());
196
        Assert.assertTrue("team3 full title must not be empty",
197
                StringUtils.isNotBlank(team3.getFullTitle()));
198

    
199
        team2.setHasMoreMembers(true);
200
        Assert.assertEquals("team2 full title should be 'P2FN P2LN P2Suff, Dr1. P1FN P1LN, P3NomT & al.'",
201
                "P2FN P2LN P2Suff, Dr1. P1FN P1LN, P3NomT & al.", team2.getFullTitle());
202

    
203

    
204
        //don't take to serious, may be also something different, but not empty
205
        Assert.assertEquals("team3 full title should should be empty team replacement string",
206
                TeamDefaultCacheStrategy.EMPTY_TEAM, team3.getFullTitle());
207
    }
208

    
209
	@Test
210
	public final void testListenersOnMembers(){
211
		Assert.assertNotNull("team1 title cache must not to be null", team1.getTitleCache());
212
		Assert.assertEquals("team1 title cache should be created by elements",
213
		        "P1LN, P.", team1.getTitleCache());
214
		person1.setFirstname("O.");
215
		Assert.assertEquals("team1 title cache should be P1LN, O.", "P1LN, O.", team1.getTitleCache());
216
	}
217

    
218
}
(2-2/2)