Project

General

Profile

Download (28.4 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
import static org.junit.Assert.assertEquals;
12

    
13
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.Method;
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.common.DOI;
24
import eu.etaxonomy.cdm.common.URI;
25
import eu.etaxonomy.cdm.common.UTF8;
26
import eu.etaxonomy.cdm.model.agent.Person;
27
import eu.etaxonomy.cdm.model.agent.Team;
28
import eu.etaxonomy.cdm.model.common.TimePeriod;
29
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
30
import eu.etaxonomy.cdm.model.reference.IArticle;
31
import eu.etaxonomy.cdm.model.reference.IBook;
32
import eu.etaxonomy.cdm.model.reference.IBookSection;
33
import eu.etaxonomy.cdm.model.reference.IGeneric;
34
import eu.etaxonomy.cdm.model.reference.IJournal;
35
import eu.etaxonomy.cdm.model.reference.IWebPage;
36
import eu.etaxonomy.cdm.model.reference.Reference;
37
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
38
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
39

    
40
/**
41
 * Copy of {@link ArticleDefaultCacheStrategyTest} to test the {@link ReferenceDefaultCacheStrategy}.
42
 *
43
 * @author a.mueller
44
 * @since 25.05.2016
45
 */
46
public class ReferenceDefaultCacheStrategyTest {
47

    
48
	@SuppressWarnings("unused")
49
	private static final Logger logger = Logger.getLogger(ReferenceDefaultCacheStrategyTest.class);
50

    
51
	private static final String SEP = TimePeriod.SEP;
52

    
53
	//article
54
	private static IArticle article1;
55
	private static IJournal journal1;
56
	private static Team articleTeam1;
57
	private static Team articleTeam2;
58

    
59
	//book // book section
60
	private static IBook book1;
61
    private static Team bookTeam1;
62

    
63
    //book section
64
    private static IBookSection bookSection1;
65
    private static Team sectionTeam1;
66

    
67
    //CdDvd
68
    private static Reference cdDvd;
69
    private static String cdDvdTitle;
70

    
71
    //Generic
72
    private static IGeneric generic1;
73
    private static Team genericTeam1;
74

    
75
    //WebPage
76
    private static IWebPage webPage1;
77
    private static Team webPageTeam1;
78

    
79
	//common
80
	private static ReferenceDefaultCacheStrategy defaultStrategy;
81

    
82
	@BeforeClass
83
	public static void setUpBeforeClass() throws Exception {
84
		defaultStrategy = ReferenceDefaultCacheStrategy.NewInstance();
85
	}
86

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

    
101
		//book / section
102
		book1 = ReferenceFactory.newBook();
103
		book1.setCacheStrategy(defaultStrategy);
104
        bookTeam1 = Team.NewTitledInstance("Book Author", "TT.");
105
        bookSection1 = ReferenceFactory.newBookSection();
106
        sectionTeam1 = Team.NewTitledInstance("Section Author", "T.");
107

    
108
        //CdDvd
109
        cdDvd = ReferenceFactory.newCdDvd();
110
        cdDvd.setCacheStrategy(defaultStrategy);
111
        cdDvdTitle = "A nice CD title";
112
        cdDvd.setTitle(cdDvdTitle);
113
        String publisher = "An ugly publisher";  //not yet implemented
114
        String place = "A beutiful place";  //not yet implemented
115
        VerbatimTimePeriod publicationDate = VerbatimTimePeriod.NewVerbatimInstance(1999, 2001);
116
        cdDvd.setDatePublished(publicationDate);
117

    
118
        //Generic
119
        generic1 = ReferenceFactory.newGeneric();
120
        generic1.setCacheStrategy(defaultStrategy);
121
        genericTeam1 = Team.NewTitledInstance("Authorteam", "AT.");
122

    
123
        //WebPage
124
        webPage1 = ReferenceFactory.newWebPage();
125
        webPage1.setCacheStrategy(defaultStrategy);
126
        webPageTeam1 = Team.NewTitledInstance("Authorteam, D.", "AT.");
127
	}
128

    
129
//**************************** TESTS ***********************************
130

    
131
	@Test
132
	public void testArticleGetTitleCache(){
133
		journal1.setTitle("My journal");
134
		((Reference)journal1).setAuthorship(articleTeam2);  //incorrect use anyway
135
		article1.setInJournal(journal1);
136
		article1.setAuthorship(articleTeam1);
137
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
138
	    Assert.assertEquals("Team1 1975: "+UTF8.EN_DASH+" My journal", article1.getTitleCache());
139
	    article1.setTitle("My article");
140
		Assert.assertEquals("Team1 1975: My article. "+UTF8.EN_DASH+" My journal", article1.getTitleCache());
141

    
142
		article1.setInJournal(null);
143
		Assert.assertEquals("Team1 1975: My article. "+UTF8.EN_DASH+" " + ReferenceDefaultCacheStrategy.UNDEFINED_JOURNAL, article1.getTitleCache());
144
	}
145

    
146
	@Test
147
	//This test is just to show that setInJournal(null) now resets caches  #1815
148
	public void testSetInJournal(){
149
		journal1.setTitle("My journal");
150
		((Reference)journal1).setAuthorship(articleTeam2);
151
		article1.setTitle("My article");
152
		article1.setInJournal(journal1);
153
		article1.setAuthorship(articleTeam1);
154
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
155
		Assert.assertEquals("Team1 1975: My article. "+UTF8.EN_DASH+" My journal", article1.getTitleCache());
156

    
157
		article1.setInJournal(null);
158
		Assert.assertEquals("Team1 1975: My article. "+UTF8.EN_DASH+" " + ReferenceDefaultCacheStrategy.UNDEFINED_JOURNAL, article1.getTitleCache());
159
        article1.setDatePublished(null);
160
        Assert.assertEquals("Team1: My article. "+UTF8.EN_DASH+" " + ReferenceDefaultCacheStrategy.UNDEFINED_JOURNAL, article1.getTitleCache());
161
	}
162

    
163
	//#6496
164
    @Test
165
    public void testArticleGetTitleCacheWithPages(){
166
        journal1.setTitle("My journal");
167
        ((Reference)journal1).setAuthorship(articleTeam2);
168
        article1.setTitle("My article");
169
        article1.setInJournal(journal1);
170
        article1.setAuthorship(articleTeam1);
171
        article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
172
        Assert.assertEquals("Team1 1975: My article. "+UTF8.EN_DASH+" My journal", article1.getTitleCache());
173
        article1.setPages("12-22");
174
        Assert.assertEquals("Team1 1975: My article. "+UTF8.EN_DASH+" My journal: 12-22", article1.getTitleCache());
175

    
176
        article1.setVolume("7");
177
        Assert.assertEquals("Team1 1975: My article. "+UTF8.EN_DASH+" My journal 7: 12-22", article1.getTitleCache());
178

    
179
        article1.setSeriesPart("II");
180
        //TODO unclear if punctuation is correct
181
        Assert.assertEquals("Team1 1975: My article. "+UTF8.EN_DASH+" My journal, II, 7: 12-22", article1.getTitleCache());
182
    }
183

    
184
	@Test
185
	public void testArticleGetAbbrevTitleCache(){
186

    
187
		journal1.setTitle("My journal");
188
		journal1.setTitle("M. Journ.");
189
		((Reference)journal1).setAuthorship(articleTeam2);
190
		article1.setTitle("My article");
191
		article1.setInJournal(journal1);
192
		article1.setAuthorship(articleTeam1);
193
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
194
		article1.setAbbrevTitle("M. Art.");
195
		Assert.assertEquals("T. 1975: M. Art. "+UTF8.EN_DASH+" M. Journ.", defaultStrategy.getFullAbbrevTitleString((Reference)article1));
196
		article1.setVolume("7");
197
        Assert.assertEquals("T. 1975: M. Art. "+UTF8.EN_DASH+" M. Journ. 7", defaultStrategy.getFullAbbrevTitleString((Reference)article1));
198
	}
199

    
200
    @Test
201
    public void testNomenclaturalTitle(){
202

    
203
        journal1.setTitle("My journal");
204
        journal1.setTitle("M. Journ.");
205
        ((Reference)journal1).setAuthorship(articleTeam2);
206
        article1.setTitle("My article");
207
        article1.setInJournal(journal1);
208
        article1.setAuthorship(articleTeam1);
209
        article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
210
        article1.setAbbrevTitle("M. Art.");
211
        article1.setVolume("7");
212
        Assert.assertEquals("T. in M. Journ. 7. 1975", article1.getAbbrevTitleCache());
213
    }
214

    
215
	@Test
216
	public void testArticleGetTitleWithoutYearAndAuthor() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
217
		journal1.setTitle("My journal");
218
		journal1.setAbbrevTitle("My journ.");
219
		((Reference)journal1).setAuthorship(articleTeam2);
220
		article1.setTitle("My article");
221
		article1.setAbbrevTitle("My art.");
222
		article1.setInJournal(journal1);
223
		article1.setAuthorship(articleTeam1);
224
		article1.setVolume("34");
225
		article1.setSeriesPart("ser. 2");
226
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
227
		Method method = ReferenceDefaultCacheStrategy.class.getDeclaredMethod("getTitleWithoutYearAndAuthor", Reference.class, boolean.class, boolean.class);
228
		method.setAccessible(true);
229
		Assert.assertEquals("My article. " + UTF8.EN_DASH + " My journal, ser. 2, 34", method.invoke(defaultStrategy, article1, false, false));
230
		Assert.assertEquals("My art. " + UTF8.EN_DASH + " My journ., ser. 2, 34", method.invoke(defaultStrategy, article1, true, false));
231
		Assert.assertEquals("in My journal, ser. 2, 34", method.invoke(defaultStrategy, article1, false, true));
232
		Assert.assertEquals("in My journ., ser. 2, 34", method.invoke(defaultStrategy, article1, true, true));
233
	}
