Project

General

Profile

Download (26.1 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.", true);
98
		articleTeam2.setTitleCache("Team2", true);
99
		articleTeam2.setNomenclaturalTitle("TT.", true);
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.", article1.getAbbrevTitleCache());
196
		article1.setVolume("7");
197
        Assert.assertEquals("T. 1975: M. Art. "+UTF8.EN_DASH+" M. Journ. 7.", article1.getAbbrevTitleCache());
198

    
199
		article1.setInJournal(null);
200
		article1.setTitleCache(null, false);
201
		Assert.assertEquals("Team1 1975: My article. "+UTF8.EN_DASH + " " +ReferenceDefaultCacheStrategy.UNDEFINED_JOURNAL + " 7.", article1.getTitleCache());
202
	}
203

    
204
	@Test
205
	public void testArticleGetTitleWithoutYearAndAuthor() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
206
		journal1.setTitle("My journal");
207
		journal1.setAbbrevTitle("My journ.");
208
		((Reference)journal1).setAuthorship(articleTeam2);
209
		article1.setTitle("My article");
210
		article1.setAbbrevTitle("My art.");
211
		article1.setInJournal(journal1);
212
		article1.setAuthorship(articleTeam1);
213
		article1.setVolume("34");
214
		article1.setSeriesPart("ser. 2");
215
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
216
		Method method = ReferenceDefaultCacheStrategy.class.getDeclaredMethod("getTitleWithoutYearAndAuthor", Reference.class, boolean.class, boolean.class);
217
		method.setAccessible(true);
218
		Assert.assertEquals("My article. " + UTF8.EN_DASH + " My journal, ser. 2, 34", method.invoke(defaultStrategy, article1, false, false));
219
		Assert.assertEquals("My art. " + UTF8.EN_DASH + " My journ., ser. 2, 34", method.invoke(defaultStrategy, article1, true, false));
220
		Assert.assertEquals("in My journal, ser. 2, 34", method.invoke(defaultStrategy, article1, false, true));
221
		Assert.assertEquals("in My journ., ser. 2, 34", method.invoke(defaultStrategy, article1, true, true));
222
	}
223

    
224
	@Test
225
	public void testArticleOldExistingBugs(){
226
		journal1.setTitle("Univ. Calif. Publ. Bot.");
227
		((Reference)journal1).setAuthorship(null);
228

    
229
		Team articleAuthor = Team.NewTitledInstance("Babc. & Stebbins", "Babc. & Stebbins");
230
		article1.setTitle("");
231
		article1.setInJournal(journal1);
232
		article1.setAuthorship(articleAuthor);
233
		article1.setVolume("18");
234
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1943));
235
		Assert.assertEquals("Babc. & Stebbins 1943: "+UTF8.EN_DASH+" Univ. Calif. Publ. Bot. 18.", defaultStrategy.getTitleCache((Reference)article1));
236
	}
237

    
238
// ******************* Book ****************************/
239

    
240
   @Test
241
    public void testBookGetTitleCache0(){
242
        book1.setTitle("My book");
243
        book1.setAuthorship(bookTeam1);
244
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
245
        Assert.assertEquals("Unexpected title cache.", "Book Author 1975: My book.", book1.getTitleCache());
246

    
247
        book1.setTitleCache(null, false);
248
        book1.setEdition("ed. 3");
249
        Assert.assertEquals("Unexpected title cache.", "Book Author 1975: My book, ed. 3.", book1.getTitleCache());
250

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

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

    
260
    }
261

    
262
    @Test
263
    public void testBookGetTitleCache1(){
264
        //series
265
        IBook book1 = ReferenceFactory.newBook();
266
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
267
        book1.setVolume("Fasc. 11");
268
        book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
269
        //TODO needs to be discussed
270
        Assert.assertEquals("Unexpected abbrev title cache", "1955: Acta Inst. Bot. Acad. Sci. URSS Fasc. 11.", book1.getTitleCache());
271
        book1.setSeriesPart("1");
272
        //TODO needs to be discussed
273
        Assert.assertEquals("Unexpected abbrev title cache", "1955: Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11.", book1.getTitleCache());
274
    }
275

    
276
// ***************************** Book Section ************************/
277

    
278
    //9529 and others
279
    @Test
