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.old;
|
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.Ignore;
|
18
|
import org.junit.Test;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.agent.Team;
|
21
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
22
|
import eu.etaxonomy.cdm.model.reference.IArticle;
|
23
|
import eu.etaxonomy.cdm.model.reference.IJournal;
|
24
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
25
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
26
|
import eu.etaxonomy.cdm.strategy.cache.reference.NewDefaultReferenceCacheStrategy;
|
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
|
journal1 = ReferenceFactory.newJournal();
|
59
|
team1 = Team.NewInstance();
|
60
|
team2 = Team.NewInstance();
|
61
|
team1.setTitleCache("Team1", true);
|
62
|
team1.setNomenclaturalTitle("T.", true);
|
63
|
team2.setTitleCache("Team2", true);
|
64
|
team2.setNomenclaturalTitle("TT.", true);
|
65
|
}
|
66
|
|
67
|
//**************************** TESTS ***********************************
|
68
|
|
69
|
|
70
|
@Test
|
71
|
public void testGetTitleCache(){
|
72
|
journal1.setTitle("My journal");
|
73
|
journal1.setAuthorship(team2);
|
74
|
article1.setTitle("My article");
|
75
|
article1.setInJournal(journal1);
|
76
|
article1.setAuthorship(team1);
|
77
|
article1.setDatePublished(TimePeriod.NewInstance(1975));
|
78
|
Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
|
79
|
|
80
|
article1.setInJournal(null);
|
81
|
//TODO should not be needed here
|
82
|
article1.setTitleCache(null, false);
|
83
|
Assert.assertEquals("Team1, My article in " + NewDefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
|
84
|
}
|
85
|
|
86
|
@Ignore
|
87
|
@Test
|
88
|
//This test is just to show that there is still the title cache bug which is not
|
89
|
//set to null by setInJournal(null)
|
90
|
public void testGetTitleCache2(){
|
91
|
journal1.setTitle("My journal");
|
92
|
journal1.setAuthorship(team2);
|
93
|
article1.setTitle("My article");
|
94
|
article1.setInJournal(journal1);
|
95
|
article1.setAuthorship(team1);
|
96
|
article1.setDatePublished(TimePeriod.NewInstance(1975));
|
97
|
Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
|
98
|
|
99
|
article1.setInJournal(null);
|
100
|
Assert.assertEquals("Team1, My article in " + NewDefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
|
101
|
}
|
102
|
|
103
|
@Test
|
104
|
public void testGetAbbrevTitleCache(){
|
105
|
|
106
|
journal1.setTitle("My journal");
|
107
|
journal1.setTitle("M. Journ.");
|
108
|
journal1.setAuthorship(team2);
|
109
|
article1.setTitle("My article");
|
110
|
article1.setInJournal(journal1);
|
111
|
article1.setAuthorship(team1);
|
112
|
article1.setDatePublished(TimePeriod.NewInstance(1975));
|
113
|
article1.setAbbrevTitle("M. Art.");
|
114
|
Assert.assertEquals("T., M. Art. in M. Journ. 1975", article1.getAbbrevTitleCache()); //double dot may be removed in future #3645
|
115
|
|
116
|
article1.setInJournal(null);
|
117
|
//TODO should not be needed here
|
118
|
article1.setTitleCache(null, false);
|
119
|
Assert.assertEquals("Team1, My article in " + NewDefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
|
120
|
}
|
121
|
|
122
|
@Test
|
123
|
public void testGetNomenclaturalCitation(){
|
124
|
journal1.setTitle("My journal");
|
125
|
journal1.setTitle("M. J.");
|
126
|
journal1.setAuthorship(team2);
|
127
|
article1.setTitle("My article");
|
128
|
article1.setInJournal(journal1);
|
129
|
article1.setAuthorship(team1);
|
130
|
article1.setDatePublished(TimePeriod.NewInstance(1975));
|
131
|
Assert.assertEquals("in M. J.: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
132
|
|
133
|
article1.setVolume("22");
|
134
|
Assert.assertEquals("in M. J. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
135
|
article1.setSeriesPart("ser. 11");
|
136
|
Assert.assertEquals("in M. J., ser. 11, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
137
|
}
|
138
|
|
139
|
/**
|
140
|
* After ser. , sect. , abt. we want to have a comma, if there is not yet one following anyway
|
141
|
*/
|
142
|
@Test
|
143
|
public void testGetNomenclaturalCitationSerSectAbt(){
|
144
|
article1.setInJournal(journal1);
|
145
|
article1.setVolume("22");
|
146
|
journal1.setAbbrevTitle("J. Pl. Eur.");
|
147
|
journal1.setAuthorship(team2);
|
148
|
article1.setDatePublished(TimePeriod.NewInstance(1975));
|
149
|
//no ser, sect, abt
|
150
|
Assert.assertEquals("in J. Pl. Eur. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
151
|
//ser
|
152
|
journal1.setAbbrevTitle("J. Pl. Eur., ser. 3");
|
153
|
Assert.assertEquals("in J. Pl. Eur., ser. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
154
|
journal1.setAbbrevTitle("J. Pl. Eur., Ser. 3");
|
155
|
Assert.assertEquals("in J. Pl. Eur., Ser. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
156
|
journal1.setAbbrevTitle("J. Pl. Eur., ser. 3, s.n.");
|
157
|
Assert.assertEquals("in J. Pl. Eur., ser. 3, s.n. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
158
|
//sect
|
159
|
journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
|
160
|
Assert.assertEquals("in J. Pl. Eur., sect. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
161
|
journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3");
|
162
|
Assert.assertEquals("in J. Pl. Eur., Sect. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
163
|
journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3, something");
|
164
|
Assert.assertEquals("in J. Pl. Eur., Sect. 3, something 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
165
|
//abt
|
166
|
journal1.setAbbrevTitle("J. Pl. Eur., abt. 3");
|
167
|
Assert.assertEquals("in J. Pl. Eur., abt. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
168
|
journal1.setAbbrevTitle("J. Pl. Eur., Abt. 3");
|
169
|
Assert.assertEquals("in J. Pl. Eur., Abt. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
170
|
journal1.setAbbrevTitle("J. Pl. Eur., abt. 3, no comma");
|
171
|
Assert.assertEquals("in J. Pl. Eur., abt. 3, no comma 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
172
|
|
173
|
journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
|
174
|
article1.setSeriesPart("1");
|
175
|
Assert.assertEquals("in J. Pl. Eur., sect. 3, ser. 1, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
176
|
article1.setSeriesPart("Series 2");
|
177
|
Assert.assertEquals("in J. Pl. Eur., sect. 3, Series 2, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
|
178
|
}
|
179
|
|
180
|
|
181
|
|
182
|
@Test
|
183
|
public void testGetTitleWithoutYearAndAuthor(){
|
184
|
journal1.setTitle("My journal");
|
185
|
journal1.setAuthorship(team2);
|
186
|
article1.setTitle("My article");
|
187
|
article1.setInJournal(journal1);
|
188
|
article1.setAuthorship(team1);
|
189
|
article1.setVolume("34");
|
190
|
article1.setSeriesPart("ser. 2");
|
191
|
article1.setDatePublished(TimePeriod.NewInstance(1975));
|
192
|
Assert.assertEquals("in My journal, ser. 2, 34", defaultStrategy.getTitleWithoutYearAndAuthor((Reference)article1, false));
|
193
|
}
|
194
|
|
195
|
@Test
|
196
|
public void testOldExistingBugs(){
|
197
|
journal1.setTitle("Univ. Calif. Publ. Bot.");
|
198
|
journal1.setAuthorship(null);
|
199
|
|
200
|
Team articleAuthor = Team.NewTitledInstance("Babc. & Stebbins", "Babc. & Stebbins");
|
201
|
article1.setTitle("");
|
202
|
article1.setInJournal(journal1);
|
203
|
article1.setAuthorship(articleAuthor);
|
204
|
article1.setVolume("18");
|
205
|
article1.setDatePublished(TimePeriod.NewInstance(1943));
|
206
|
Assert.assertEquals("Babc. & Stebbins in Univ. Calif. Publ. Bot. 18. 1943", defaultStrategy.getTitleCache((Reference)article1));
|
207
|
}
|
208
|
|
209
|
}
|