Agent cache strategies
[cdmlib.git] / cdmlib-model / src / test / java / eu / etaxonomy / cdm / strategy / cache / agent / TeamDefaultCacheStrategyTest.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 import eu.etaxonomy.cdm.model.agent.Team;
27
28 /**
29 * @author a.mueller
30 * @created 29.09.2009
31 * @version 1.0
32 */
33 public class TeamDefaultCacheStrategyTest {
34 @SuppressWarnings("unused")
35 private static final Logger logger = Logger.getLogger(TeamDefaultCacheStrategyTest.class);
36
37 private static Team team1;
38 private static Team team2;
39 private static Team team3;
40
41 private static Person person1;
42 private static Person person2;
43 private static Person person3;
44 private static Person person4;
45
46 /**
47 * @throws java.lang.Exception
48 */
49 @BeforeClass
50 public static void setUpBeforeClass() throws Exception {
51 }
52
53 /**
54 * @throws java.lang.Exception
55 */
56 @AfterClass
57 public static void tearDownAfterClass() throws Exception {
58
59
60 }
61
62 /**
63 * @throws java.lang.Exception
64 */
65 @Before
66 public void setUp() throws Exception {
67 team1 = Team.NewInstance();
68 team2 = Team.NewInstance();
69 team3 = Team.NewInstance(); //empty team
70
71 person1 = Person.NewInstance();
72
73 person1.setFirstname("P1FN");
74 person1.setLastname("P1LN");
75 person1.setPrefix("Dr1.");
76 person1.setSuffix("Suff1");
77
78 person2 = Person.NewInstance();
79 person2.setNomenclaturalTitle("P2NomT");
80 person2.setLastname("P2LN");
81 person2.setFirstname("P2FN");
82 person2.setSuffix("P2Suff");
83
84 person3 = Person.NewInstance();
85 person3.setNomenclaturalTitle("P3NomT");
86
87
88 person4 = Person.NewInstance(); //empty person
89
90 team1.addTeamMember(person1);
91 team2.addTeamMember(person2);
92 team2.addTeamMember(person1);
93 team2.addTeamMember(person3);
94
95
96
97 }
98
99 /**
100 * @throws java.lang.Exception
101 */
102 @After
103 public void tearDown() throws Exception {
104 }
105
106 //**************************************** TESTS **************************************
107
108 /**
109 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy#NewInstance()}.
110 */
111 @Test
112 public final void testNewInstance() {
113 TeamDefaultCacheStrategy cacheStrategy = TeamDefaultCacheStrategy.NewInstance();
114 assertNotNull(cacheStrategy);
115 }
116
117 @Test
118 public final void testGetNomenclaturalTitleCache(){
119 Assert.assertNotNull("team1 nomenclatural title must not to be null", team1.getNomenclaturalTitle());
120 Assert.assertEquals("team1 nomenclatural title should be created by elements", "Dr1. P1FN P1LN Suff1", team1.getNomenclaturalTitle());
121 person1.setSuffix(null);
122 Assert.assertEquals("team1 nomenclatural title should be Dr1. P1FN P1LN", "Dr1. P1FN P1LN", team1.getNomenclaturalTitle());
123 //peson2
124 Assert.assertEquals("team2 nomenclatural title should be 'P2NomT & Dr1. P1FN P1LN & P3NomT'", "P2NomT & Dr1. P1FN P1LN & P3NomT", team2.getNomenclaturalTitle());
125 //person3
126 Assert.assertNotNull("team3 nomenclatural title must not to be null", team3.getNomenclaturalTitle());
127 Assert.assertTrue("team3 nomenclatural title must not be empty", CdmUtils.isNotEmpty(team3.getNomenclaturalTitle()));
128 //don't take to serious, may be also something different, but not empty
129 Assert.assertEquals("team3 nomenclatural title should be empty team replacement string", TeamDefaultCacheStrategy.EMPTY_TEAM, team3.getNomenclaturalTitle());
130 }
131
132
133 @Test
134 public final void testGetTitleCache(){
135 Assert.assertNotNull("team1 title cache must not to be null", team1.getTitleCache());
136 Assert.assertEquals("team1 title cache should be created by elements", "Dr1. P1FN P1LN Suff1", team1.getTitleCache());
137 person1.setSuffix(null);
138 Assert.assertEquals("team1 title cache should be Dr1. P1FN P1LN", "Dr1. P1FN P1LN", team1.getTitleCache());
139 //peson2
140 Assert.assertEquals("team2 title cache should be 'P2FN P2LN P2Suff & Dr1. P1FN P1LN & P3NomT'", "P2FN P2LN P2Suff & Dr1. P1FN P1LN & P3NomT", team2.getTitleCache());
141 //person3
142 Assert.assertNotNull("team3 title cache must not to be null", team3.getTitleCache());
143 Assert.assertTrue("team3 title cache must not be empty", CdmUtils.isNotEmpty(team3.getTitleCache()));
144 //don't take to serious, may be also something different, but not empty
145 Assert.assertEquals("team3 title cache should should be empty team replacement string", TeamDefaultCacheStrategy.EMPTY_TEAM, team3.getTitleCache());
146
147 }
148
149
150 }