Agent cache strategies
[cdmlib.git] / cdmlib-model / src / test / java / eu / etaxonomy / cdm / strategy / cache / agent / PersonDefaultCacheStrategyTest.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.cdm.strategy.cache.agent;
12
13
14 import static org.junit.Assert.assertNotNull;
15 import junit.framework.Assert;
16
17 import org.apache.log4j.Logger;
18 import org.junit.After;
19 import org.junit.AfterClass;
20 import org.junit.Before;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23
24 import eu.etaxonomy.cdm.common.CdmUtils;
25 import eu.etaxonomy.cdm.model.agent.Person;
26
27 /**
28 * @author a.mueller
29 * @created 29.09.2009
30 * @version 1.0
31 */
32 public class PersonDefaultCacheStrategyTest {
33 @SuppressWarnings("unused")
34 private static final Logger logger = Logger.getLogger(PersonDefaultCacheStrategyTest.class);
35
36 private static Person person1;
37 private static Person person2;
38 private static Person person3;
39
40 /**
41 * @throws java.lang.Exception
42 */
43 @BeforeClass
44 public static void setUpBeforeClass() throws Exception {
45 }
46
47 /**
48 * @throws java.lang.Exception
49 */
50 @AfterClass
51 public static void tearDownAfterClass() throws Exception {
52
53
54 }
55
56 /**
57 * @throws java.lang.Exception
58 */
59 @Before
60 public void setUp() throws Exception {
61 person1 = Person.NewInstance();
62
63 person1.setFirstname("P1FN");
64 person1.setLastname("P1LN");
65 person1.setPrefix("Dr1.");
66 person1.setSuffix("Suff1");
67
68 person2 = Person.NewInstance();
69 person2.setNomenclaturalTitle("P2NomT");
70 person2.setLastname("P2LN");
71 person2.setFirstname("P2FN");
72 person2.setSuffix("P2Suff");
73
74 person3 = Person.NewInstance(); //empty person
75
76 }
77
78 /**
79 * @throws java.lang.Exception
80 */
81 @After
82 public void tearDown() throws Exception {
83 }
84
85 //**************************************** TESTS **************************************
86
87 /**
88 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy#NewInstance()}.
89 */
90 @Test
91 public final void testNewInstance() {
92 PersonDefaultCacheStrategy cacheStrategy = PersonDefaultCacheStrategy.NewInstance();
93 assertNotNull(cacheStrategy);
94 }
95
96 @Test
97 public final void testGetNomenclaturalTitleCache(){
98 Assert.assertNotNull("person1 nomenclatural title must not to be null", person1.getNomenclaturalTitle());
99 Assert.assertEquals("Person1 nomenclatural title should be created by elements", "Dr1. P1FN P1LN Suff1", person1.getNomenclaturalTitle());
100 person1.setSuffix(null);
101 Assert.assertEquals("Person1 title should be Dr1. P1FN P1LN", "Dr1. P1FN P1LN", person1.getNomenclaturalTitle());
102 //peson2
103 Assert.assertEquals("Person2 title should be P2NomT", "P2NomT", person2.getNomenclaturalTitle());
104 //person3
105 Assert.assertNotNull("person3 nomenclatural title must not to be null", person3.getNomenclaturalTitle());
106 Assert.assertTrue("Person3 nomenclatural title must not be empty", CdmUtils.isNotEmpty(person3.getNomenclaturalTitle()));
107 //don't take to serious, may be also something different, but not empty
108 Assert.assertEquals("Person3 title should start with Person#0", "Person#0", person3.getNomenclaturalTitle().substring(0, 8));
109 }
110
111
112 @Test
113 public final void testGetTitleCache(){
114 Assert.assertNotNull("person1 title cache must not to be null", person1.getTitleCache());
115 Assert.assertEquals("Person1 title cache should be created by elements", "Dr1. P1FN P1LN Suff1", person1.getTitleCache());
116 person1.setSuffix(null);
117 Assert.assertEquals("Person1 title cache should be Dr1. P1FN P1LN", "Dr1. P1FN P1LN", person1.getTitleCache());
118 //peson2
119 Assert.assertEquals("Person2 title cache should be P2NomT", "P2FN P2LN P2Suff", person2.getTitleCache());
120 //person3
121 Assert.assertNotNull("person3 title cache must not to be null", person3.getTitleCache());
122 Assert.assertTrue("Person3 title cache must not be empty", CdmUtils.isNotEmpty(person3.getTitleCache()));
123 //don't take to serious, may be also something different, but not empty
124 Assert.assertEquals("Person3 title cache should start with Person#0", "Person#0", person3.getTitleCache().substring(0, 8));
125 }
126
127
128 }