Project

General

Profile

Download (4.3 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

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

    
35
	private static Person person1;
36
	private static Person person2;
37
	private static Person person3;
38
	
39
	/**
40
	 * @throws java.lang.Exception
41
	 */
42
	@BeforeClass
43
	public static void setUpBeforeClass() throws Exception {
44
	}
45

    
46
	/**
47
	 * @throws java.lang.Exception
48
	 */
49
	@AfterClass
50
	public static void tearDownAfterClass() throws Exception {
51
		
52
		
53
	}
54

    
55
	/**
56
	 * @throws java.lang.Exception
57
	 */
58
	@Before
59
	public void setUp() throws Exception {
60
		person1 = Person.NewInstance();
61
		
62
		person1.setFirstname("P1FN");
63
		person1.setLastname("P1LN");
64
		person1.setPrefix("Dr1.");
65
		person1.setSuffix("Suff1");
66
		
67
		person2 = Person.NewInstance();
68
		person2.setNomenclaturalTitle("P2NomT");
69
		person2.setLastname("P2LN");
70
		person2.setFirstname("P2FN");
71
		person2.setSuffix("P2Suff");
72
		
73
		person3 = Person.NewInstance(); //empty person
74
		
75
	}
76

    
77
	/**
78
	 * @throws java.lang.Exception
79
	 */
80
	@After
81
	public void tearDown() throws Exception {
82
	}
83
	
84
//**************************************** TESTS **************************************
85
	
86
	/**
87
	 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy#NewInstance()}.
88
	 */
89
	@Test
90
	public final void testNewInstance() {
91
		PersonDefaultCacheStrategy cacheStrategy = PersonDefaultCacheStrategy.NewInstance();
92
		assertNotNull(cacheStrategy);
93
	}
94

    
95
	@Test
96
	public final void testGetNomenclaturalTitleCache(){
97
		Assert.assertNotNull("person1 nomenclatural title must not to be null", person1.getNomenclaturalTitle());
98
		Assert.assertEquals("Person1 nomenclatural title should be created by elements", "Dr1. P1FN P1LN Suff1", person1.getNomenclaturalTitle());
99
		person1.setSuffix(null);
100
		Assert.assertEquals("Person1 title should be Dr1. P1FN P1LN", "Dr1. P1FN P1LN", person1.getNomenclaturalTitle());
101
		//peson2
102
		Assert.assertEquals("Person2 title should be P2NomT", "P2NomT", person2.getNomenclaturalTitle());
103
		//person3
104
		Assert.assertNotNull("person3 nomenclatural title must not to be null", person3.getNomenclaturalTitle());
105
		Assert.assertTrue("Person3 nomenclatural title must not be empty", StringUtils.isNotBlank(person3.getNomenclaturalTitle()));
106
		//don't take to serious, may be also something different, but not empty
107
		Assert.assertEquals("Person3 title should start with Person#0", "Person#0", person3.getNomenclaturalTitle().substring(0, 8));
108
	}
109
	
110

    
111
	@Test
112
	public final void testGetTitleCache(){
113
		Assert.assertNotNull("person1 title cache must not to be null", person1.getTitleCache());
114
		Assert.assertEquals("Person1 title cache should be created by elements", "Dr1. P1FN P1LN Suff1", person1.getTitleCache());
115
		person1.setSuffix(null);
116
		Assert.assertEquals("Person1 title cache should be Dr1. P1FN P1LN", "Dr1. P1FN P1LN", person1.getTitleCache());
117
		//peson2
118
		Assert.assertEquals("Person2 title cache should be P2NomT", "P2FN P2LN P2Suff", person2.getTitleCache());
119
		//person3
120
		Assert.assertNotNull("person3 title cache must not to be null", person3.getTitleCache());
121
		Assert.assertTrue("Person3 title cache must not be empty", StringUtils.isNotBlank(person3.getTitleCache()));
122
		//don't take to serious, may be also something different, but not empty
123
		Assert.assertEquals("Person3 title cache should start with Person#0", "Person#0", person3.getTitleCache().substring(0, 8));
124
		person3.setFirstname("Klaus");
125
		Assert.assertEquals("Person3 title cache should be Klaus", "Klaus", person3.getTitleCache());
126
	}
127
	
128
	
129
}
(1-1/2)