234

    
235
	@Test
236
	public void testArticleOldExistingBugs(){
237
		journal1.setTitle("Univ. Calif. Publ. Bot.");
238
		((Reference)journal1).setAuthorship(null);
239

    
240
		Team articleAuthor = Team.NewTitledInstance("Babc. & Stebbins", "Babc. & Stebbins");
241
		article1.setTitle("");
242
		article1.setInJournal(journal1);
243
		article1.setAuthorship(articleAuthor);
244
		article1.setVolume("18");
245
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1943));
246
		Assert.assertEquals("Babc. & Stebbins 1943: "+UTF8.EN_DASH+" Univ. Calif. Publ. Bot. 18", defaultStrategy.getTitleCache((Reference)article1));
247
	}
248

    
249
// ******************* Book ****************************/
250

    
251
   @Test
252
    public void testBookGetTitleCache0(){
253
        book1.setTitle("My book");
254
        book1.setAuthorship(bookTeam1);
255
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
256
        Assert.assertEquals("Unexpected title cache.", "Book Author 1975: My book", book1.getTitleCache());
257

    
258
        book1.setTitleCache(null, false);
259
        book1.setEdition("ed. 3");
260
        Assert.assertEquals("Unexpected title cache.", "Book Author 1975: My book, ed. 3", book1.getTitleCache());
261

    
262
        VerbatimTimePeriod newDatePublished = TimePeriodParser.parseStringVerbatim("1975 (after Aug.)");
263
        book1.setDatePublished(newDatePublished);
264
        book1.setTitleCache(null, false);
265
        //TODO this behaviour needs to be discussed. Maybe better the complete date published string should be returned.
266
        Assert.assertEquals("Unexpected title cache.", "Book Author: My book, ed. 3", book1.getTitleCache());
267

    
268
        book1.setPages("1-405");
269
        Assert.assertEquals("Unexpected title cache.", "Book Author: My book, ed. 3: 1-405", book1.getTitleCache());
270
    }