280
    public void testBookSectionGetTitleCache(){
281
        String bookSetionTitle = "My chapter";
282
        book1.setTitle("My book");
283
        book1.setAuthorship(bookTeam1);
284
        bookSection1.setTitle(bookSetionTitle);
285
        bookSection1.setInBook(book1);
286
        bookSection1.setAuthorship(sectionTeam1);
287
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
288
        Assert.assertEquals("Unexpected title cache.", "Section Author 1975: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book.", bookSection1.getTitleCache());
289

    
290
        book1.setDatePublished((VerbatimTimePeriod)null);
291
        bookSection1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1976));
292
        bookSection1.setTitleCache(null, false);
293
        book1.setTitleCache(null, false);
294
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book.", bookSection1.getTitleCache());
295
        //with in-ref year (ignore if there is ref year)
296
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1977));
297
        bookSection1.setTitleCache(null, false);
298
        book1.setTitleCache(null, false);
299
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book.", bookSection1.getTitleCache());
300
        //with series part
301
        bookSection1.setTitleCache(null, false);
302
        book1.setTitleCache(null, false);
303
        book1.setSeriesPart("2");
304
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book, ser. 2.", bookSection1.getTitleCache());
305
        //without section title
306
        bookSection1.setTitle(null);
307
        bookSection1.setTitleCache(null, false);
308
        book1.setTitleCache(null, false);
309
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976 "+UTF8.EN_DASH+" In: Book Author, My book, ser. 2.", bookSection1.getTitleCache());
310
        bookSection1.setTitle(bookSetionTitle);
311

    
312
        //#6496, 9529, 9530
313
        bookSection1.setPages("33-38");
314
        bookSection1.setTitleCache(null, false);
315
        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());
316
        bookSection1.setPages("v");
317
        bookSection1.setTitleCache(null, false);
318
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter, p. v. "+UTF8.EN_DASH+" In: Book Author, My book, ser. 2.", bookSection1.getTitleCache());
319
        bookSection1.setPages(null);
320

    
321
        bookSection1.setInBook(null);
322
        bookSection1.setTitleCache(null, false);
323
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: - undefined book -.", bookSection1.getTitleCache());
324
    }
325

    
326
    @Test
327
    //This test is just to show that setInBook(null) now resets caches  #1815
328
    public void testBookSectionSetInBook(){
329
        book1.setTitle("My book");
330
        book1.setAuthorship(bookTeam1);
331
        bookSection1.setTitle("My chapter");
332
        bookSection1.setInBook(book1);
333
        bookSection1.setAuthorship(sectionTeam1);
334
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
335
        Assert.assertEquals("Unexpected title cache.", "Section Author 1975: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book.", bookSection1.getTitleCache());
336
        book1.setDatePublished((VerbatimTimePeriod)null);
337
        bookSection1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1976));
338
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book.", bookSection1.getTitleCache());
339
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1977));
340
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: Book Author, My book.", bookSection1.getTitleCache());
341

    
342
        bookSection1.setInBook(null);
343
        Assert.assertEquals("Unexpected title cache.", "Section Author 1976: My chapter. "+UTF8.EN_DASH+" In: - undefined book -.", bookSection1.getTitleCache());
344
    }
345

    
346
    @Test
347
    public void testBookSectionRealExample(){
348
        Team bookTeam = Team.NewTitledInstance("Chaudhary S. A.(ed.)", "Chaudhary S. A.(ed.)");
349
        IBook book = ReferenceFactory.newBook();
350
        book.setTitle("Flora of the Kingdom of Saudi Arabia");
351
        book.setAuthorship(bookTeam);
352
        book.setVolume("2(3)");
353
        book.setPlacePublished("Riyadh");
354
        book.setPublisher("National Herbarium");
355
        book.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(2000));
356

    
357
        Team sectionTeam = Team.NewTitledInstance("Chaudhary S. A.", "Chaudhary S. A.");
358
        IBookSection bookSection = ReferenceFactory.newBookSection();
359
        bookSection.setTitle("73. Hedypnois - 87. Crepis");
360
        bookSection.setInBook(book);
361
        bookSection.setAuthorship(sectionTeam);
362
        bookSection.setPages("222-251");
363
        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());
364

    
365
    }
