Project

General

Profile

Download (35.3 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.VerbatimTimePeriod;
26
import eu.etaxonomy.cdm.model.reference.IArticle;
27
import eu.etaxonomy.cdm.model.reference.IBook;
28
import eu.etaxonomy.cdm.model.reference.IBookSection;
29
import eu.etaxonomy.cdm.model.reference.ICdDvd;
30
import eu.etaxonomy.cdm.model.reference.IDatabase;
31
import eu.etaxonomy.cdm.model.reference.IGeneric;
32
import eu.etaxonomy.cdm.model.reference.IJournal;
33
import eu.etaxonomy.cdm.model.reference.IWebPage;
34
import eu.etaxonomy.cdm.model.reference.Reference;
35
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
36
import eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy;
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
        VerbatimTimePeriod publicationDate = VerbatimTimePeriod.NewVerbatimInstance(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
		((Reference)journal1).setAuthorship(articleTeam2);  //incorrect use anyway
140
		article1.setTitle("My article");
141
		article1.setInJournal(journal1);
142
		article1.setAuthorship(articleTeam1);
143
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(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
		((Reference)journal1).setAuthorship(articleTeam2);
157
		article1.setTitle("My article");
158
		article1.setInJournal(journal1);
159
		article1.setAuthorship(articleTeam1);
160
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(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
        ((Reference)journal1).setAuthorship(articleTeam2);
172
        article1.setTitle("My article");
173
        article1.setInJournal(journal1);
174
        article1.setAuthorship(articleTeam1);
175
        article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(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
		((Reference)journal1).setAuthorship(articleTeam2);
194
		article1.setTitle("My article");
195
		article1.setInJournal(journal1);
196
		article1.setAuthorship(articleTeam1);
197
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(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
		((Reference)journal1).setAuthorship(articleTeam2);
212
		article1.setTitle("My article");
213
		article1.setInJournal(journal1);
214
		article1.setAuthorship(articleTeam1);
215
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(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
		((Reference)journal1).setAuthorship(articleTeam2);
236
		article1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(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
		((Reference)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(VerbatimTimePeriod.NewVerbatimInstance(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
		((Reference)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(VerbatimTimePeriod.NewVerbatimInstance(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(VerbatimTimePeriod.NewVerbatimInstance(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
        VerbatimTimePeriod newDatePublished = TimePeriodParser.parseStringVerbatim("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
    //https://dev.e-taxonomy.eu/redmine/issues/8881
323
    @Test
324
    public void testInRefAuthor(){
325
        Person person1 = Person.NewInstance("Inauth.", "Inauthor", "A.B.", "Ala Bala");
326
        Person person2 = Person.NewInstance("Twoauth.", "Twoauthor", "C.", "Cla");
327
        Person person3 = Person.NewTitledInstance("Threeauth.");
328
        Team team = Team.NewInstance(person1, person2, person3);
329
        IBook book1 = ReferenceFactory.newBook();
330
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
331
        book1.setVolume("Fasc. 11");
332
        book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
333
        bookSection1.setTitle("My chapter");
334
        bookSection1.setInBook(book1);
335
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1956));
336

    
337
        book1.setAuthorship(person1);
338
        Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
339
        book1.setAuthorship(team);
340
        Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Twoauthor & Threeauth., Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
341
        team.setHasMoreMembers(true);
342
        Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Twoauthor, Threeauth. & al., Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
343
        book1.setAuthorship(Team.NewInstance(person1));
344
        Assert.assertEquals("Unexpected nomencl. reference", "in Inauthor, Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
345

    
346
        //for the following the behavior is not yet finally discussed, may change in future
347
        book1.setAuthorship(team);
348
        team.setTitleCache("Teamcache", true);
349
        Assert.assertEquals("Unexpected nomencl. reference", "in Teamcache, Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
350
        team.setTitleCache("Teamc.", true);
351
        Assert.assertEquals("Unexpected nomencl. reference", "in Teamc., Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
352
        book1.setAuthorship(Team.NewInstance());
353
        Assert.assertEquals("Unexpected nomencl. reference", "in "+TeamDefaultCacheStrategy.EMPTY_TEAM+", Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1956", bookSection1.getNomenclaturalCitation("248"));
354
    }
355

    
356
    @Test
357
    public void testBookGetTitleCache1(){
358
        //series
359
        IBook book1 = ReferenceFactory.newBook();
360
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
361
        book1.setSeriesPart("1");
362
        book1.setVolume("Fasc. 11");
363
        book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
364
        Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11. 1955", book1.getTitleCache());
365
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
366
    }
367

    
368
    @Test
369
    public void testBookGetTitleCache2(){
370
        //series
371
        IBook book1 = ReferenceFactory.newBook();
372
        book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
373
        book1.setVolume("Fasc. 11");
374
        book1.setDatePublished(TimePeriodParser.parseStringVerbatim("1955"));
375
        Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11. 1955", book1.getTitleCache());
376
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
377
        book1.setSeriesPart("1");
378
        Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
379
    }
380

    
381
    @Test
382
    public void testBookGetNomenclaturalCitation(){
383
        book1.setTitle("My book");
384
        book1.setAuthorship(bookTeam1);
385
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
386
        Assert.assertEquals("My book: 55. 1975", book1.getNomenclaturalCitation(detail1));
387
        book1.setAbbrevTitle("Analect. Bot.");
388
        Assert.assertEquals("Analect. Bot. 1975", book1.getNomenclaturalCitation(null));
389
    }
390

    
391
// ***************************** Book Section ************************/
392

    
393
    @Test
394
    public void testBookSectionGetTitleCache(){
395
        book1.setTitle("My book");
396
        book1.setAuthorship(bookTeam1);
397
        bookSection1.setTitle("My chapter");
398
        bookSection1.setInBook(book1);
399
        bookSection1.setAuthorship(sectionTeam1);
400
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
401
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1.getTitleCache());
402
        book1.setDatePublished((VerbatimTimePeriod)null);
403
        bookSection1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1976));
404
        bookSection1.setTitleCache(null, false);
405
        book1.setTitleCache(null, false);
406
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
407
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1977));
408
        bookSection1.setTitleCache(null, false);
409
        book1.setTitleCache(null, false);
410
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
411
        bookSection1.setTitleCache(null, false);
412
        book1.setTitleCache(null, false);
413
        book1.setSeriesPart("2");
414
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book, ser. 2. 1976", bookSection1.getTitleCache());
415

    
416
        //FIXME #6496
417
//        bookSection1.setPages("33-38");
418
//        bookSection1.setTitleCache(null);
419
//        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book, ser. 2: 33-38. 1976", bookSection1.getTitleCache());
420

    
421
        bookSection1.setInBook(null);
422
        bookSection1.setTitleCache(null, false);
423
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1.getTitleCache());
424

    
425
    }
426

    
427
    @Test
428
    //This test is just to show that setInBook(null) now resets caches  #1815
429
    public void testBookSectionGetTitleCache2(){
430
        book1.setTitle("My book");
431
        book1.setAuthorship(bookTeam1);
432
        bookSection1.setTitle("My chapter");
433
        bookSection1.setInBook(book1);
434
        bookSection1.setAuthorship(sectionTeam1);
435
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
436
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1.getTitleCache());
437
        book1.setDatePublished((VerbatimTimePeriod)null);
438
        bookSection1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1976));
439
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
440
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1977));
441
        Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
442

    
443

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

    
447
    }
448

    
449

    
450
    @Test
451
    public void testBookSectionGetNomenclaturalCitation(){
452
        book1.setTitle("My book");
453
        book1.setAuthorship(bookTeam1);
454
        bookSection1.setTitle("My chapter");
455
        bookSection1.setInBook(book1);
456
        bookSection1.setAuthorship(sectionTeam1);
457
        book1.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(1975));
458
        //TODO still unclear which is correct
459
//      Assert.assertEquals("in Book Author, My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
460
        Assert.assertEquals("in TT., My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
461

    
462
        book1.setSeriesPart("2");
463
        Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
464
        //#6496 don't show pages in nom.ref. citations
465
        bookSection1.setPages("35-39");
466
        Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
467

    
468
    }
469

    
470
    @Test
471
    public void testBookSectionRealExample(){
472
        Team bookTeam = Team.NewTitledInstance("Chaudhary S. A.(ed.)", "Chaudhary S. A.(ed.)");
473
        IBook book = ReferenceFactory.newBook();
474
        book.setTitle("Flora of the Kingdom of Saudi Arabia");
475
        book.setAuthorship(bookTeam);
476
        book.setVolume("2(3)");
477
        book.setPlacePublished("Riyadh");
478
        book.setPublisher("National Herbarium");
479
        book.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(2000));
480

    
481
        Team sectionTeam = Team.NewTitledInstance("Chaudhary S. A.", "Chaudhary S. A.");
482
        IBookSection bookSection = ReferenceFactory.newBookSection();
483
        bookSection.setTitle("73. Hedypnois - 87. Crepis");
484
        bookSection.setInBook(book);
485
        bookSection.setAuthorship(sectionTeam);
486
        bookSection.setPages("222-251");
487
        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());
488

    
489
    }
490

    
491
    @Test
492
    public void testCdDvdGetTitleWithoutYearAndAuthor() {
493
        String result = TitleWithoutYearAndAuthorHelper.getTitleWithoutYearAndAuthor(cdDvd, false);
494
        assertEquals(cdDvdTitle, result);
495
    }
496

    
497
    //TODO missing publicationPlace and publisher has to be discussed
498
    @Test
499
    public void testCdDvdGetTitleCache() {
500
        String result = defaultStrategy.getTitleCache(cdDvd);
501
        assertEquals(cdDvdTitle + ". 1999-2001", result);
502
    }
503

    
504
// *************************** GENERIC *****************************************/
505

    
506
    @Test
507
    public void testGenericGetTitleCache(){
508
        generic1.setTitle("auct.");
509
        Assert.assertEquals("Unexpected title cache.", "auct.", generic1.getTitleCache());
510
    }
511

    
512
    @Test
513
    public void testGenericGetInRef(){
514
        generic1.setTitle("auct.");
515
        IBook book1 = ReferenceFactory.newBook();
516
        book1.setTitle("My book title");
517
        book1.setAuthorship(genericTeam1);
518
        Reference inRef = (Reference)book1;
519
        generic1.setInReference(inRef);
520
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
521
        //TODO author still unclear
522
//      Assert.assertEquals("Unexpected title cache.", "in Authorteam, My book title: 2", generic1.getNomenclaturalCitation("2"));
523
        Assert.assertEquals("Unexpected title cache.", "in AT., My book title: 2", generic1.getNomenclaturalCitation("2"));
524
    }
525

    
526
    @Test
527
    public void testGenericGetInRefWithoutInRef(){
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.", "My generic title: 2", generic1.getNomenclaturalCitation("2"));
532
    }
533

    
534
    @Test
535
    public void testGenericGetTitleCache2(){
536
        generic1.setTitle("Part Title");
537
        IBook book1 = ReferenceFactory.newBook();
538
        book1.setTitle("My book title");
539
        book1.setAuthorship(genericTeam1);
540
        Reference inRef = (Reference)book1;
541
        generic1.setInReference(inRef);
542
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
543
        Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title", generic1.getTitleCache());
544
    }
545

    
546

    
547
    @Test
548
    public void testGenericGetAbbrevTitleCache(){
549
        generic1.setTitle("Part Title");
550
        generic1.setAbbrevTitle("Pt. Tit.");
551
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1987"));
552
        IBook book1 = ReferenceFactory.newBook();
553
        book1.setTitle("My book title");
554
        book1.setAbbrevTitle("My bk. tit.");
555
        book1.setAuthorship(genericTeam1);  //TODO handling not yet defined
556
        Reference inRef = (Reference)book1;
557
        generic1.setInReference(inRef);
558
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
559
        generic1.setAbbrevTitleCache(null, false);  //reset cache in case aspectJ is not enabled
560
        Assert.assertEquals("Unexpected abbrev title cache.", "Pt. Tit. in AT., My bk. tit. 1987", generic1.getAbbrevTitleCache());
561
        Assert.assertEquals("Title cache must still be the same", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
562
        //TODO author still unclear
563
//      Assert.assertEquals("Unexpected nom. ref.", "in Authorteam, My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
564
        Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
565
        generic1.setVolume("23");
566
        Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit. 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
567
        generic1.setSeriesPart("ser. 11");
568
        //TODO
569
//      Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit., ser. 11, 23: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
570

    
571

    
572
        //protected
573
        generic1.setAbbrevTitleCache("My prot. abb. tit. in a bk.", true);
574
        Assert.assertEquals("Unexpected abbrev title cache.", "My prot. abb. tit. in a bk.", generic1.getAbbrevTitleCache());
575
        Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
576

    
577
        generic1.setDatePublished((VerbatimTimePeriod)null);
578
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(null));
579
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(""));
580
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44", generic1.getNomenclaturalCitation("pp. 44"));
581

    
582
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1893"));
583
        Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44. 1893", generic1.getNomenclaturalCitation("pp. 44"));
584

    
585
    }
586

    
587
    @Test
588
    public void testGenericGetTitleCacheWithoutInRef(){
589
        generic1.setTitle("My generic title");
590
        generic1.setAuthorship(genericTeam1);
591
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
592
        Assert.assertEquals("Unexpected title cache.", "Authorteam, My generic title", generic1.getTitleCache());
593
    }
594

    
595
    @Test
596
    public void testGenericAuthorOnly(){
597
        generic1.setAuthorship(genericTeam1);
598
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
599
        Assert.assertEquals("Unexpected title cache.", "Authorteam", generic1.getTitleCache());
600
        Assert.assertEquals("", generic1.getNomenclaturalCitation(null));
601
    }
602

    
603
    @Test
604
    public void testGenericYearAndAuthorOnly(){
605
        generic1.setAuthorship(genericTeam1);
606
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1792"));
607
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
608
        Assert.assertEquals("Unexpected title cache.", "Authorteam, 1792", generic1.getTitleCache());
609
        Assert.assertEquals("1792", generic1.getNomenclaturalCitation(null));
610
    }
611

    
612
    @Test
613
    public void testGenericDoubleDotBeforeYear(){
614
        generic1.setAuthorship(genericTeam1);
615
        String detail = "sine no.";
616
        generic1.setAbbrevTitle("My title");
617
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1883-1884"));
618
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
619
        Assert.assertEquals("My title: sine no. 1883-1884", generic1.getNomenclaturalCitation(detail));
620
    }
621

    
622
    //#4338
623
    @Test
624
    public void testGenericMissingVolume(){
625
        generic1.setTitle("My generic");
626
        generic1.setAuthorship(genericTeam1);
627
        generic1.setDatePublished(TimePeriodParser.parseStringVerbatim("1883-1884"));
628
        generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
629
        Assert.assertEquals("My generic: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
630
        generic1.setVolume("7");
631
        Assert.assertEquals("My generic 7: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
632
        Assert.assertEquals("Authorteam, My generic 7. 1883-1884", generic1.getTitleCache());
633
        Assert.assertEquals("AT., My generic 7. 1883-1884", generic1.getAbbrevTitleCache());
634

    
635
        //inRef
636
        Reference generic2 = ReferenceFactory.newGeneric();
637
        generic2.setTitle("My InRef");
638
        Person person2 = Person.NewTitledInstance("InRefAuthor");
639
        generic2.setAuthorship(person2);
640
        generic2.setDatePublished(TimePeriodParser.parseStringVerbatim("1885"));
641
        generic1.setInReference(generic2);
642

    
643
        //only reference has a volume
644
        Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
645
//        Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getTitleCache());
646
//        Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getAbbrevTitleCache());
647

    
648
        //both have a volume
649
        generic2.setVolume("9");  //still unclear what should happen if you have such dirty data
650
//        Assert.assertEquals("in InRefAuthor, My InRef 7: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
651
//        Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getTitleCache());
652
//        Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 7. 1883-1884", generic1.getAbbrevTitleCache());
653

    
654
        //only inref has volume
655
        generic1.setVolume(null);
656
        Assert.assertEquals("in InRefAuthor, My InRef 9: 55. 1883-1884", generic1.getNomenclaturalCitation(detail1));
657
        Assert.assertEquals("Authorteam - My generic in InRefAuthor, My InRef 9. 1883-1884", generic1.getTitleCache());
658
        Assert.assertEquals("AT. - My generic in InRefAuthor, My InRef 9. 1883-1884", generic1.getAbbrevTitleCache());
659
   }
660

    
661
    //#3532
662
    @Test
663
    public void testUnexpectedNomenclaturalReferences(){
664
        Reference reference;
665

    
666
        //database
667
        IDatabase database1 = ReferenceFactory.newDatabase();
668
        reference = (Reference)database1;
669

    
670
        database1.setTitle("My database");
671
        //maybe we should have a trailing dot here
672
        Assert.assertEquals("My database: 55", reference.getNomenclaturalCitation(detail1));
673
        database1.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
674
        Assert.assertEquals("My database: 55. 1998", reference.getNomenclaturalCitation(detail1));
675

    
676
        database1.setTitleCache("Your database", true);
677
        Assert.assertEquals("My database: 55. 1998", reference.getNomenclaturalCitation(detail1));
678

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

    
683

    
684
        //CD/DVD
685
        ICdDvd cdDvd = ReferenceFactory.newCdDvd();
686
        reference= (Reference)cdDvd;
687
        cdDvd.setTitle("My Cd/Dvd");
688
        //maybe we should have a trailing dot here
689
        Assert.assertEquals("My Cd/Dvd: 55", reference.getNomenclaturalCitation(detail1));
690
        cdDvd.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
691
        Assert.assertEquals("My Cd/Dvd: 55. 1998", reference.getNomenclaturalCitation(detail1));
692

    
693
        cdDvd.setTitleCache("Your Cd/Dvd", true);
694
        Assert.assertEquals("My Cd/Dvd: 55. 1998", reference.getNomenclaturalCitation(detail1));
695

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

    
700

    
701
        //WebSite
702
        IWebPage webPage = ReferenceFactory.newWebPage();
703
        reference= (Reference)webPage;
704
        webPage.setTitle("My WebPage");
705
        //maybe we should have a trailing dot here
706
        Assert.assertEquals("My WebPage: 55", reference.getNomenclaturalCitation(detail1));
707
        webPage.setDatePublished(TimePeriodParser.parseStringVerbatim("1998"));
708
        Assert.assertEquals("My WebPage: 55. 1998", reference.getNomenclaturalCitation(detail1));
709

    
710
        webPage.setTitleCache("Your WebPage", true);
711
        Assert.assertEquals("My WebPage: 55. 1998", reference.getNomenclaturalCitation(detail1));
712

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

    
717
        //uri
718
        webPage = ReferenceFactory.newWebPage();
719
        reference= (Reference)webPage;
720
        webPage.setUri(URI.create("http://www.abc.de"));
721
        Assert.assertEquals("http://www.abc.de: 55", reference.getNomenclaturalCitation(detail1));
722

    
723
        //TBC
724
   }
725

    
726
// ********************************** WEB PAGE ********************************************/
727

    
728
    @Test
729
    //still preliminary, may be modified in future
730
    public void testWebPageGetTitleCache(){
731
        webPage1.setUri(URI.create("http://flora.huji.ac.il"));
732
        Assert.assertEquals("Unexpected title cache.",
733
                "http://flora.huji.ac.il",
734
                webPage1.getTitleCache());
735

    
736
        webPage1.setTitle("Flora of Israel Online");
737
        webPage1.setAuthorship(webPageTeam1);
738
        webPage1.setAccessed(DateTime.parse("2001-01-05"));
739
        Assert.assertEquals("Unexpected title cache.",
740
                "Authorteam, D., Flora of Israel Online - http://flora.huji.ac.il [accessed 2001-01-05]",
741
                webPage1.getTitleCache());
742

    
743
    }
744

    
745
//  @Test
746
//  //WebPages should usually not be used as nomencl.reference, therefore this is less important
747
//  public void testWebPageGetAbbrevTitleCache(){
748
//      webPage1.setTitle("auct.");
749
//      Assert.assertEquals("Unexpected title cache.", "auct.", webPage1.getTitleCache());
750
//  }
751

    
752

    
753
}
(1-1/2)