271

    
272
    @Test
273
    public void testBookGetTitleCache1(){
274
        //series
275
        IBook book1 = ReferenceFactory.newBook();
276
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
277
        book1.setVolume("Fasc. 11");
278
        book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
279
        //TODO needs to be discussed
280
        Assert.assertEquals("Unexpected abbrev title cache", "1955: Acta Inst. Bot. Acad. Sci. URSS Fasc. 11", book1.getTitleCache());
281
        book1.setSeriesPart("1");
282
        //TODO needs to be discussed
283
        Assert.assertEquals("Unexpected abbrev title cache", "1955: Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11", book1.getTitleCache());
284
    }
285

    
286
// ***************************** Book Section ************************/
287

    
288
    //9529 and others
289
    @Test
290
    public void testBookSectionGetTitleCache(){
291
        String bookSetionTitle = "My chapter";
292
        book1.setTitle("My book");
293
        book1.setAuthorship(bookTeam1);
294
        bookSection1.setTitle(bookSetionTitle);
295
        bookSection1.setInBook(book1);
296
        bookSection1.setAuthorship(sectionTeam1);
297
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
298
        Assert.assertEquals("Unexpected title cache.", "Section Author 1975: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book", bookSection1.getTitleCache());
299

    
300
        book1.setDatePublished((VerbatimTimePeriod)null);
301
        bookSection1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1976));