366

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

    
387
        Assert.assertEquals("Unexpected title cache.",
388
                "Chudaev, D.A., Glushchenko, A., Kulikovskiy, M. & Kociolek, J.P. 2020 "+UTF8.EN_DASH+" In: "
389
                + "Kulikovskiy, M., Chudaev, D.A., Glushchenko, A., Kuznetsova, I. & Kociolek, J.P., "
390
                + "New diatom species Navicula davidovichii from Vietnam (Southeast Asia). "+UTF8.EN_DASH+" Phytotaxa 452(1).",
391
                section.getTitleCache());
392
    }
393

    
394
    @Test
395
    public void testSectionInBookSection(){
396
        //#9326, #3764
397
        Reference book = ReferenceFactory.newBook();
398
        book.setTitle("Species Plantarum");
399
        Team bookAuthor = Team.NewTitledInstance("Linne", null);
400
        book.setAuthorship(bookAuthor);
401
        book.setVolume("3");
402
        Reference bookSection = ReferenceFactory.newBookSection();
403
        String bookSectionTitle = "Trees";
404
        bookSection.setTitle(bookSectionTitle);
405
        Team bookSectionTeam = Team.NewTitledInstance("Chapter author", null);
406
        bookSection.setAuthorship(bookSectionTeam);
407
        bookSection.setInBook(book);
408
        bookSection.setPages("83-91");
409
        bookSection.setDatePublished(TimePeriodParser.parseStringVerbatim("1752"));
410
        bookSection.setDoi(DOI.fromString("10.12345/speciesplantarum.3"));
411
        Reference section = ReferenceFactory.newSection();
412
        Team sectionTeam = Team.NewTitledInstance("Section author", null);
413
        section.setAuthorship(sectionTeam);
414
        section.setInReference(bookSection);
415

    
416
        Assert.assertEquals("Unexpected title cache.",
417
                "Section author 1752 "+UTF8.EN_DASH+" In: Chapter author, Trees, pp. 83-91. "+UTF8.EN_DASH+" In: Linne, Species Plantarum 3.",
418
                section.getTitleCache());
419
    }
420

    
421
    @Test
422
    public void testCdDvdGetTitleWithoutYearAndAuthor() {
423
        String result = TitleWithoutYearAndAuthorHelper.getTitleWithoutYearAndAuthor(cdDvd, false, false);
424
        assertEquals(cdDvdTitle, result);
425
    }
426

    
427
    //TODO missing publicationPlace and publisher has to be discussed
428
    @Test
429
    public void testCdDvdGetTitleCache() {
430
        String result = defaultStrategy.getTitleCache(cdDvd);
431
        //TODO position of year needs to be discussed
432
        assertEquals("1999"+SEP+"2001: " + cdDvdTitle + ".", result);
433
    }
434

    
435
// *************************** GENERIC *****************************************/
436

    
437
    @Test
438
    public void testGenericGetTitleCache(){
439
        generic1.setTitle("auct.");
440
        Assert.assertEquals("Unexpected title cache.", "auct.", generic1.getTitleCache());
441
    }
442

    
443
    @Test
444
    public void testGenericGetTitleCache2(){
445
        generic1.setTitle("Part Title");
446
        IBook book1 = ReferenceFactory.newBook();
447
        book1.setTitle("My book title");
448
        book1.setAuthorship(genericTeam1);
449
        Reference inRef = (Reference)book1;
450
        generic1.setInReference(inRef);
451
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
452
        Assert.assertEquals("Unexpected title cache.", "Part Title. "+UTF8.EN_DASH+" In: Authorteam, My book title.", generic1.getTitleCache());
453
    }
454

    
455
    @Test
456
    public void testGenericGetAbbrevTitleCache(){
457
        generic1.setTitle("Part Title");
458
        generic1.setAbbrevTitle("Pt. Tit.");
459
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1987"));
460
        IBook book1 = ReferenceFactory.newBook();
461
        book1.setTitle("My book title");
462
        book1.setAbbrevTitle("My bk. tit.");
463
        book1.setAuthorship(genericTeam1);  //TODO handling not yet defined
464
        Reference inRef = (Reference)book1;
465
        generic1.setInReference(inRef);
466
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
467
        generic1.setAbbrevTitleCache(null, false);  //reset cache in case aspectJ is not enabled
468
        //TODO needs discussion
469
        Assert.assertEquals("Unexpected abbrev title cache.", "1987: Pt. Tit. "+UTF8.EN_DASH+" In: AT., My bk. tit.", generic1.getAbbrevTitleCache());
470
        Assert.assertEquals("Title cache must still be the same", "1987: Part Title. "+UTF8.EN_DASH+" In: Authorteam, My book title.", generic1.getTitleCache());
471

    
472
        //protected
473
        generic1.setAbbrevTitleCache("My prot. abb. tit. in a bk.", true);
474
        Assert.assertEquals("Unexpected abbrev title cache.", "My prot. abb. tit. in a bk.", generic1.getAbbrevTitleCache());
475
        Assert.assertEquals("Unexpected title cache.", "1987: Part Title. "+UTF8.EN_DASH+" In: Authorteam, My book title.", generic1.getTitleCache());
476
    }
