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.junit.Assert;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.junit.Before;
|
17
|
import org.junit.BeforeClass;
|
18
|
import org.junit.Ignore;
|
19
|
import org.junit.Test;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.agent.Team;
|
22
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
23
|
import eu.etaxonomy.cdm.model.reference.IArticle;
|
24
|
import eu.etaxonomy.cdm.model.reference.IJournal;
|
25
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
26
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
27
|
|
28
|
/**
|
29
|
* @author a.mueller
|
30
|
* @date 16.06.2010
|
31
|
*
|
32
|
*/
|
33
|
public class ArticleDefaultCacheStrategyTest {
|
34
|
@SuppressWarnings("unused")
|
35
|
private static final Logger logger = Logger.getLogger(ArticleDefaultCacheStrategyTest.class);
|
36
|
|
37
|
private static IArticle article1;
|
38
|
private static IJournal journal1;
|
39
|
private static Team team1;
|
40
|
private static Team team2;
|
41
|
private static ArticleDefaultCacheStrategy defaultStrategy;
|
42
|
private static final String detail1 = "55";
|
43
|
|
44
|
/**
|
45
|
* @throws java.lang.Exception
|
46
|
*/
|
47
|
@BeforeClass
|
48
|
public static void setUpBeforeClass() throws Exception {
|
49
|
defaultStrategy = ArticleDefaultCacheStrategy.NewInstance();
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* @throws java.lang.Exception
|
54
|
*/
|
55
|
@Before
|
56
|
public void setUp() throws Exception {
|
57
|
article1 = ReferenceFactory.newArticle();
|
58
|
article1.setCacheStrategy(defaultStrategy);
|
59
|
journal1 = ReferenceFactory.newJournal();
|
60
|
team1 = Team.NewInstance();
|
61
|
team2 = Team.NewInstance();
|
62
|
team1.setTitleCache("Team1", true);
|
63
|
team1.setNomenclaturalTitle("T.", true);
|
64
|
team2.setTitleCache("Team2", true);
|
65
|
team2.setNomenclaturalTitle("TT.", true);
|
66
|
}
|
67
|
|
68
|
//**************************** TESTS ***********************************
|
69
|
|
70
|
|
71
|
@Test
|
72
|
public void testGetTitleCache(){
|
73
|
journal1.setTitle("My journal");
|
74
|
journal1.setAuthorTeam(team2);
|
75
|
article1.setTitle("My article");
|
76
|
article1.setInJournal(journal1);
|
77
|
article1.setAuthorTeam(team1);
|
78
|
article1.setDatePublished(TimePeriod.NewInstance(1975));
|
79
|
Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
|
80
|
|
81
|
article1.setInJournal(null);
|
82
|
//TODO should not be needed here
|
83
|
article1.setTitleCache(null);
|
84
|
Assert.assertEquals("Team1, My article in " + ArticleDefaultCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
|
85
|
}
|
86
|
|
87
|
@Ignore
|
88
|
@Test
|
89
|
//This test is just to show that there is still the title cache bug which is not
|
90
|
//set to null by setInJournal(null)
|
91
|
public void testGetTitleCache2(){
|
92
|
journal1.setTitle("My journal");
|
93
|
journal1.setAuthorTeam(team2);
|
94
|
article1.setTitle("My article");
|
95
|
article1.setInJournal(journal1);
|
96
|
article1.setAuthorTeam(team1);
|
97
|
article1.setDatePublished(TimePeriod.NewInstance(1975));
|
98
|
Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
|
99
|
|
100
|
article1.setInJournal(null);
|
101
|
Assert.assertEquals("Team1, My article in " + ArticleDefaultCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
|
102
|
}
|
103
|
|
104
|
@Test
|
105
|
public void testGetAbbrevTitleCache(){
|
106
|
|
107
|
journal1.setTitle("My journal");
|
108
|
journal1.setTitle("M. Journ.");
|
109
|
journal1.setAuthorTeam(team2);
|
110
|
article1.setTitle("My article");
|
111
|
article1.setInJournal(journal1);
|
112
|
article1.setAuthorTeam(team1);
|
113
|
article1.setDatePublished(TimePeriod.NewInstance(1975));
|
114
|
article1.setAbbrevTitle("M. Art.");
|
115
|
Assert.assertEquals("T., M. Art. in M. Journ. 1975", article1.getAbbrevTitleCache()); //double dot may be removed in future #3645
|
116
|
|
117
|
article1.setInJournal(null);
|
118
|
//TODO should not be needed here
|
119
|
article1.setTitleCache(null);
|
120
|
Assert.assertEquals("Team1, My article in " + ArticleDefaultCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
|
121
|
}
|
122
|
|
123
|
@Test
|
124
|
public void testGetNomenclaturalCitation(){
|
125
|
journal1.setTitle("My journal");
|
126
|
journal1.setAuthorTeam(team2);
|
127
|
article1.setTitle("My article");
|
128
|
article1.setInJournal(journal1);
|
129
|
article1.setAuthorTeam(team1);
|
130
|
article1.setDatePublished(TimePeriod.NewInstance(1975));
|
131
|
Assert.assertEquals("in My journal: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
132
|
}
|
133
|
|
134
|
|
135
|
@Test
|
136
|
public void testGetTitleWithoutYearAndAuthor(){
|
137
|
journal1.setTitle("My journal");
|
138
|
journal1.setAuthorTeam(team2);
|
139
|
article1.setTitle("My article");
|
140
|
article1.setInJournal(journal1);
|
141
|
article1.setAuthorTeam(team1);
|
142
|
article1.setVolume("34");
|
143
|
article1.setSeries("ser. 2");
|
144
|
article1.setDatePublished(TimePeriod.NewInstance(1975));
|
145
|
Assert.assertEquals("in My journal ser. 2, 34", defaultStrategy.getTitleWithoutYearAndAuthor((Reference<?>)article1, false));
|
146
|
}
|
147
|
|
148
|
@Test
|
149
|
public void testOldExistingBugs(){
|
150
|
journal1.setTitle("Univ. Calif. Publ. Bot.");
|
151
|
journal1.setAuthorTeam(null);
|
152
|
|
153
|
Team articleAuthor = Team.NewTitledInstance("Babc. & Stebbins", "Babc. & Stebbins");
|
154
|
article1.setTitle("");
|
155
|
article1.setInJournal(journal1);
|
156
|
article1.setAuthorTeam(articleAuthor);
|
157
|
article1.setVolume("18");
|
158
|
article1.setDatePublished(TimePeriod.NewInstance(1943));
|
159
|
Assert.assertEquals("Babc. & Stebbins in Univ. Calif. Publ. Bot. 18. 1943", defaultStrategy.getTitleCache((Reference<?>)article1));
|
160
|
}
|
161
|
|
162
|
}
|