302
        bookSection1.setTitleCache(null, false);
303
        book1.setTitleCache(null, false);
304
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book", bookSection1.getTitleCache());
305
        //with in-ref year (ignore if there is ref year)
306
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1977));
307
        bookSection1.setTitleCache(null, false);
308
        book1.setTitleCache(null, false);
309
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book", bookSection1.getTitleCache());
310
        //with series part
311
        bookSection1.setTitleCache(null, false);
312
        book1.setTitleCache(null, false);
313
        book1.setSeriesPart("2");
314
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book, ser. 2", bookSection1.getTitleCache());
315
        //without section title
316
        bookSection1.setTitle(null);
317
        bookSection1.setTitleCache(null, false);
318
        book1.setTitleCache(null, false);
319
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976 "+UTF8.EN_DASH+" In: Book Author, My book, ser. 2", bookSection1.getTitleCache());
320
        bookSection1.setTitle(bookSetionTitle);
321

    
322
        //#6496, 9529, 9530
323
        bookSection1.setPages("33-38");
324
        bookSection1.setTitleCache(null, false);
325
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter, pp. 33-38. "+UTF8.EN_DASH+" In: Book Author, My book, ser. 2", bookSection1.getTitleCache());
326
        bookSection1.setPages("v");
327
        bookSection1.setTitleCache(null, false);
328
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter, p. v. "+UTF8.EN_DASH+" In: Book Author, My book, ser. 2", bookSection1.getTitleCache());
329
        bookSection1.setPages(null);
330

    
331
        bookSection1.setInBook(null);
332
        bookSection1.setTitleCache(null, false);
333
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: - undefined book -", bookSection1.getTitleCache());
334
    }
335

    
336
    @Test
337
    //This test is just to show that setInBook(null) now resets caches  #1815
338
    public void testBookSectionSetInBook(){
339
        book1.setTitle("My book");
340
        book1.setAuthorship(bookTeam1);
341
        bookSection1.setTitle("My chapter");
342
        bookSection1.setInBook(book1);
343
        bookSection1.setAuthorship(sectionTeam1);
344
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
345
        Assert.assertEquals("Unexpected title cache.", "Section Author 1975: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book", bookSection1.getTitleCache());
346
        book1.setDatePublished((VerbatimTimePeriod)null);
347
        bookSection1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1976));
348
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book", bookSection1.getTitleCache());
349
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1977));
350
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book", bookSection1.getTitleCache());
351

    
352
        bookSection1.setInBook(null);
353
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: - undefined book -", bookSection1.getTitleCache());
354
    }
355

    
356
    @Test
357
    public void testBookSectionRealExample(){
358
        Team bookTeam = Team.NewTitledInstance("Chaudhary S. A.(ed.)", "Chaudhary S. A.(ed.)");
359
        IBook book = ReferenceFactory.newBook();
360
        book.setTitle("Flora of the Kingdom of Saudi Arabia");
361
        book.setAuthorship(bookTeam);
362
        book.setVolume("2(3)");
363
        book.setPlacePublished("Riyadh");
364
        book.setPublisher("National Herbarium");
365
        book.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(2000));
366

    
367
        Team sectionTeam = Team.NewTitledInstance("Chaudhary S. A.", "Chaudhary S. A.");
368
        IBookSection bookSection = ReferenceFactory.newBookSection();
369
        bookSection.setTitle("73. Hedypnois - 87. Crepis");
370
        bookSection.setInBook(book);
371
        bookSection.setAuthorship(sectionTeam);
372
        bookSection.setPages("222-251");
373
        Assert.assertEquals("Chaudhary S. A. 2000: 73. Hedypnois - 87. Crepis, pp. 222-251. "+UTF8.EN_DASH+" In: Chaudhary S. A.(ed.), Flora of the Kingdom of Saudi Arabia 2(3)", bookSection.getTitleCache());
