Project

General

Profile

Download (32.2 KB) Statistics
| Branch: | Tag: | Revision:
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.TimePeriod;
26
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
27
import eu.etaxonomy.cdm.model.reference.IArticle;
28
import eu.etaxonomy.cdm.model.reference.IBook;
29
import eu.etaxonomy.cdm.model.reference.IBookSection;
30
import eu.etaxonomy.cdm.model.reference.ICdDvd;
31
import eu.etaxonomy.cdm.model.reference.IDatabase;
32
import eu.etaxonomy.cdm.model.reference.IGeneric;
33
import eu.etaxonomy.cdm.model.reference.IJournal;
34
import eu.etaxonomy.cdm.model.reference.IWebPage;
35
import eu.etaxonomy.cdm.model.reference.Reference;
36
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
37
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
38

    
39
/**
40
 * Copy of {@link ArticleDefaultCacheStrategyTest} to test the {@link DefaultReferenceCacheStrategy}.
41
 *
42
 * @author a.mueller
43
 * @since 25.05.2016
44
 *
45
 */
46
public class DefaultReferenceCacheStrategyTest {
47
	@SuppressWarnings("unused")
48
	private static final Logger logger = Logger.getLogger(DefaultReferenceCacheStrategyTest.class);
49

    
50
	//article
51
	private static IArticle article1;
52
	private static IJournal journal1;
53
	private static Team articleTeam1;
54
	private static Team articleTeam2;
55

    
56
	//book // book section
57
	private static IBook book1;
58
    private static Team bookTeam1;
59

    
60
    //book section
61
    private static IBookSection bookSection1;
62
    private static Team sectionTeam1;
63

    
64
    //CdDvd
65
    private static Reference cdDvd;
66
    private static String cdDvdTitle;
67

    
68
    //Generic
69
    private static IGeneric generic1;
70
    private static Team genericTeam1;
71

    
72
    //WebPage
73
    private static IWebPage webPage1;
74
    private static Team webPageTeam1;
75

    
76
	//common
77
	private static DefaultReferenceCacheStrategy defaultStrategy;
78
	private static final String detail1 = "55";
79

    
80
	/**
81
	 * @throws java.lang.Exception
82
	 */
83
	@BeforeClass
84
	public static void setUpBeforeClass() throws Exception {
85
		defaultStrategy = DefaultReferenceCacheStrategy.NewInstance();
86
	}
87

    
88
	/**
89
	 * @throws java.lang.Exception
90
	 */
91
	@Before
92
	public void setUp() throws Exception {
93
	    //article
94
		article1 = ReferenceFactory.newArticle();
95
		article1.setCacheStrategy(defaultStrategy);
96
		journal1 = ReferenceFactory.newJournal();
97
		journal1.setCacheStrategy(defaultStrategy);
98
        articleTeam1 = Team.NewInstance();
99
		articleTeam2 = Team.NewInstance();
100
		articleTeam1.setTitleCache("Team1", true);
101
		articleTeam1.setNomenclaturalTitle("T.", true);
102
		articleTeam2.setTitleCache("Team2", true);
103
		articleTeam2.setNomenclaturalTitle("TT.", true);
104

    
105
		//book / section
106
		book1 = ReferenceFactory.newBook();
107
		book1.setCacheStrategy(defaultStrategy);
108
        bookTeam1 = Team.NewTitledInstance("Book Author", "TT.");
109
        bookSection1 = ReferenceFactory.newBookSection();
110
        sectionTeam1 = Team.NewTitledInstance("Section Author", "T.");
111

    
112
        //CdDvd
113
        cdDvd = ReferenceFactory.newCdDvd();
114
        cdDvd.setCacheStrategy(defaultStrategy);
115
        cdDvdTitle = "A nice CD title";
116
        cdDvd.setTitle(cdDvdTitle);
117
        String publisher = "An ugly publisher";  //not yet implemented
118
        String place = "A beutiful place";  //not yet implemented
119
        TimePeriod publicationDate = TimePeriod.NewInstance(1999, 2001);
120
        cdDvd.setDatePublished(publicationDate);
121

    
122
        //Generic
123
        generic1 = ReferenceFactory.newGeneric();
124
        generic1.setCacheStrategy(defaultStrategy);
125
        genericTeam1 = Team.NewTitledInstance("Authorteam", "AT.");
126

    
127
        //WebPage
128
        webPage1 = ReferenceFactory.newWebPage();
129
        webPage1.setCacheStrategy(defaultStrategy);
130
        webPageTeam1 = Team.NewTitledInstance("Authorteam, D.", "AT.");
131
	}
132

    
133
//**************************** TESTS ***********************************
134

    
135

    
136
	@Test
137
	public void testArticleGetTitleCache(){
138
		journal1.setTitle("My journal");
139
		journal1.setAuthorship(articleTeam2);
140
		article1.setTitle("My article");
141
		article1.setInJournal(journal1);
142
		article1.setAuthorship(articleTeam1);
143
		article1.setDatePublished(TimePeriod.NewInstance(1975));
144
		Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
145

    
146
		article1.setInJournal(null);
147
		//TODO should not be needed here
148
		article1.setTitleCache(null, false);
149
		Assert.assertEquals("Team1, My article in " + DefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
150
	}
151

    
152
	@Test
153
	//This test is just to show that setInJournal(null) now resets caches  #1815
154
	public void testArticleGetTitleCache2(){
155
		journal1.setTitle("My journal");
156
		journal1.setAuthorship(articleTeam2);
157
		article1.setTitle("My article");
158
		article1.setInJournal(journal1);
159
		article1.setAuthorship(articleTeam1);
160
		article1.setDatePublished(TimePeriod.NewInstance(1975));
161
		Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
162

    
163
		article1.setInJournal(null);
164
		Assert.assertEquals("Team1, My article in " + DefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
165
	}
166

    
167
	//#6496
168
    @Test
169
    public void testArticleGetTitleCacheWithPages(){
170
        journal1.setTitle("My journal");
171
        journal1.setAuthorship(articleTeam2);
172
        article1.setTitle("My article");
173
        article1.setInJournal(journal1);
174
        article1.setAuthorship(articleTeam1);
175
        article1.setDatePublished(TimePeriod.NewInstance(1975));
176
        Assert.assertEquals("Team1, My article in My journal. 1975", article1.getTitleCache());
177
        article1.setPages("12-22");
178
        Assert.assertEquals("Team1, My article in My journal: 12-22. 1975", article1.getTitleCache());
179

    
180
        article1.setVolume("7");
181
        Assert.assertEquals("Team1, My article in My journal 7: 12-22. 1975", article1.getTitleCache());
182

    
183
        article1.setSeriesPart("II");
184
        //TODO unclear if punctuation is correct
185
        Assert.assertEquals("Team1, My article in My journal, II, 7: 12-22. 1975", article1.getTitleCache());
186
   }
187

    
188
	@Test
189
	public void testArticleGetAbbrevTitleCache(){
190

    
191
		journal1.setTitle("My journal");
192
		journal1.setTitle("M. Journ.");
193
		journal1.setAuthorship(articleTeam2);
194
		article1.setTitle("My article");
195
		article1.setInJournal(journal1);
196
		article1.setAuthorship(articleTeam1);
197
		article1.setDatePublished(TimePeriod.NewInstance(1975));
198
		article1.setAbbrevTitle("M. Art.");
199
		Assert.assertEquals("T., M. Art. in M. Journ. 1975", article1.getAbbrevTitleCache());  //double dot may be removed in future #3645
200

    
201
		article1.setInJournal(null);
202
		//TODO should not be needed here
203
		article1.setTitleCache(null, false);
204
		Assert.assertEquals("Team1, My article in " + DefaultReferenceCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());
205
	}
206

    
207
	@Test
208
	public void testArticleGetNomenclaturalCitation(){
209
		journal1.setTitle("My journal");
210
		journal1.setTitle("M. J.");
211
		journal1.setAuthorship(articleTeam2);
212
		article1.setTitle("My article");
213
		article1.setInJournal(journal1);
214
		article1.setAuthorship(articleTeam1);
215
		article1.setDatePublished(TimePeriod.NewInstance(1975));
216
		Assert.assertEquals("in M. J.: 55. 1975", article1.getNomenclaturalCitation(detail1));
217

    
218
		article1.setVolume("22");
219
		Assert.assertEquals("in M. J. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
220
		article1.setSeriesPart("ser. 11");
221
		Assert.assertEquals("in M. J., ser. 11, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
222

    
223
		article1.setPages("33"); //#6496 don't show pages in nomencl. citation
224
        Assert.assertEquals("in M. J., ser. 11, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
225
	}
226

    
227
	/**
228
	 * After ser. , sect. , abt. we want to have a comma, if there is not yet one following anyway
229
	 */
230
	@Test
231
	public void testArticleGetNomenclaturalCitationSerSectAbt(){
232
		article1.setInJournal(journal1);
233
		article1.setVolume("22");
234
		journal1.setAbbrevTitle("J. Pl. Eur.");
235
		journal1.setAuthorship(articleTeam2);
236
		article1.setDatePublished(TimePeriod.NewInstance(1975));
237
		//no ser, sect, abt
238
		Assert.assertEquals("in J. Pl. Eur. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
239
		//ser
240
		journal1.setAbbrevTitle("J. Pl. Eur., ser. 3");
241
		Assert.assertEquals("in J. Pl. Eur., ser. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
242
		journal1.setAbbrevTitle("J. Pl. Eur., Ser. 3");
243
		Assert.assertEquals("in J. Pl. Eur., Ser. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
244
		journal1.setAbbrevTitle("J. Pl. Eur., ser. 3, s.n.");
245
		Assert.assertEquals("in J. Pl. Eur., ser. 3, s.n. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
246
		//sect
247
		journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
248
		Assert.assertEquals("in J. Pl. Eur., sect. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
249
		journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3");
250
		Assert.assertEquals("in J. Pl. Eur., Sect. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
251
		journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3, something");
252
		Assert.assertEquals("in J. Pl. Eur., Sect. 3, something 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
253
		//abt
254
		journal1.setAbbrevTitle("J. Pl. Eur., abt. 3");
255
		Assert.assertEquals("in J. Pl. Eur., abt. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
256
		journal1.setAbbrevTitle("J. Pl. Eur., Abt. 3");
257
		Assert.assertEquals("in J. Pl. Eur., Abt. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
258
		journal1.setAbbrevTitle("J. Pl. Eur., abt. 3, no comma");
259
		Assert.assertEquals("in J. Pl. Eur., abt. 3, no comma 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
260

    
261
		journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
262
		article1.setSeriesPart("1");
263
		Assert.assertEquals("in J. Pl. Eur., sect. 3, ser. 1, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
264
		article1.setSeriesPart("Series 2");
265
		Assert.assertEquals("in J. Pl. Eur., sect. 3, Series 2, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
266
	}
267

    
268

    
269

    
270
	@Test
271
	public void testArticleGetTitleWithoutYearAndAuthor(){
272
		journal1.setTitle("My journal");
273
		journal1.setAuthorship(articleTeam2);
274
		article1.setTitle("My article");
275
		article1.setInJournal(journal1);
276
		article1.setAuthorship(articleTeam1);
277
		article1.setVolume("34");
278
		article1.setSeriesPart("ser. 2");
279
		article1.setDatePublished(TimePeriod.NewInstance(1975));
280
		//FIXME removed for new formatter
281
//		Assert.assertEquals("in My journal, ser. 2, 34", defaultStrategy.getTitleWithoutYearAndAuthor((Reference)article1, false));
282
	}
283

    
284
	@Test
285
	public void testArticleOldExistingBugs(){
286
		journal1.setTitle("Univ. Calif. Publ. Bot.");
287
		journal1.setAuthorship(null);
288

    
289
		Team articleAuthor = Team.NewTitledInstance("Babc. & Stebbins", "Babc. & Stebbins");
290
		article1.setTitle("");
291
		article1.setInJournal(journal1);
292
		article1.setAuthorship(articleAuthor);
293
		article1.setVolume("18");
294
		article1.setDatePublished(TimePeriod.NewInstance(1943));
295
		Assert.assertEquals("Babc. & Stebbins in Univ. Calif. Publ. Bot. 18. 1943", defaultStrategy.getTitleCache((Reference)article1));
296
	}
297

    
298
// ******************* Book ****************************/
299

    
300
   @Test
301
    public void testBookGetTitleCache0(){
302
        book1.setTitle("My book");
303
        book1.setAuthorship(bookTeam1);
304
        book1.setDatePublished(TimePeriod.NewInstance(1975));
305
        Assert.assertEquals("Unexpected title cache.", "Book Author, My book. 1975", book1.getTitleCache());
306

    
307
        book1.setTitleCache(null, false);
308
        book1.setEdition("ed. 3");
309
        Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3. 1975", book1.getTitleCache());
310

    
311
        TimePeriod newDatePublished = TimePeriodParser.parseString("1975 (after Aug.)");
312
        book1.setDatePublished(newDatePublished);
313
        book1.setTitleCache(null, false);
314
        //TODO this behaviour needs to be discussed. Maybe better the complete date published string should be returned.
315
        Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3", book1.getTitleCache());
316

    
317
        book1.setPages("1-405");
318
        Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3: 1-405", book1.getTitleCache());
319

    
320
    }
321

    
322

    
323
    @Test
324
    public void testBookGetTitleCache1(){
325
        //series
326
        IBook book1 = ReferenceFactory.newBook();
327
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
328
        book1.setSeriesPart("1");
329
        book1.setVolume("Fasc. 11");
330
        book1.setDatePublished(TimePeriodParser.parseString("1955"));
331
        Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11. 1955", book1.getTitleCache());
332
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
333
    }
334

    
335

    
336
    @Test
337
    public void testBookGetTitleCache2(){
338
        //series
339
        IBook book1 = ReferenceFactory.newBook();
340
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
341
        book1.setVolume("Fasc. 11");
342
        book1.setDatePublished(TimePeriodParser.parseString("1955"));
343
        Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11. 1955", book1.getTitleCache());
344
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
345
        book1.setSeriesPart("1");
346
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
347
    }
348

    
349
    @Test
350
    public void testBookGetNomenclaturalCitation(){
351
        book1.setTitle("My book");
352
        book1.setAuthorship(bookTeam1);
353
        book1.setDatePublished(TimePeriod.NewInstance(1975));
354
        Assert.assertEquals("My book: 55. 1975", book1.getNomenclaturalCitation(detail1));
355
        book1.setAbbrevTitle("Analect. Bot.");
356
        Assert.assertEquals("Analect. Bot. 1975", book1.getNomenclaturalCitation(null));
357
    }
358

    
359
// ***************************** Book Section ************************/
360

    
361
    @Test
362
    public void testBookSectionGetTitleCache(){
363
        book1.setTitle("My book");
364
        book1.setAuthorship(bookTeam1);
365
        bookSection1.setTitle("My chapter");
366
        bookSection1.setInBook(book1);
367
        bookSection1.setAuthorship(sectionTeam1);
368
        book1.setDatePublished(TimePeriod.NewInstance(1975));
369
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1.getTitleCache());
370
        book1.setDatePublished((VerbatimTimePeriod)null);
371
        bookSection1.setDatePublished(TimePeriod.NewInstance(1976));
372
        bookSection1.setTitleCache(null, false);
373
        book1.setTitleCache(null, false);
374
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
375
        book1.setDatePublished(TimePeriod.NewInstance(1977));
376
        bookSection1.setTitleCache(null, false);
377
        book1.setTitleCache(null, false);
378
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
379
        bookSection1.setTitleCache(null, false);
380
        book1.setTitleCache(null, false);
381
        book1.setSeriesPart("2");
382
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book, ser. 2. 1976", bookSection1.getTitleCache());
383

    
384
        //FIXME #6496
385
//        bookSection1.setPages("33-38");
386
//        bookSection1.setTitleCache(null);
387
//        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book, ser. 2: 33-38. 1976", bookSection1.getTitleCache());
388

    
389
        bookSection1.setInBook(null);
390
        bookSection1.setTitleCache(null, false);
391
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1.getTitleCache());
392

    
393
    }
394

    
395
    @Test
396
    //This test is just to show that setInBook(null) now resets caches  #1815
397
    public void testBookSectionGetTitleCache2(){
398
        book1.setTitle("My book");
399
        book1.setAuthorship(bookTeam1);
400
        bookSection1.setTitle("My chapter");
401
        bookSection1.setInBook(book1);
402
        bookSection1.setAuthorship(sectionTeam1);
403
        book1.setDatePublished(TimePeriod.NewInstance(1975));
404
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1.getTitleCache());
405
        book1.setDatePublished((VerbatimTimePeriod)null);
406
        bookSection1.setDatePublished(TimePeriod.NewInstance(1976));
407
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
408
        book1.setDatePublished(TimePeriod.NewInstance(1977));
409
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
410

    
411

    
412
        bookSection1.setInBook(null);
413
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1.getTitleCache());
414

    
415
    }
416

    
417

    
418
    @Test
419
    public void testBookSectionGetNomenclaturalCitation(){
420
        book1.setTitle("My book");
421
        book1.setAuthorship(bookTeam1);
422
        bookSection1.setTitle("My chapter");
423
        bookSection1.setInBook(book1);
424
        bookSection1.setAuthorship(sectionTeam1);
425
        book1.setDatePublished(TimePeriod.NewInstance(1975));
426
        //TODO still unclear which is correct
427
//      Assert.assertEquals("in Book Author, My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
428
        Assert.assertEquals("in TT., My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
429

    
430
        book1.setSeriesPart("2");
431
        Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
432
        //#6496 don't show pages in nom.ref. citations
433
        bookSection1.setPages("35-39");
434
        Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
435

    
436
    }
437

    
438
    @Test
439
    public void testBookSectionRealExample(){
440
        Team bookTeam = Team.NewTitledInstance("Chaudhary S. A.(ed.)", "Chaudhary S. A.(ed.)");
441
        IBook book = ReferenceFactory.newBook();
442
        book.setTitle("Flora of the Kingdom of Saudi Arabia");
443
        book.setAuthorship(bookTeam);
444
        book.setVolume("2(3)");
445
        book.setPlacePublished("Riyadh");
446
        book.setPublisher("National Herbarium");
447
        book.setDatePublished(TimePeriod.NewInstance(2000));
448

    
449
        Team sectionTeam = Team.NewTitledInstance("Chaudhary S. A.", "Chaudhary S. A.");
450
        IBookSection bookSection = ReferenceFactory.newBookSection();
451
        bookSection.setTitle("73. Hedypnois - 87. Crepis");
452
        bookSection.setInBook(book);
453
        bookSection.setAuthorship(sectionTeam);
454
        bookSection.setPages("222-251");
455
        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());
456

    
457
    }
458

    
459
    @Test
460
    public void testCdDvdGetTitleWithoutYearAndAuthor() {
461
        String result = TitleWithoutYearAndAuthorHelper.getTitleWithoutYearAndAuthor(cdDvd, false);
462
        assertEquals(cdDvdTitle, result);
463
    }
464

    
465
    //TODO missing publicationPlace and publisher has to be discussed
466
    @Test
467
    public void testCdDvdGetTitleCache() {
468
        String result = defaultStrategy.getTitleCache(cdDvd);
469
        assertEquals(cdDvdTitle + ". 1999-2001", result);
470
    }
471

    
472
// *************************** GENERIC *****************************************/
473

    
474
    @Test
475
    public void testGenericGetTitleCache(){
476
        generic1.setTitle("auct.");
477
        Assert.assertEquals("Unexpected title cache.", "auct.", generic1.getTitleCache());
478
    }
479

    
480

    
481
    @Test
482
    public void testGenericGetInRef(){
483
        generic1.setTitle("auct.");
484
        IBook book1 = ReferenceFactory.newBook();
485
        book1.setTitle("My book title");
486
        book1.setAuthorship(genericTeam1);
487
        Reference inRef = (Reference)book1;
488
        generic1.setInReference(inRef);
489
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
490
        //TODO author still unclear
491
//      Assert.assertEquals("Unexpected title cache.", "in Authorteam, My book title: 2", generic1.getNomenclaturalCitation("2"));
492
        Assert.assertEquals("Unexpected title cache.", "in AT., My book title: 2", generic1.getNomenclaturalCitation("2"));
493
    }
494

    
495
    @Test
496
    public void testGenericGetInRefWithoutInRef(){
497
        generic1.setTitle("My generic title");
498
        generic1.setAuthorship(genericTeam1);
499
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
500
        Assert.assertEquals("Unexpected title cache.", "My generic title: 2", generic1.getNomenclaturalCitation("2"));
501
    }
502

    
503
    @Test
504
    public void testGenericGetTitleCache2(){
505
        generic1.setTitle("Part Title");
506
        IBook book1 = ReferenceFactory.newBook();
507
        book1.setTitle("My book title");
508
        book1.setAuthorship(genericTeam1);
509
        Reference inRef = (Reference)book1;
510
        generic1.setInReference(inRef);
511
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
512
        Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title", generic1.getTitleCache());
513
    }
514

    
515

    
516
    @Test
517
    public void testGenericGetAbbrevTitleCache(){
518
        generic1.setTitle("Part Title");
519
        generic1.setAbbrevTitle("Pt. Tit.");
520
        generic1.setDatePublished(TimePeriodParser.parseString("1987"));
521
        IBook book1 = ReferenceFactory.newBook();
522
        book1.setTitle("My book title");
523
        book1.setAbbrevTitle("My bk. tit.");
524
        book1.setAuthorship(genericTeam1);  //TODO handling not yet defined
525
        Reference inRef = (Reference)book1;
526
        generic1.setInReference(inRef);
527
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
528
        generic1.setAbbrevTitleCache(null, false);  //reset cache in case aspectJ is not enabled
529
        Assert.assertEquals("Unexpected abbrev title cache.", "Pt. Tit. in AT., My bk. tit. 1987", generic1.getAbbrevTitleCache());
530
        Assert.assertEquals("Title cache must still be the same", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
531
        //TODO author still unclear
532
//      Assert.assertEquals("Unexpected nom. ref.", "in Authorteam, My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
533
        Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
534
        generic1.setVolume("23");
535
        Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit. 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
536
        generic1.setSeriesPart("ser. 11");
537
        //TODO
538
//      Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit., ser. 11, 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
539

    
540

    
541
        //protected
542
        generic1.setAbbrevTitleCache("My prot. abb. tit. in a bk.", true);
543
        Assert.assertEquals("Unexpected abbrev title cache.", "My prot. abb. tit. in a bk.", generic1.getAbbrevTitleCache());
544
        Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
545

    
546
        generic1.setDatePublished((VerbatimTimePeriod)null);
547
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(null));
548
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(""));
549
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44", generic1.getNomenclaturalCitation("pp. 44"));
550

    
551
        generic1.setDatePublished(TimePeriodParser.parseString("1893"));
552
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44. 1893", generic1.getNomenclaturalCitation("pp. 44"));
553

    
554
    }
555

    
556
    @Test
557
    public void testGenericGetTitleCacheWithoutInRef(){
558
        generic1.setTitle("My generic title");
559
        generic1.setAuthorship(genericTeam1);
560
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
561
        Assert.assertEquals("Unexpected title cache.", "Authorteam, My generic title", generic1.getTitleCache());
562
    }
563

    
564
    @Test
565
    public void testGenericAuthorOnly(){
566
        generic1.setAuthorship(genericTeam1);
567
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
568
        Assert.assertEquals("Unexpected title cache.", "Authorteam", generic1.getTitleCache());
569
        Assert.assertEquals("", generic1.getNomenclaturalCitation(null));
570
    }
571

    
572
    @Test
573
    public void testGenericYearAndAuthorOnly(){
574
        generic1.setAuthorship(genericTeam1);
575
        generic1.setDatePublished(TimePeriodParser.parseString("1792"));
576
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
577
        Assert.assertEquals("Unexpected title cache.", "Authorteam, 1792", generic1.getTitleCache());
578
        Assert.assertEquals("1792", generic1.getNomenclaturalCitation(null));
579
    }
580

    
581
    @Test
582
    public void testGenericDoubleDotBeforeYear(){
583
        generic1.setAuthorship(genericTeam1);
584
        String detail = "sine no.";
585
        generic1.setAbbrevTitle("My title");
586
        generic1.setDatePublished(TimePeriodParser.parseString("1883-1884"));
587
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
588
        Assert.assertEquals("My title: sine no. 1883-1884", generic1.getNomenclaturalCitation(detail));
589
    }
590

    
591
    //#4338
592
    @Test
593
    public void testGenericMissingVolume(){
594
        generic1.setTitle("My generic");
595
        generic1.setAuthorship(genericTeam1);
596
        generic1.setDatePublished(TimePeriodParser.parseString("1883-1884"));
597
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
598
        Assert.assertEquals("My generic: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
599
        generic1.setVolume("7");
600
        Assert.assertEquals("My generic 7: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
601
        Assert.assertEquals("Authorteam, My generic 7. 1883-1884", generic1.getTitleCache());
602
        Assert.assertEquals("AT., My generic 7. 1883-1884", generic1.getAbbrevTitleCache());
603

    
604
        //inRef
605
        Reference generic2 = ReferenceFactory.newGeneric();
606
        generic2.setTitle("My InRef");
607
        Person person2 = Person.NewTitledInstance("InRefAuthor");
608
        generic2.setAuthorship(person2);
609
        generic2.setDatePublished(TimePeriodParser.parseString("1885"));
610
        generic1.setInReference(generic2);
611

    
612
        //only reference has a volume
613
        Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
614
//        Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getTitleCache());
615
//        Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getAbbrevTitleCache());
616

    
617
        //both have a volume
618
        generic2.setVolume("9");  //still unclear what should happen if you have such dirty data
619
//        Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
620
//        Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getTitleCache());
621
//        Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getAbbrevTitleCache());
622

    
623
        //only inref has volume
624
        generic1.setVolume(null);
625
        Assert.assertEquals("in InRefAuthor, My InRef 9: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
626
        Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 9. 1883-1884", generic1.getTitleCache());
627
        Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 9. 1883-1884", generic1.getAbbrevTitleCache());
628
   }
629

    
630
    //#3532
631
    @Test
632
    public void testUnexpectedNomenclaturalReferences(){
633
        Reference reference;
634

    
635
        //database
636
        IDatabase database1 = ReferenceFactory.newDatabase();
637
        reference = (Reference)database1;
638

    
639
        database1.setTitle("My database");
640
        //maybe we should have a trailing dot here
641
        Assert.assertEquals("My database: 55", reference.getNomenclaturalCitation(detail1));
642
        database1.setDatePublished(TimePeriodParser.parseString("1998"));
643
        Assert.assertEquals("My database: 55. 1998", reference.getNomenclaturalCitation(detail1));
644

    
645
        database1.setTitleCache("Your database", true);
646
        Assert.assertEquals("My database: 55. 1998", reference.getNomenclaturalCitation(detail1));
647

    
648
        //unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
649
        reference.setAbbrevTitleCache("You. Db.", true);
650
        Assert.assertEquals("You. Db.: 55. 1998", reference.getNomenclaturalCitation(detail1));
651

    
652

    
653
        //CD/DVD
654
        ICdDvd cdDvd = ReferenceFactory.newCdDvd();
655
        reference= (Reference)cdDvd;
656
        cdDvd.setTitle("My Cd/Dvd");
657
        //maybe we should have a trailing dot here
658
        Assert.assertEquals("My Cd/Dvd: 55", reference.getNomenclaturalCitation(detail1));
659
        cdDvd.setDatePublished(TimePeriodParser.parseString("1998"));
660
        Assert.assertEquals("My Cd/Dvd: 55. 1998", reference.getNomenclaturalCitation(detail1));
661

    
662
        cdDvd.setTitleCache("Your Cd/Dvd", true);
663
        Assert.assertEquals("My Cd/Dvd: 55. 1998", reference.getNomenclaturalCitation(detail1));
664

    
665
        //unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
666
        reference.setAbbrevTitleCache("You. Cd.", true);
667
        Assert.assertEquals("You. Cd.: 55. 1998", reference.getNomenclaturalCitation(detail1));
668

    
669

    
670
        //WebSite
671
        IWebPage webPage = ReferenceFactory.newWebPage();
672
        reference= (Reference)webPage;
673
        webPage.setTitle("My WebPage");
674
        //maybe we should have a trailing dot here
675
        Assert.assertEquals("My WebPage: 55", reference.getNomenclaturalCitation(detail1));
676
        webPage.setDatePublished(TimePeriodParser.parseString("1998"));
677
        Assert.assertEquals("My WebPage: 55. 1998", reference.getNomenclaturalCitation(detail1));
678

    
679
        webPage.setTitleCache("Your WebPage", true);
680
        Assert.assertEquals("My WebPage: 55. 1998", reference.getNomenclaturalCitation(detail1));
681

    
682
        //unclear if it is wanted that the year is shown, though the abbrev cache is protected, probably not
683
        reference.setAbbrevTitleCache("You. WP.", true);
684
        Assert.assertEquals("You. WP.: 55. 1998", reference.getNomenclaturalCitation(detail1));
685

    
686
        //uri
687
        webPage = ReferenceFactory.newWebPage();
688
        reference= (Reference)webPage;
689
        webPage.setUri(URI.create("http://www.abc.de"));
690
        Assert.assertEquals("http://www.abc.de: 55", reference.getNomenclaturalCitation(detail1));
691

    
692
        //TBC
693
   }
694

    
695
// ********************************** WEB PAGE ********************************************/
696

    
697
    @Test
698
    //still preliminary, may be modified in future
699
    public void testWebPageGetTitleCache(){
700
        webPage1.setUri(URI.create("http://flora.huji.ac.il"));
701
        Assert.assertEquals("Unexpected title cache.",
702
                "http://flora.huji.ac.il",
703
                webPage1.getTitleCache());
704

    
705
        webPage1.setTitle("Flora of Israel Online");
706
        webPage1.setAuthorship(webPageTeam1);
707
        webPage1.setAccessed(DateTime.parse("2001-01-05"));
708
        Assert.assertEquals("Unexpected title cache.",
709
                "Authorteam, D., Flora of Israel Online - http://flora.huji.ac.il [accessed 2001-01-05]",
710
                webPage1.getTitleCache());
711

    
712
    }
713

    
714
//  @Test
715
//  //WebPages should usually not be used as nomencl.reference, therefore this is less important
716
//  public void testWebPageGetAbbrevTitleCache(){
717
//      webPage1.setTitle("auct.");
718
//      Assert.assertEquals("Unexpected title cache.", "auct.", webPage1.getTitleCache());
719
//  }
720

    
721

    
722
}
(1-1/2)