Remove ". " from year only nom-refs
[cdmlib.git] / cdmlib-model / src / test / java / eu / etaxonomy / cdm / strategy / cache / reference / GenericDefaultCacheStrategyTest.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 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 package eu.etaxonomy.cdm.strategy.cache.reference;
11
12
13 import org.apache.log4j.Logger;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.BeforeClass;
17 import org.junit.Test;
18
19 import eu.etaxonomy.cdm.model.agent.Team;
20 import eu.etaxonomy.cdm.model.reference.IBook;
21 import eu.etaxonomy.cdm.model.reference.IGeneric;
22 import eu.etaxonomy.cdm.model.reference.Reference;
23 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
24 import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
25
26 /**
27 * @author a.mueller
28 * @date 16.06.2010
29 *
30 */
31 public class GenericDefaultCacheStrategyTest {
32 @SuppressWarnings("unused")
33 private static final Logger logger = Logger.getLogger(GenericDefaultCacheStrategyTest.class);
34
35 private static IGeneric generic1;
36 private static Team team1;
37 private static GenericDefaultCacheStrategy defaultStrategy;
38 private static final String detail1 = "55";
39
40 /**
41 * @throws java.lang.Exception
42 */
43 @BeforeClass
44 public static void setUpBeforeClass() throws Exception {
45 defaultStrategy = GenericDefaultCacheStrategy.NewInstance();
46 }
47
48 /**
49 * @throws java.lang.Exception
50 */
51 @Before
52 public void setUp() throws Exception {
53 generic1 = ReferenceFactory.newGeneric();
54 generic1.setCacheStrategy(defaultStrategy);
55 team1 = Team.NewTitledInstance("Authorteam", "TT.");
56 }
57
58 //**************************** TESTS ***********************************
59
60
61 @Test
62 public void testGetTitleCache(){
63 generic1.setTitle("auct.");
64 Assert.assertEquals("Unexpected title cache.", "auct.", generic1.getTitleCache());
65 }
66
67
68 @Test
69 public void testGetInRef(){
70 generic1.setTitle("auct.");
71 IBook book1 = ReferenceFactory.newBook();
72 book1.setTitle("My book title");
73 book1.setAuthorTeam(team1);
74 Reference<?> inRef = (Reference<?>)book1;
75 generic1.setInReference(inRef);
76 generic1.setTitleCache(null); //reset cache in case aspectJ is not enabled
77 Assert.assertEquals("Unexpected title cache.", "in Authorteam, My book title: 2", generic1.getNomenclaturalCitation("2"));
78 }
79
80 @Test
81 public void testGetInRefWithoutInRef(){
82 generic1.setTitle("My generic title");
83 generic1.setAuthorTeam(team1);
84 generic1.setTitleCache(null); //reset cache in case aspectJ is not enabled
85 Assert.assertEquals("Unexpected title cache.", "My generic title: 2", generic1.getNomenclaturalCitation("2"));
86 }
87
88 @Test
89 public void testGetTitleCache2(){
90 generic1.setTitle("Part Title");
91 IBook book1 = ReferenceFactory.newBook();
92 book1.setTitle("My book title");
93 book1.setAuthorTeam(team1);
94 Reference<?> inRef = (Reference<?>)book1;
95 generic1.setInReference(inRef);
96 generic1.setTitleCache(null); //reset cache in case aspectJ is not enabled
97 Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title", generic1.getTitleCache());
98 }
99
100 @Test
101 public void testGetTitleCacheWithoutInRef(){
102 generic1.setTitle("My generic title");
103 generic1.setAuthorTeam(team1);
104 generic1.setTitleCache(null); //reset cache in case aspectJ is not enabled
105 Assert.assertEquals("Unexpected title cache.", "Authorteam, My generic title", generic1.getTitleCache());
106 }
107
108 @Test
109 public void testAuthorOnly(){
110 generic1.setAuthorTeam(team1);
111 generic1.setTitleCache(null); //reset cache in case aspectJ is not enabled
112 Assert.assertEquals("Unexpected title cache.", "Authorteam", generic1.getTitleCache());
113 Assert.assertEquals("", generic1.getNomenclaturalCitation(null));
114 }
115
116 @Test
117 public void testYearAndAuthorOnly(){
118 generic1.setAuthorTeam(team1);
119 generic1.setDatePublished(TimePeriodParser.parseString("1792"));
120 generic1.setTitleCache(null); //reset cache in case aspectJ is not enabled
121 Assert.assertEquals("Unexpected title cache.", "Authorteam, 1792", generic1.getTitleCache());
122 Assert.assertEquals("1792", generic1.getNomenclaturalCitation(null));
123 }
124
125
126
127 }