374
    }
375

    
376
    @Test
377
    public void testSectionInArticle(){
378
        //#9326, #3764
379
        Reference journal = ReferenceFactory.newJournal();
380
        journal.setTitle("Phytotaxa");
381
        Reference article = ReferenceFactory.newArticle();
382
        String articleTitle = "New diatom species Navicula davidovichii from Vietnam (Southeast Asia)";
383
        article.setTitle(articleTitle);
384
        Team articleTeam = Team.NewTitledInstance("Kulikovskiy, M., Chudaev, D.A., Glushchenko, A., Kuznetsova, I. & Kociolek, J.P.", null);
385
        article.setAuthorship(articleTeam);
386
        article.setInJournal(journal);
387
        article.setVolume("452(1)");
388
        article.setPages("83-91");
389
        article.setDatePublished(TimePeriodParser.parseStringVerbatim("8 Jul 2020"));
390
        article.setDoi(DOI.fromString("10.11646/phytotaxa.452.1.8"));
391
        Reference section = ReferenceFactory.newSection();
392
        Team sectionTeam = Team.NewTitledInstance("Chudaev, D.A., Glushchenko, A., Kulikovskiy, M. & Kociolek, J.P.", null);
393
        section.setAuthorship(sectionTeam);
394
        section.setInReference(article);
395

    
396
        Assert.assertEquals("Unexpected title cache.",
397
                "Chudaev, D.A., Glushchenko, A., Kulikovskiy, M. & Kociolek, J.P. 2020 "+UTF8.EN_DASH+" In: "
398
                + "Kulikovskiy, M., Chudaev, D.A., Glushchenko, A., Kuznetsova, I. & Kociolek, J.P., "
399
                + "New diatom species Navicula davidovichii from Vietnam (Southeast Asia). "+UTF8.EN_DASH+" Phytotaxa 452(1)",
400
                section.getTitleCache());
401
    }
402

    
403
    @Test
404
    public void testSectionInJournal(){
405
        //#9326, #3764
406
        Reference journal = ReferenceFactory.newJournal();
407
        journal.setTitle("Phytotaxa");
408
        Reference section = ReferenceFactory.newSection();
409
        Team sectionTeam = Team.NewTitledInstance("Kulikovskiy, M., Chudaev, D.A., Glushchenko, A., Kuznetsova, I. & Kociolek, J.P.", null);
410
        section.setAuthorship(sectionTeam);
411

    
412
        section.setInReference(journal);
413
        section.setVolume("452(1)");
414
        section.setDatePublished(TimePeriodParser.parseStringVerbatim("8 Jul 2020"));
415

    
416
        Assert.assertEquals("Unexpected title cache.",
417
                "Kulikovskiy, M., Chudaev, D.A., Glushchenko, A., Kuznetsova, I. & Kociolek, J.P. 2020 "+UTF8.EN_DASH+" In: "
418
                + "Phytotaxa 452(1)",
419
                section.getTitleCache());
420
    }
421

    
422
    @Test
423
    public void testSectionInBookSection(){
424
        //#9326, #3764
425
        Reference book = ReferenceFactory.newBook();
426
        book.setTitle("Species Plantarum");
427
        Team bookAuthor = Team.NewTitledInstance("Linne", null);
428
        book.setAuthorship(bookAuthor);
429
        book.setVolume("3");
430
        Reference bookSection = ReferenceFactory.newBookSection();
431
        String bookSectionTitle = "Trees";
432
        bookSection.setTitle(bookSectionTitle);
433
        Team bookSectionTeam = Team.NewTitledInstance("Chapter author", null);
434
        bookSection.setAuthorship(bookSectionTeam);
435
        bookSection.setInBook(book);
436
        bookSection.setPages("83-91");
437
        bookSection.setDatePublished(TimePeriodParser.parseStringVerbatim("1752"));
438
        bookSection.setDoi(DOI.fromString("10.12345/speciesplantarum.3"));
439
        Reference section = ReferenceFactory.newSection();
440
        Team sectionTeam = Team.NewTitledInstance("Section author", null);
441
        section.setAuthorship(sectionTeam);
442
        section.setInReference(bookSection);
443

    
444
        Assert.assertEquals("Unexpected title cache.",
445
                "Section author 1752 "+UTF8.EN_DASH+" In: Chapter author, Trees, pp. 83-91. "+UTF8.EN_DASH+" In: Linne, Species Plantarum 3",
446
                section.getTitleCache());
447
    }
