fix #7915 move datePublished to subinterface IWithAuthorAndDate, remove from IJournal...
[cdmlib.git] / cdmlib-model / src / test / java / eu / etaxonomy / cdm / strategy / cache / reference / DefaultReferenceCacheStrategyTest.java
1 /**
2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.strategy.cache.reference;
10
11
12 import static org.junit.Assert.assertEquals;
13
14 import java.net.URI;
15
16 import org.apache.log4j.Logger;
17 import org.joda.time.DateTime;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.BeforeClass;
21 import org.junit.Test;
22
23 import eu.etaxonomy.cdm.model.agent.Person;
24 import eu.etaxonomy.cdm.model.agent.Team;
25 import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
26 import eu.etaxonomy.cdm.model.reference.IArticle;
27 import eu.etaxonomy.cdm.model.reference.IBook;
28 import eu.etaxonomy.cdm.model.reference.IBookSection;
29 import eu.etaxonomy.cdm.model.reference.ICdDvd;
30 import eu.etaxonomy.cdm.model.reference.IDatabase;
31 import eu.etaxonomy.cdm.model.reference.IGeneric;
32 import eu.etaxonomy.cdm.model.reference.IJournal;
33 import eu.etaxonomy.cdm.model.reference.IWebPage;
34 import eu.etaxonomy.cdm.model.reference.Reference;
35 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
36 import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
37
38 /**
39 * Copy of {@link ArticleDefaultCacheStrategyTest} to test the {@link DefaultReferenceCacheStrategy}.
40 *
41 * @author a.mueller
42 * @since 25.05.2016
43 *
44 */
45 public class DefaultReferenceCacheStrategyTest {
46 @SuppressWarnings("unused")
47 private static final Logger logger = Logger.getLogger(DefaultReferenceCacheStrategyTest.class);
48
49 //article
50 private static IArticle article1;
51 private static IJournal journal1;
52 private static Team articleTeam1;
53 private static Team articleTeam2;
54
55 //book // book section
56 private static IBook book1;
57 private static Team bookTeam1;
58
59 //book section
60 private static IBookSection bookSection1;
61 private static Team sectionTeam1;
62
63 //CdDvd
64 private static Reference cdDvd;
65 private static String cdDvdTitle;
66
67 //Generic
68 private static IGeneric generic1;
69 private static Team genericTeam1;
70
71 //WebPage
72 private static IWebPage webPage1;
73 private static Team webPageTeam1;
74
75 //common
76 private static DefaultReferenceCacheStrategy defaultStrategy;
77 private static final String detail1 = "55";
78
79 /**
80 * @throws java.lang.Exception
81 */
82 @BeforeClass
83 public static void setUpBeforeClass() throws Exception {
84 defaultStrategy = DefaultReferenceCacheStrategy.NewInstance();
85 }
86
87 /**
88 * @throws java.lang.Exception
89 */
90 @Before
91 public void setUp() throws Exception {
92 //article
93 article1 = ReferenceFactory.newArticle();
94 article1.setCacheStrategy(defaultStrategy);
95 journal1 = ReferenceFactory.newJournal();
96 journal1.setCacheStrategy(defaultStrategy);
97 articleTeam1 = Team.NewInstance();
98 articleTeam2 = Team.NewInstance();
99 articleTeam1.setTitleCache("Team1", true);
100 articleTeam1.setNomenclaturalTitle("T.", true);
101 articleTeam2.setTitleCache("Team2", true);
102 articleTeam2.setNomenclaturalTitle("TT.", true);
103
104 //book / section
105 book1 = ReferenceFactory.newBook();
106 book1.setCacheStrategy(defaultStrategy);
107 bookTeam1 = Team.NewTitledInstance("Book Author", "TT.");
108 bookSection1 = ReferenceFactory.newBookSection();
109 sectionTeam1 = Team.NewTitledInstance("Section Author", "T.");
110
111 //CdDvd
112 cdDvd = ReferenceFactory.newCdDvd();
113 cdDvd.setCacheStrategy(defaultStrategy);
114 cdDvdTitle = "A nice CD title";
115 cdDvd.setTitle(cdDvdTitle);
116 String publisher = "An ugly publisher"; //not yet implemented
117 String place = "A beutiful place"; //not yet implemented
118 VerbatimTimePeriod publicationDate = VerbatimTimePeriod.NewVerbatimInstance(1999, 2001);
119 cdDvd.setDatePublished(publicationDate);
120
121 //Generic
122 generic1 = ReferenceFactory.newGeneric();
123 generic1.setCacheStrategy(defaultStrategy);
124 genericTeam1 = Team.NewTitledInstance("Authorteam", "AT.");
125
126 //WebPage
127 webPage1 = ReferenceFactory.newWebPage();
128 webPage1.setCacheStrategy(defaultStrategy);
129 webPageTeam1 = Team.NewTitledInstance("Authorteam, D.", "AT.");
130 }
131
132 //**************************** TESTS ***********************************
133
134
135 @Test
136 public void testArticleGetTitleCache(){
137 journal1.setTitle("My journal");
138 ((Reference)journal1).setAuthorship(articleTeam2); //incorrect use anyway
139 article1.setTitle("My article");
140 article1.setInJournal(journal1);
141 article1.setAuthorship(articleTeam1);
142 article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
143 Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
144
145 article1.setInJournal(null);
146 //TODO should not be needed here
147 article1.setTitleCache(null, false);
148 Assert.assertEquals("Team1, My article in " + DefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
149 }
150
151 @Test
152 //This test is just to show that setInJournal(null) now resets caches #1815
153 public void testArticleGetTitleCache2(){
154 journal1.setTitle("My journal");
155 ((Reference)journal1).setAuthorship(articleTeam2);
156 article1.setTitle("My article");
157 article1.setInJournal(journal1);
158 article1.setAuthorship(articleTeam1);
159 article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
160 Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
161
162 article1.setInJournal(null);
163 Assert.assertEquals("Team1, My article in " + DefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
164 }
165
166 //#6496
167 @Test
168 public void testArticleGetTitleCacheWithPages(){
169 journal1.setTitle("My journal");
170 ((Reference)journal1).setAuthorship(articleTeam2);
171 article1.setTitle("My article");
172 article1.setInJournal(journal1);
173 article1.setAuthorship(articleTeam1);
174 article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
175 Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
176 article1.setPages("12-22");
177 Assert.assertEquals("Team1, My article in My journal: 12-22. 1975", article1.getTitleCache());
178
179 article1.setVolume("7");
180 Assert.assertEquals("Team1, My article in My journal 7: 12-22. 1975", article1.getTitleCache());
181
182 article1.setSeriesPart("II");
183 //TODO unclear if punctuation is correct
184 Assert.assertEquals("Team1, My article in My journal, II, 7: 12-22. 1975", article1.getTitleCache());
185 }
186
187 @Test
188 public void testArticleGetAbbrevTitleCache(){
189
190 journal1.setTitle("My journal");
191 journal1.setTitle("M. Journ.");
192 ((Reference)journal1).setAuthorship(articleTeam2);
193 article1.setTitle("My article");
194 article1.setInJournal(journal1);
195 article1.setAuthorship(articleTeam1);
196 article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
197 article1.setAbbrevTitle("M. Art.");
198 Assert.assertEquals("T., M. Art. in M. Journ. 1975", article1.getAbbrevTitleCache()); //double dot may be removed in future #3645
199
200 article1.setInJournal(null);
201 //TODO should not be needed here
202 article1.setTitleCache(null, false);
203 Assert.assertEquals("Team1, My article in " + DefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
204 }
205
206 @Test
207 public void testArticleGetNomenclaturalCitation(){
208 journal1.setTitle("My journal");
209 journal1.setTitle("M. J.");
210 ((Reference)journal1).setAuthorship(articleTeam2);
211 article1.setTitle("My article");
212 article1.setInJournal(journal1);
213 article1.setAuthorship(articleTeam1);
214 article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
215 Assert.assertEquals("in M. J.: 55. 1975", article1.getNomenclaturalCitation(detail1));
216
217 article1.setVolume("22");
218 Assert.assertEquals("in M. J. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
219 article1.setSeriesPart("ser. 11");
220 Assert.assertEquals("in M. J., ser. 11, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
221
222 article1.setPages("33"); //#6496 don't show pages in nomencl. citation
223 Assert.assertEquals("in M. J., ser. 11, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
224 }
225
226 /**
227 * After ser. , sect. , abt. we want to have a comma, if there is not yet one following anyway
228 */
229 @Test
230 public void testArticleGetNomenclaturalCitationSerSectAbt(){
231 article1.setInJournal(journal1);
232 article1.setVolume("22");
233 journal1.setAbbrevTitle("J. Pl. Eur.");
234 ((Reference)journal1).setAuthorship(articleTeam2);
235 article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
236 //no ser, sect, abt
237 Assert.assertEquals("in J. Pl. Eur. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
238 //ser
239 journal1.setAbbrevTitle("J. Pl. Eur., ser. 3");
240 Assert.assertEquals("in J. Pl. Eur., ser. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
241 journal1.setAbbrevTitle("J. Pl. Eur., Ser. 3");
242 Assert.assertEquals("in J. Pl. Eur., Ser. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
243 journal1.setAbbrevTitle("J. Pl. Eur., ser. 3, s.n.");
244 Assert.assertEquals("in J. Pl. Eur., ser. 3, s.n. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
245 //sect
246 journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
247 Assert.assertEquals("in J. Pl. Eur., sect. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
248 journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3");
249 Assert.assertEquals("in J. Pl. Eur., Sect. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
250 journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3, something");
251 Assert.assertEquals("in J. Pl. Eur., Sect. 3, something 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
252 //abt
253 journal1.setAbbrevTitle("J. Pl. Eur., abt. 3");
254 Assert.assertEquals("in J. Pl. Eur., abt. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
255 journal1.setAbbrevTitle("J. Pl. Eur., Abt. 3");
256 Assert.assertEquals("in J. Pl. Eur., Abt. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
257 journal1.setAbbrevTitle("J. Pl. Eur., abt. 3, no comma");
258 Assert.assertEquals("in J. Pl. Eur., abt. 3, no comma 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
259
260 journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
261 article1.setSeriesPart("1");
262 Assert.assertEquals("in J. Pl. Eur., sect. 3, ser. 1, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
263 article1.setSeriesPart("Series 2");
264 Assert.assertEquals("in J. Pl. Eur., sect. 3, Series 2, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
265 }
266
267
268
269 @Test
270 public void testArticleGetTitleWithoutYearAndAuthor(){
271 journal1.setTitle("My journal");
272 ((Reference)journal1).setAuthorship(articleTeam2);
273 article1.setTitle("My article");
274 article1.setInJournal(journal1);
275 article1.setAuthorship(articleTeam1);
276 article1.setVolume("34");
277 article1.setSeriesPart("ser. 2");
278 article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
279 //FIXME removed for new formatter
280 // Assert.assertEquals("in My journal, ser. 2, 34", defaultStrategy.getTitleWithoutYearAndAuthor((Reference)article1, false));
281 }
282
283 @Test
284 public void testArticleOldExistingBugs(){
285 journal1.setTitle("Univ. Calif. Publ. Bot.");
286 ((Reference)journal1).setAuthorship(null);
287
288 Team articleAuthor = Team.NewTitledInstance("Babc. & Stebbins", "Babc. & Stebbins");
289 article1.setTitle("");
290 article1.setInJournal(journal1);
291 article1.setAuthorship(articleAuthor);
292 article1.setVolume("18");
293 article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1943));
294 Assert.assertEquals("Babc. & Stebbins in Univ. Calif. Publ. Bot. 18. 1943", defaultStrategy.getTitleCache((Reference)article1));
295 }
296
297 // ******************* Book ****************************/
298
299 @Test
300 public void testBookGetTitleCache0(){
301 book1.setTitle("My book");
302 book1.setAuthorship(bookTeam1);
303 book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
304 Assert.assertEquals("Unexpected title cache.", "Book Author, My book. 1975", book1.getTitleCache());
305
306 book1.setTitleCache(null, false);
307 book1.setEdition("ed. 3");
308 Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3. 1975", book1.getTitleCache());
309
310 VerbatimTimePeriod newDatePublished = TimePeriodParser.parseStringVerbatim("1975 (after Aug.)");
311 book1.setDatePublished(newDatePublished);
312 book1.setTitleCache(null, false);
313 //TODO this behaviour needs to be discussed. Maybe better the complete date published string should be returned.
314 Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3", book1.getTitleCache());
315
316 book1.setPages("1-405");
317 Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3: 1-405", book1.getTitleCache());
318
319 }
320
321
322 @Test
323 public void testBookGetTitleCache1(){
324 //series
325 IBook book1 = ReferenceFactory.newBook();
326 book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
327 book1.setSeriesPart("1");
328 book1.setVolume("Fasc. 11");
329 book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
330 Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11. 1955", book1.getTitleCache());
331 Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
332 }
333
334
335 @Test
336 public void testBookGetTitleCache2(){
337 //series
338 IBook book1 = ReferenceFactory.newBook();
339 book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
340 book1.setVolume("Fasc. 11");
341 book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
342 Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11. 1955", book1.getTitleCache());
343 Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
344 book1.setSeriesPart("1");
345 Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
346 }
347
348 @Test
349 public void testBookGetNomenclaturalCitation(){
350 book1.setTitle("My book");
351 book1.setAuthorship(bookTeam1);
352 book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
353 Assert.assertEquals("My book: 55. 1975", book1.getNomenclaturalCitation(detail1));
354 book1.setAbbrevTitle("Analect. Bot.");
355 Assert.assertEquals("Analect. Bot. 1975", book1.getNomenclaturalCitation(null));
356 }
357
358 // ***************************** Book Section ************************/
359
360 @Test
361 public void testBookSectionGetTitleCache(){
362 book1.setTitle("My book");
363 book1.setAuthorship(bookTeam1);
364 bookSection1.setTitle("My chapter");
365 bookSection1.setInBook(book1);
366 bookSection1.setAuthorship(sectionTeam1);
367 book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
368 Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1.getTitleCache());
369 book1.setDatePublished((VerbatimTimePeriod)null);
370 bookSection1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1976));
371 bookSection1.setTitleCache(null, false);
372 book1.setTitleCache(null, false);
373 Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
374 book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1977));
375 bookSection1.setTitleCache(null, false);
376 book1.setTitleCache(null, false);
377 Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
378 bookSection1.setTitleCache(null, false);
379 book1.setTitleCache(null, false);
380 book1.setSeriesPart("2");
381 Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book, ser. 2. 1976", bookSection1.getTitleCache());
382
383 //FIXME #6496
384 // bookSection1.setPages("33-38");
385 // bookSection1.setTitleCache(null);
386 // Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book, ser. 2: 33-38. 1976", bookSection1.getTitleCache());
387
388 bookSection1.setInBook(null);
389 bookSection1.setTitleCache(null, false);
390 Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1.getTitleCache());
391
392 }
393
394 @Test
395 //This test is just to show that setInBook(null) now resets caches #1815
396 public void testBookSectionGetTitleCache2(){
397 book1.setTitle("My book");
398 book1.setAuthorship(bookTeam1);
399 bookSection1.setTitle("My chapter");
400 bookSection1.setInBook(book1);
401 bookSection1.setAuthorship(sectionTeam1);
402 book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
403 Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1.getTitleCache());
404 book1.setDatePublished((VerbatimTimePeriod)null);
405 bookSection1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1976));
406 Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
407 book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1977));
408 Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
409
410
411 bookSection1.setInBook(null);
412 Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1.getTitleCache());
413
414 }
415
416
417 @Test
418 public void testBookSectionGetNomenclaturalCitation(){
419 book1.setTitle("My book");
420 book1.setAuthorship(bookTeam1);
421 bookSection1.setTitle("My chapter");
422 bookSection1.setInBook(book1);
423 bookSection1.setAuthorship(sectionTeam1);
424 book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
425 //TODO still unclear which is correct
426 // Assert.assertEquals("in Book Author, My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
427 Assert.assertEquals("in TT., My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
428
429 book1.setSeriesPart("2");
430 Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
431 //#6496 don't show pages in nom.ref. citations
432 bookSection1.setPages("35-39");
433 Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
434
435 }
436
437 @Test
438 public void testBookSectionRealExample(){
439 Team bookTeam = Team.NewTitledInstance("Chaudhary S. A.(ed.)", "Chaudhary S. A.(ed.)");
440 IBook book = ReferenceFactory.newBook();
441 book.setTitle("Flora of the Kingdom of Saudi Arabia");
442 book.setAuthorship(bookTeam);
443 book.setVolume("2(3)");
444 book.setPlacePublished("Riyadh");
445 book.setPublisher("National Herbarium");
446 book.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(2000));
447
448 Team sectionTeam = Team.NewTitledInstance("Chaudhary S. A.", "Chaudhary S. A.");
449 IBookSection bookSection = ReferenceFactory.newBookSection();
450 bookSection.setTitle("73. Hedypnois - 87. Crepis");
451 bookSection.setInBook(book);
452 bookSection.setAuthorship(sectionTeam);
453 bookSection.setPages("222-251");
454 Assert.assertEquals("Chaudhary S. A. - 73. Hedypnois - 87. Crepis in Chaudhary S. A.(ed.), Flora of the Kingdom of Saudi Arabia 2(3). 2000", bookSection.getTitleCache());
455
456 }
457
458 @Test
459 public void testCdDvdGetTitleWithoutYearAndAuthor() {
460 String result = TitleWithoutYearAndAuthorHelper.getTitleWithoutYearAndAuthor(cdDvd, false);
461 assertEquals(cdDvdTitle, result);
462 }
463
464 //TODO missing publicationPlace and publisher has to be discussed
465 @Test
466 public void testCdDvdGetTitleCache() {
467 String result = defaultStrategy.getTitleCache(cdDvd);
468 assertEquals(cdDvdTitle + ". 1999-2001", result);
469 }
470
471 // *************************** GENERIC *****************************************/
472
473 @Test
474 public void testGenericGetTitleCache(){
475 generic1.setTitle("auct.");
476 Assert.assertEquals("Unexpected title cache.", "auct.", generic1.getTitleCache());
477 }
478
479
480 @Test
481 public void testGenericGetInRef(){
482 generic1.setTitle("auct.");
483 IBook book1 = ReferenceFactory.newBook();
484 book1.setTitle("My book title");
485 book1.setAuthorship(genericTeam1);
486 Reference inRef = (Reference)book1;
487 generic1.setInReference(inRef);
488 generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
489 //TODO author still unclear
490 // Assert.assertEquals("Unexpected title cache.", "in Authorteam, My book title: 2", generic1.getNomenclaturalCitation("2"));
491 Assert.assertEquals("Unexpected title cache.", "in AT., My book title: 2", generic1.getNomenclaturalCitation("2"));
492 }
493
494 @Test
495 public void testGenericGetInRefWithoutInRef(){
496 generic1.setTitle("My generic title");
497 generic1.setAuthorship(genericTeam1);
498 generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
499 Assert.assertEquals("Unexpected title cache.", "My generic title: 2", generic1.getNomenclaturalCitation("2"));
500 }
501
502 @Test
503 public void testGenericGetTitleCache2(){
504 generic1.setTitle("Part Title");
505 IBook book1 = ReferenceFactory.newBook();
506 book1.setTitle("My book title");
507 book1.setAuthorship(genericTeam1);
508 Reference inRef = (Reference)book1;
509 generic1.setInReference(inRef);
510 generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
511 Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title", generic1.getTitleCache());
512 }
513
514
515 @Test
516 public void testGenericGetAbbrevTitleCache(){
517 generic1.setTitle("Part Title");
518 generic1.setAbbrevTitle("Pt. Tit.");
519 generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1987"));
520 IBook book1 = ReferenceFactory.newBook();
521 book1.setTitle("My book title");
522 book1.setAbbrevTitle("My bk. tit.");
523 book1.setAuthorship(genericTeam1); //TODO handling not yet defined
524 Reference inRef = (Reference)book1;
525 generic1.setInReference(inRef);
526 generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
527 generic1.setAbbrevTitleCache(null, false); //reset cache in case aspectJ is not enabled
528 Assert.assertEquals("Unexpected abbrev title cache.", "Pt. Tit. in AT., My bk. tit. 1987", generic1.getAbbrevTitleCache());
529 Assert.assertEquals("Title cache must still be the same", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
530 //TODO author still unclear
531 // Assert.assertEquals("Unexpected nom. ref.", "in Authorteam, My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
532 Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
533 generic1.setVolume("23");
534 Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit. 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
535 generic1.setSeriesPart("ser. 11");
536 //TODO
537 // Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit., ser. 11, 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
538
539
540 //protected
541 generic1.setAbbrevTitleCache("My prot. abb. tit. in a bk.", true);
542 Assert.assertEquals("Unexpected abbrev title cache.", "My prot. abb. tit. in a bk.", generic1.getAbbrevTitleCache());
543 Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
544
545 generic1.setDatePublished((VerbatimTimePeriod)null);
546 Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(null));
547 Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(""));
548 Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44", generic1.getNomenclaturalCitation("pp. 44"));
549
550 generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1893"));
551 Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44. 1893", generic1.getNomenclaturalCitation("pp. 44"));
552
553 }
554
555 @Test
556 public void testGenericGetTitleCacheWithoutInRef(){
557 generic1.setTitle("My generic title");
558 generic1.setAuthorship(genericTeam1);
559 generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
560 Assert.assertEquals("Unexpected title cache.", "Authorteam, My generic title", generic1.getTitleCache());
561 }
562
563 @Test
564 public void testGenericAuthorOnly(){
565 generic1.setAuthorship(genericTeam1);
566 generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
567 Assert.assertEquals("Unexpected title cache.", "Authorteam", generic1.getTitleCache());
568 Assert.assertEquals("", generic1.getNomenclaturalCitation(null));
569 }
570
571 @Test
572 public void testGenericYearAndAuthorOnly(){
573 generic1.setAuthorship(genericTeam1);
574 generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1792"));
575 generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
576 Assert.assertEquals("Unexpected title cache.", "Authorteam, 1792", generic1.getTitleCache());
577 Assert.assertEquals("1792", generic1.getNomenclaturalCitation(null));
578 }
579
580 @Test
581 public void testGenericDoubleDotBeforeYear(){
582 generic1.setAuthorship(genericTeam1);
583 String detail = "sine no.";
584 generic1.setAbbrevTitle("My title");
585 generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1883-1884"));
586 generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
587 Assert.assertEquals("My title: sine no. 1883-1884", generic1.getNomenclaturalCitation(detail));
588 }
589
590 //#4338
591 @Test
592 public void testGenericMissingVolume(){
593 generic1.setTitle("My generic");
594 generic1.setAuthorship(genericTeam1);
595 generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1883-1884"));
596 generic1.setTitleCache(null, false); //reset cache in case aspectJ is not enabled
597 Assert.assertEquals("My generic: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
598 generic1.setVolume("7");
599 Assert.assertEquals("My generic 7: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
600 Assert.assertEquals("Authorteam, My generic 7. 1883-1884", generic1.getTitleCache());
601 Assert.assertEquals("AT., My generic 7. 1883-1884", generic1.getAbbrevTitleCache());
602
603 //inRef
604 Reference generic2 = ReferenceFactory.newGeneric();
605 generic2.setTitle("My InRef");
606 Person person2 = Person.NewTitledInstance("InRefAuthor");
607 generic2.setAuthorship(person2);
608 generic2.setDatePublished(TimePeriodParser.parseStringVerbatim("1885"));
609 generic1.setInReference(generic2);
610
611 //only reference has a volume
612 Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
613 // Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getTitleCache());
614 // Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getAbbrevTitleCache());
615
616 //both have a volume
617 generic2.setVolume("9"); //still unclear what should happen if you have such dirty data
618 // Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
619 // Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getTitleCache());
620 // Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getAbbrevTitleCache());
621
622 //only inref has volume
623 generic1.setVolume(null);
624 Assert.assertEquals("in InRefAuthor, My InRef 9: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
625 Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 9. 1883-1884", generic1.getTitleCache());
626 Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 9. 1883-1884", generic1.getAbbrevTitleCache());
627 }
628
629 //#3532
630 @Test
631 public void testUnexpectedNomenclaturalReferences(){
632 Reference reference;
633
634 //database
635 IDatabase database1 = ReferenceFactory.newDatabase();
636 reference = (Reference)database1;
637
638 database1.setTitle("My database");
639 //maybe we should have a trailing dot here
640 Assert.assertEquals("My database: 55", reference.getNomenclaturalCitation(detail1));
641 database1.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
642 Assert.assertEquals("My database: 55. 1998", reference.getNomenclaturalCitation(detail1));
643
644 database1.setTitleCache("Your database", true);
645 Assert.assertEquals("My database: 55. 1998", reference.getNomenclaturalCitation(detail1));
646
647 //unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
648 reference.setAbbrevTitleCache("You. Db.", true);
649 Assert.assertEquals("You. Db.: 55. 1998", reference.getNomenclaturalCitation(detail1));
650
651
652 //CD/DVD
653 ICdDvd cdDvd = ReferenceFactory.newCdDvd();
654 reference= (Reference)cdDvd;
655 cdDvd.setTitle("My Cd/Dvd");
656 //maybe we should have a trailing dot here
657 Assert.assertEquals("My Cd/Dvd: 55", reference.getNomenclaturalCitation(detail1));
658 cdDvd.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
659 Assert.assertEquals("My Cd/Dvd: 55. 1998", reference.getNomenclaturalCitation(detail1));
660
661 cdDvd.setTitleCache("Your Cd/Dvd", true);
662 Assert.assertEquals("My Cd/Dvd: 55. 1998", reference.getNomenclaturalCitation(detail1));
663
664 //unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
665 reference.setAbbrevTitleCache("You. Cd.", true);
666 Assert.assertEquals("You. Cd.: 55. 1998", reference.getNomenclaturalCitation(detail1));
667
668
669 //WebSite
670 IWebPage webPage = ReferenceFactory.newWebPage();
671 reference= (Reference)webPage;
672 webPage.setTitle("My WebPage");
673 //maybe we should have a trailing dot here
674 Assert.assertEquals("My WebPage: 55", reference.getNomenclaturalCitation(detail1));
675 webPage.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
676 Assert.assertEquals("My WebPage: 55. 1998", reference.getNomenclaturalCitation(detail1));
677
678 webPage.setTitleCache("Your WebPage", true);
679 Assert.assertEquals("My WebPage: 55. 1998", reference.getNomenclaturalCitation(detail1));
680
681 //unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
682 reference.setAbbrevTitleCache("You. WP.", true);
683 Assert.assertEquals("You. WP.: 55. 1998", reference.getNomenclaturalCitation(detail1));
684
685 //uri
686 webPage = ReferenceFactory.newWebPage();
687 reference= (Reference)webPage;
688 webPage.setUri(URI.create("http://www.abc.de"));
689 Assert.assertEquals("http://www.abc.de: 55", reference.getNomenclaturalCitation(detail1));
690
691 //TBC
692 }
693
694 // ********************************** WEB PAGE ********************************************/
695
696 @Test
697 //still preliminary, may be modified in future
698 public void testWebPageGetTitleCache(){
699 webPage1.setUri(URI.create("http://flora.huji.ac.il"));
700 Assert.assertEquals("Unexpected title cache.",
701 "http://flora.huji.ac.il",
702 webPage1.getTitleCache());
703
704 webPage1.setTitle("Flora of Israel Online");
705 webPage1.setAuthorship(webPageTeam1);
706 webPage1.setAccessed(DateTime.parse("2001-01-05"));
707 Assert.assertEquals("Unexpected title cache.",
708 "Authorteam, D., Flora of Israel Online - http://flora.huji.ac.il [accessed 2001-01-05]",
709 webPage1.getTitleCache());
710
711 }
712
713 // @Test
714 // //WebPages should usually not be used as nomencl.reference, therefore this is less important
715 // public void testWebPageGetAbbrevTitleCache(){
716 // webPage1.setTitle("auct.");
717 // Assert.assertEquals("Unexpected title cache.", "auct.", webPage1.getTitleCache());
718 // }
719
720
721 }