477

    
478
    @Test
479
    public void testGenericGetTitleCacheWithoutInRef(){
480
        generic1.setTitle("My generic title");
481
        generic1.setAuthorship(genericTeam1);
482
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
483
        Assert.assertEquals("Unexpected title cache.", "Authorteam: My generic title.", generic1.getTitleCache());
484
    }
485

    
486
    @Test
487
    public void testGenericAuthorOnly(){
488
        generic1.setAuthorship(genericTeam1);
489
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
490
        Assert.assertEquals("Unexpected title cache.", "Authorteam.", generic1.getTitleCache());
491
    }
492

    
493
    @Test
494
    public void testGenericYearAndAuthorOnly(){
495
        generic1.setAuthorship(genericTeam1);
496
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1792"));
497
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
498
        Assert.assertEquals("Unexpected title cache.", "Authorteam 1792.", generic1.getTitleCache());
499
    }
500

    
501
    //#4338
502
    @Test
503
    public void testGenericMissingVolume(){
504
        generic1.setTitle("My generic");
505
        generic1.setAuthorship(genericTeam1);
506
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1883-1884"));
507
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
508
        generic1.setVolume("7");
509
        Assert.assertEquals("Authorteam 1883"+SEP+"1884: My generic 7.", generic1.getTitleCache());
510
        Assert.assertEquals("AT. 1883"+SEP+"1884: My generic 7.", generic1.getAbbrevTitleCache());
511

    
512
        //inRef
513
        Reference generic2 = ReferenceFactory.newGeneric();
514
        generic2.setTitle("My InRef");
515
        Person person2 = Person.NewTitledInstance("InRefAuthor");
516
        generic2.setAuthorship(person2);
517
        generic2.setDatePublished(TimePeriodParser.parseStringVerbatim("1885"));
518
        generic1.setInReference(generic2);
519

    
520
        //only reference has a volume
521
//        Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883"+SEP+"1884", generic1.getNomenclaturalCitation(detail1));
522
//        Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getTitleCache());
523
//        Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getAbbrevTitleCache());
524

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

    
530
        //only inref has volume
531
        generic1.setVolume(null);
532
        Assert.assertEquals("Authorteam 1883"+SEP+"1884: My generic. "+UTF8.EN_DASH+" In: InRefAuthor, My InRef 9.", generic1.getTitleCache());
533
        Assert.assertEquals("AT. 1883"+SEP+"1884: My generic. "+UTF8.EN_DASH+" In: InRefAuthor, My InRef 9.", generic1.getAbbrevTitleCache());
534
   }
535

    
536
// ********************************** WEB PAGE ********************************************/
537

    
538
    @Test
539
    //still preliminary, may be modified in future
540
    public void testWebPageGetTitleCache(){
541
        webPage1.setUri(URI.create("http://flora.huji.ac.il"));
542
        Assert.assertEquals("Unexpected title cache.",
543
                "http://flora.huji.ac.il",
544
                webPage1.getTitleCache());
545

    
546
        webPage1.setTitle("Flora of Israel Online");
547
        webPage1.setAuthorship(webPageTeam1);
548
        webPage1.setAccessed(DateTime.parse("2001-01-05"));
549
        Assert.assertEquals("Unexpected title cache.",
550
                "Authorteam, D.: Flora of Israel Online "+UTF8.EN_DASH+" http://flora.huji.ac.il [accessed 2001-01-05]",
551
                webPage1.getTitleCache());
552
    }
553

    
554
//  @Test
555
//  //WebPages should usually not be used as nomencl.reference, therefore this is less important
556
//  public void testWebPageGetAbbrevTitleCache(){
557
//      webPage1.setTitle("auct.");
558
//      Assert.assertEquals("Unexpected title cache.", "auct.", webPage1.getTitleCache());
559
//  }
560

    
561
}
(1-1/2)