448

    
449
    @Test
450
    public void testCdDvdGetTitleWithoutYearAndAuthor() {
451
        String result = TitleWithoutYearAndAuthorHelper.getTitleWithoutYearAndAuthor(cdDvd, false, false);
452
        assertEquals(cdDvdTitle, result);
453
    }
454

    
455
    //TODO missing publicationPlace and publisher has to be discussed
456
    @Test
457
    public void testCdDvdGetTitleCache() {
458
        String result = defaultStrategy.getTitleCache(cdDvd);
459
        //TODO position of year needs to be discussed
460
        assertEquals("1999"+SEP+"2001: " + cdDvdTitle, result);
461
    }
462

    
463
// *************************** GENERIC *****************************************/
464

    
465
    @Test
466
    public void testGenericGetTitleCache(){
467
        generic1.setTitle("auct.");
468
        Assert.assertEquals("Unexpected title cache.", "auct.", generic1.getTitleCache());
469
    }
470

    
471
    @Test
472
    public void testGenericGetTitleCache2(){
473
        generic1.setTitle("Part Title");
474
        IBook book1 = ReferenceFactory.newBook();
475
        book1.setTitle("My book title");
476
        book1.setAuthorship(genericTeam1);
477
        Reference inRef = (Reference)book1;
478
        generic1.setInReference(inRef);
479
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
480
        Assert.assertEquals("Unexpected title cache.", "Part Title. "+UTF8.EN_DASH+" In: Authorteam, My book title", generic1.getTitleCache());
481
    }
482

    
483
    @Test
484
    public void testGenericGetAbbrevTitleCache(){
485
        generic1.setTitle("Part Title");
486
        generic1.setAbbrevTitle("Pt. Tit.");
487
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1987"));
488
        IBook book1 = ReferenceFactory.newBook();
489
        book1.setTitle("My book title");
490
        book1.setAbbrevTitle("My bk. tit.");
491
        book1.setAuthorship(genericTeam1);  //TODO handling not yet defined
492
        Reference inRef = (Reference)book1;
493
        generic1.setInReference(inRef);
494
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
495
        generic1.setAbbrevTitleCache(null, false);  //reset cache in case aspectJ is not enabled
496
        //TODO needs discussion
497
        Assert.assertEquals("Unexpected abbrev title cache.", "1987: Pt. Tit. "+UTF8.EN_DASH+" In: AT., My bk. tit.", defaultStrategy.getFullAbbrevTitleString((Reference)generic1));
498

    
499
        //protected
500
        generic1.setAbbrevTitleCache("My prot. abb. tit. in a bk.", true);
501
        Assert.assertEquals("Unexpected abbrev title cache.", "My prot. abb. tit. in a bk.", defaultStrategy.getFullAbbrevTitleString((Reference)generic1));
502
    }
503

    
504
    @Test
505
    public void testGenericNomenclaturalTitle(){
506
        generic1.setTitle("Part Title");
507
        generic1.setAbbrevTitle("Pt. Tit.");
508
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1987"));
509
        IBook book1 = ReferenceFactory.newBook();
510
        book1.setTitle("My book title");
511
        book1.setAbbrevTitle("My bk. tit.");
512
        book1.setAuthorship(genericTeam1);  //TODO handling not yet defined
513
        Reference inRef = (Reference)book1;
514
        generic1.setInReference(inRef);
515
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
516
        generic1.setAbbrevTitleCache(null, false);  //reset cache in case aspectJ is not enabled
517
        Assert.assertEquals("Unexpected abbrev title cache.", "in AT., My bk. tit. 1987", generic1.getAbbrevTitleCache());
518
        Assert.assertEquals("Title cache must still be the same", "1987: Part Title. "+UTF8.EN_DASH+" In: Authorteam, My book title", generic1.getTitleCache());
519

    
520
        //protected
521
        generic1.setAbbrevTitleCache("My prot. abb. tit. in a bk.", true);
522
        Assert.assertEquals("Unexpected abbrev title cache.", "My prot. abb. tit. in a bk.", generic1.getAbbrevTitleCache());
523
        Assert.assertEquals("Unexpected title cache.", "1987: Part Title. "+UTF8.EN_DASH+" In: Authorteam, My book title", generic1.getTitleCache());
524
    }
525

    
526
    @Test
527
    public void testGenericGetTitleCacheWithoutInRef(){
528
        generic1.setTitle("My generic title");
529
        generic1.setAuthorship(genericTeam1);
530
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
531
        Assert.assertEquals("Unexpected title cache.", "Authorteam: My generic title", generic1.getTitleCache());
532
    }
533

    
534
    @Test
535
    public void testGenericAuthorOnly(){
536
        generic1.setAuthorship(genericTeam1);
537
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
538
        Assert.assertEquals("Unexpected title cache.", "Authorteam", generic1.getTitleCache());
539
    }
540

    
541
    @Test
542
    public void testGenericYearAndAuthorOnly(){
543
        generic1.setAuthorship(genericTeam1);
544
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1792"));
545
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
546
        Assert.assertEquals("Unexpected title cache.", "Authorteam 1792", generic1.getTitleCache());
547
    }
548

    
549
    //#4338
550
    @Test
551
    public void testGenericMissingVolume(){
552
        generic1.setTitle("My generic");
553
        generic1.setAuthorship(genericTeam1);
554
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1883-1884"));
555
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
556
        generic1.setVolume("7");
557
        Assert.assertEquals("Authorteam 1883"+SEP+"1884: My generic 7", generic1.getTitleCache());
558
        Assert.assertEquals("AT., My generic 7. 1883"+UTF8.EN_DASH+"1884", generic1.getAbbrevTitleCache());
559

    
560
        //inRef
561
        Reference generic2 = ReferenceFactory.newGeneric();
562
        generic2.setTitle("My InRef");
563
        Person person2 = Person.NewTitledInstance("InRefAuthor");
564
        generic2.setAuthorship(person2);
565
        generic2.setDatePublished(TimePeriodParser.parseStringVerbatim("1885"));
566
        generic1.setInReference(generic2);
567

    
568
        //only reference has a volume
569
//        Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883"+SEP+"1884", generic1.getNomenclaturalCitation(detail1));
570
//        Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getTitleCache());
571
//        Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getAbbrevTitleCache());
572

    
573
        //both have a volume
574
        generic2.setVolume("9");  //still unclear what should happen if you have such dirty data
575
//        Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getTitleCache());
576
//        Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getAbbrevTitleCache());
577

    
578
        //only inref has volume
579
        generic1.setVolume(null);
580
        Assert.assertEquals("Authorteam 1883"+SEP+"1884: My generic. "+UTF8.EN_DASH+" In: InRefAuthor, My InRef 9", generic1.getTitleCache());
581
        Assert.assertEquals("AT. in InRefAuthor, My InRef 9. 1883"+UTF8.EN_DASH+"1884", generic1.getAbbrevTitleCache());
582
   }
583

    
584
// ********************************** WEB PAGE ********************************************/
585

    
586
    @Test
587
    //still preliminary, may be modified in future
588
    public void testWebPageGetTitleCache(){
589
        webPage1.setUri(URI.create("http://flora.huji.ac.il"));
590
        Assert.assertEquals("Unexpected title cache.",
591
                "http://flora.huji.ac.il",
592
                webPage1.getTitleCache());
593

    
594
        webPage1.setTitle("Flora of Israel Online");
595
        webPage1.setAuthorship(webPageTeam1);
596
        webPage1.setAccessed(DateTime.parse("2001-01-05"));
597
        Assert.assertEquals("Unexpected title cache.",
598
                "Authorteam, D.: Flora of Israel Online "+UTF8.EN_DASH+" http://flora.huji.ac.il [accessed 2001-01-05]",
599
                webPage1.getTitleCache());
600
    }
601

    
602
//  @Test
603
//  //WebPages should usually not be used as nomencl.reference, therefore this is less important
604
//  public void testWebPageGetAbbrevTitleCache(){
605
//      webPage1.setTitle("auct.");
606
//      Assert.assertEquals("Unexpected title cache.", "auct.", webPage1.getTitleCache());
607
//  }
608

    
609
}
(1-1/2)